File size: 1,934 Bytes
e2847fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
import torch
from components.tiny_confessional_layer_fixed import TinyConfessionalLayer

def test_fixed_layer():
    """Test the fixed TinyConfessionalLayer with various input shapes."""
    print("🧪 Testing TinyConfessionalLayer with shape safety...")
    
    # Test cases with different input shapes
    test_cases = [
        (1, 10, 256),    # Standard input
        (2, 8, 512),     # Different batch/seq
        (4, 20, 128),    # Different dimensions
        (1, 5, 768),     # Larger feature dimension
        (3, 3, 3),       # Very small dimensions
    ]
    
    for batch, seq, d_model in test_cases:
        print(f"\nTesting: batch={batch}, seq={seq}, d_model={d_model}")
        
        try:
            # Create model with default d_model=256
            model = TinyConfessionalLayer(
                d_model=256,  # Fixed internal dimension
                enable_ambient=False,  # Disable ambient for simpler testing
                enable_windsurf=False  # Disable windsurf for now
            )
            
            # Create random input
            x = torch.randn(batch, seq, d_model)
            
            # Run forward pass
            out, metadata = model(x, audit_mode=True)
            
            # Check output shape
            expected_shape = (batch, seq, 256)  # Should match model's d_model
            assert out.shape == expected_shape, \
                f"Expected shape {expected_shape}, got {out.shape}"
                
            print(f"✅ Success! Input: {x.shape} -> Output: {out.shape}")
            print(f"   Cycles: {metadata['cycles_run']}, "
                  f"Shape fixes: {metadata.get('shape_issues_resolved', 0)}")
            
        except Exception as e:
            print(f"❌ Test failed: {str(e)}")
            import traceback
            traceback.print_exc()

if __name__ == "__main__":
    test_fixed_layer()
    print("\n🎉 All tests completed!")