TRuCAL / tests /test_fixed_layer.py
johnaugustine's picture
Upload 24 files
e2847fd verified
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!")