| |
| |
| |
| |
| """ |
| Demo script for testing HAR CoT (Human Activity Recognition Chain-of-Thought) model from HuggingFace. |
| |
| This script: |
| 1. Loads a pretrained model from HuggingFace Hub |
| 2. Loads the HAR CoT test dataset |
| 3. Generates predictions on the evaluation set |
| 4. Prints model outputs |
| """ |
|
|
| from opentslm.model.llm.OpenTSLM import OpenTSLM |
| from opentslm.time_series_datasets.har_cot.HARCoTQADataset import HARCoTQADataset |
| from opentslm.time_series_datasets.util import extend_time_series_to_match_patch_size_and_aggregate |
| from torch.utils.data import DataLoader |
| from opentslm.model_config import PATCH_SIZE |
| import torch |
|
|
| |
| REPO_ID = "OpenTSLM/llama-3.2-1b-har-sp" |
|
|
| def main(): |
| print("=" * 60) |
| print("HAR CoT Model Demo") |
| print("=" * 60) |
| |
| |
| print(f"\n๐ฅ Loading model from {REPO_ID}...") |
| enable_lora = False |
| if "-sp" in REPO_ID: |
| enable_lora = True |
| model = OpenTSLM.load_pretrained(REPO_ID, enable_lora=enable_lora, device="cuda" if torch.cuda.is_available() else "cpu") |
|
|
| |
| |
| |
| print("\n๐ Loading HAR CoT test dataset...") |
| test_dataset = HARCoTQADataset("test", EOS_TOKEN=model.get_eos_token()) |
| |
| |
| test_loader = DataLoader( |
| test_dataset, |
| shuffle=False, |
| batch_size=1, |
| collate_fn=lambda batch: extend_time_series_to_match_patch_size_and_aggregate( |
| batch, patch_size=PATCH_SIZE |
| ), |
| ) |
| |
| print(f"\n๐ Running inference on {len(test_dataset)} test samples...") |
| print("=" * 60) |
| |
| |
| for i, batch in enumerate(test_loader): |
| |
| predictions = model.generate(batch, max_new_tokens=500) |
| |
| |
| for sample, pred in zip(batch, predictions): |
| print(f"\n๐ Sample {i + 1}:") |
| if 'pre_prompt' in sample: |
| print(f" Question: {sample['pre_prompt']}") |
| print(f" Gold Answer: {sample.get('answer', 'N/A')}") |
| print(f" Model Output: {pred}") |
| print("-" * 60) |
| |
| |
| if i >= 4: |
| print("\nโ
Demo complete! (Showing first 5 samples)") |
| break |
|
|
| if __name__ == "__main__": |
| main() |
|
|
|
|