File size: 1,309 Bytes
04d936d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from modeling_ini import IniForCausalLM, IniConfig

def test_model():
    print("1. Loading model from './model_save'...")
    try:
        model = IniForCausalLM.from_pretrained("./model_save")
        print("   Success! Model loaded.")
    except Exception as e:
        print(f"   Error loading model: {e}")
        return

    print("\n2. Model Stats:")
    print(f"   Parameters: {model.num_parameters():,}")
    print(f"   Hidden Size: {model.config.hidden_size}")
    print(f"   Vocab Size: {model.config.vocab_size}")

    print("\n3. Running Inference (Forward Pass)...")
    device = "cuda" if torch.cuda.is_available() else "cpu"
    print(f"   Using device: {device}")
    model = model.to(device)
    model.eval()

    # Create dummy input (batch_size=1, seq_len=5)
    input_ids = torch.tensor([[101, 200, 300, 400, 500]]).to(device)
    print(f"   Input IDs: {input_ids.tolist()}")

    with torch.no_grad():
        outputs = model(input_ids)
        logits = outputs[0]
        
    print(f"   Output Logits Shape: {logits.shape}")
    print("   Prediction (Random user, untrained model):")
    predicted_ids = torch.argmax(logits, dim=-1)
    print(f"   Predicted Token IDs: {predicted_ids.tolist()}")

    print("\nTest Complete!")

if __name__ == "__main__":
    test_model()