File size: 1,543 Bytes
5a08ee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""
Example usage of SuperLinear model for time series forecasting.
"""

import torch
from transformers import AutoModelForCausalLM, AutoConfig

def main():
    # Load model configuration and model
    config = AutoConfig.from_pretrained("./", trust_remote_code=True)
    model = AutoModelForCausalLM.from_pretrained("./", trust_remote_code=True)
    
    # Set model to evaluation mode
    model.eval()
    
    # Create sample time series data
    # Shape: [batch_size, sequence_length, features]
    batch_size = 4
    sequence_length = 512
    num_features = 1
    prediction_length = 96
    
    # Generate synthetic time series data
    t = torch.linspace(0, 10, sequence_length)
    sample_data = torch.sin(t).unsqueeze(0).unsqueeze(-1).repeat(batch_size, 1, num_features)
    
    print(f"Input shape: {sample_data.shape}")
    
    # Generate predictions
    with torch.no_grad():
        outputs = model(inputs_embeds=sample_data, pred_len=prediction_length)
        predictions = outputs.logits
    
    print(f"Prediction shape: {predictions.shape}")
    print(f"Sample predictions: {predictions[0, :5, 0]}")  # First 5 predictions of first batch
    
    # Demonstrate with different prediction lengths
    for pred_len in [24, 48, 96, 192]:
        with torch.no_grad():
            outputs = model(inputs_embeds=sample_data, pred_len=pred_len)
            predictions = outputs.logits
        print(f"Prediction length {pred_len}: output shape {predictions.shape}")

if __name__ == "__main__":
    main()