mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-03-10 04:32:07 -05:00
58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
"""
|
|
Capability Tests for Module XX: [Module Name]
|
|
Template for testing that the module enables its intended capabilities
|
|
"""
|
|
|
|
import numpy as np
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
|
|
|
|
|
|
class TestModuleCapabilities:
|
|
"""Test that the module enables its promised capabilities."""
|
|
|
|
def test_solves_intended_problem(self):
|
|
"""Test the module can solve its primary use case."""
|
|
# Example for Conv2D:
|
|
# from tinytorch.core.spatial import Conv2D
|
|
#
|
|
# conv = Conv2D(3, 32, kernel_size=3)
|
|
# image = Tensor(np.random.randn(1, 28, 28, 3))
|
|
# features = conv(image)
|
|
#
|
|
# # Should extract features
|
|
# assert features.shape[-1] == 32 # 32 feature maps
|
|
pass
|
|
|
|
def test_real_world_scenario(self):
|
|
"""Test a real-world usage scenario."""
|
|
# Example for Optimizer:
|
|
# from tinytorch.core.optimizers import Adam
|
|
# from tinytorch.core.layers import Linear
|
|
#
|
|
# layer = Linear(10, 5)
|
|
# optimizer = Adam(learning_rate=0.001)
|
|
#
|
|
# # Simulate training step
|
|
# loss = compute_loss()
|
|
# gradients = compute_gradients()
|
|
# optimizer.step(layer.parameters(), gradients)
|
|
#
|
|
# # Parameters should be updated
|
|
# assert parameters_changed
|
|
pass
|
|
|
|
def test_performance_acceptable(self):
|
|
"""Test that performance is acceptable."""
|
|
# Example:
|
|
# import time
|
|
#
|
|
# start = time.time()
|
|
# result = expensive_operation()
|
|
# duration = time.time() - start
|
|
#
|
|
# assert duration < 1.0 # Should complete in under 1 second
|
|
pass |