File size: 1,290 Bytes
148b631
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Quick test to verify the optimized model works correctly."""

import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from src.model import RippleGPT
from src.config import RippleConfig
import torch

def test_model():
    print("🔧 Testando modelo otimizado...")
    
    config = RippleConfig(vocab_size=65, block_size=256, n_layer=2, n_head=2, n_embd=64)
    model = RippleGPT(config)
    
    # Teste com contexto menor que treino
    x = torch.randint(0, 65, (1, 100))
    with torch.no_grad():
        logits, _ = model(x)
    print(f"✅ Forward pass OK - Shape: {logits.shape}")
    
    # Teste com contexto igual ao treino
    x = torch.randint(0, 65, (1, 256))
    with torch.no_grad():
        logits, _ = model(x)
    print(f"✅ Forward pass (256 tokens) OK - Shape: {logits.shape}")
    
    # Teste com contexto MAIOR que treino (extrapolação!)
    x = torch.randint(0, 65, (1, 512))
    with torch.no_grad():
        logits, _ = model(x)
    print(f"🔬 Forward pass (512 tokens - 2x!) OK - Shape: {logits.shape}")
    
    print()
    print("✅ Modelo otimizado funcionando corretamente!")
    print("✅ Extrapolação para 2x contexto: SUCESSO")
    return 0

if __name__ == "__main__":
    exit(test_model())