File size: 893 Bytes
0523608
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from nanochat.gpt import GPT, GPTConfig

def test_tiny_model_forward():
    # Use a tiny n_embd that would have triggered the bug (n_embd < 32)
    config = GPTConfig(
        n_head=2,
        n_kv_head=2,
        n_embd=16, 
        vocab_size=128,
        sequence_len=32
    )
    
    device = "cuda" if torch.cuda.is_available() else "cpu"
    print(f"Using device: {device}")
    
    model = GPT(config).to(device)
    model.init_weights()
    
    # Create dummy input
    idx = torch.randint(0, config.vocab_size, (1, 8), device=device)
    
    print("Running forward pass...")
    try:
        logits = model(idx)
        print("Forward pass successful!")
        assert logits.shape == (1, 8, config.vocab_size)
    except Exception as e:
        print(f"Forward pass failed with error: {e}")
        raise e

if __name__ == "__main__":
    test_tiny_model_forward()