- Import Module base class from core.layers
- Fix embeddings import path (text.embeddings not core.embeddings)
- Fix attention import (MultiHeadAttention not SelfAttention)
- Fix transformer import path (models.transformer not core.transformers)
- Handle missing functional module gracefully with try/except
- Update __all__ exports to match available components
PROBLEM:
- nbdev requires #| export directive on EACH cell to export when using # %% markers
- Cell markers inside class definitions split classes across multiple cells
- Only partial classes were being exported to tinytorch package
- Missing matmul, arithmetic operations, and activation classes in exports
SOLUTION:
1. Removed # %% cell markers INSIDE class definitions (kept classes as single units)
2. Added #| export to imports cell at top of each module
3. Added #| export before each exportable class definition in all 20 modules
4. Added __call__ method to Sigmoid for functional usage
5. Fixed numpy import (moved to module level from __init__)
MODULES FIXED:
- 01_tensor: Tensor class with all operations (matmul, arithmetic, shape ops)
- 02_activations: Sigmoid, ReLU, Tanh, GELU, Softmax classes
- 03_layers: Linear, Dropout classes
- 04_losses: MSELoss, CrossEntropyLoss, BinaryCrossEntropyLoss classes
- 05_autograd: Function, AddBackward, MulBackward, MatmulBackward, SumBackward
- 06_optimizers: Optimizer, SGD, Adam, AdamW classes
- 07_training: CosineSchedule, Trainer classes
- 08_dataloader: Dataset, TensorDataset, DataLoader classes
- 09_spatial: Conv2d, MaxPool2d, AvgPool2d, SimpleCNN classes
- 10-20: All exportable classes in remaining modules
TESTING:
- Test functions use 'if __name__ == "__main__"' guards
- Tests run in notebooks but NOT on import
- Rosenblatt Perceptron milestone working perfectly
RESULT:
✅ All 20 modules export correctly
✅ Perceptron (1957) milestone functional
✅ Clean separation: development (modules/source) vs package (tinytorch)
- Remove circular imports where modules imported from themselves
- Convert tinytorch.core imports to sys.path relative imports
- Only import dependencies that are actually used in each module
- Preserve documentation imports in markdown cells
- Use consistent relative path pattern across all modules
- Remove hardcoded absolute paths in favor of relative imports
Affected modules: 02_activations, 03_layers, 04_losses, 06_optimizers,
07_training, 09_spatial, 12_attention, 17_quantization
Major refactoring:
- Eliminated Variable class completely from autograd module
- Implemented progressive enhancement pattern with enable_autograd()
- All modules now use pure Tensor with requires_grad=True
- PyTorch 2.0 compatible API throughout
- Clean separation: Module 01 has simple Tensor, Module 05 enhances with gradients
- Fixed all imports and references across layers, activations, losses
- Educational clarity: students learn modern patterns from day one
The system now follows the principle: 'One Tensor class to rule them all'
No more confusion between Variable and Tensor - everything is just Tensor!
🎯 NORTH STAR VISION DOCUMENTED:
'Don't Just Import It, Build It' - Training AI Engineers, not just ML users
AI Engineering emerges as a foundational discipline like Computer Engineering,
bridging algorithms and systems to build the AI infrastructure of the future.
🧪 ROBUST TESTING FRAMEWORK ESTABLISHED:
- Created tests/regression/ for sandbox integrity tests
- Implemented test-driven bug prevention workflow
- Clear separation: student tests (pedagogical) vs system tests (robustness)
- Every bug becomes a test to prevent recurrence
✅ KEY IMPLEMENTATIONS:
- NORTH_STAR.md: Vision for AI Engineering discipline
- Testing best practices: Focus on robust student sandbox
- Git workflow standards: Professional development practices
- Regression test suite: Prevent infrastructure issues
- Conv->Linear dimension tests (found CNN bug)
- Transformer reshaping tests (found GPT bug)
🏗️ SANDBOX INTEGRITY:
Students need a solid, predictable environment where they focus on ML concepts,
not debugging framework issues. The framework must be invisible.
📚 EDUCATIONAL PHILOSOPHY:
TinyTorch isn't just teaching a framework - it's founding the AI Engineering
discipline by training engineers who understand how to BUILD ML systems.
This establishes the foundation for training the first generation of true
AI Engineers who will define this emerging discipline.
Final stage of TinyTorch API simplification:
- Exported updated tensor module with Parameter function
- Exported updated layers module with Linear class and Module base class
- Fixed nn module to use unified Module class from core.layers
- Complete modern API now working with automatic parameter registration
✅ All 7 stages completed successfully:
1. Unified Tensor with requires_grad support
2. Module base class for automatic parameter registration
3. Dense renamed to Linear for PyTorch compatibility
4. Spatial helpers (flatten, max_pool2d) and Conv2d rename
5. Package organization with nn and optim modules
6. Modern API examples showing 50-70% code reduction
7. Complete export with working PyTorch-compatible interface
🎉 Students can now write PyTorch-like code while still implementing
all core algorithms (Conv2d, Linear, ReLU, Adam, autograd)
The API achieves the goal: clean professional interfaces that enhance
learning by reducing cognitive load on framework mechanics.
Stage 5 of TinyTorch API simplification:
- Created tinytorch.nn package with PyTorch-compatible interface
- Added Module base class in nn.modules for automatic parameter registration
- Added functional module with relu, flatten, max_pool2d operations
- Created tinytorch.optim package exposing Adam and SGD optimizers
- Updated main __init__.py to export nn and optim modules
- Linear and Conv2d now available through clean nn interface
Students can now write PyTorch-like code:
import tinytorch.nn as nn
import tinytorch.nn.functional as F
model = nn.Linear(784, 10)
x = F.relu(model(x))