Commit Graph

28 Commits

Author SHA1 Message Date
Vijay Janapa Reddi
fb753882ec fix(module-01): Fix batched matmul and transpose grad preservation
- Change np.dot to np.matmul for proper batched 3D tensor multiplication
- Add requires_grad preservation in transpose() operation
- Fixes attention mechanism gradient flow issues

Regression tests added in tests/regression/test_gradient_flow_fixes.py
2025-10-27 20:28:53 -04:00
Vijay Janapa Reddi
688e5826ec feat: Add Milestone 04 (CNN Revolution 1998) + Clean spatial imports
Milestone 04 - CNN Revolution:
 Complete 5-Act narrative structure (Challenge → Reflection)
 SimpleCNN architecture: Conv2d → ReLU → MaxPool → Linear
 Trains on 8x8 digits dataset (1,437 train, 360 test)
 Achieves 84.2% accuracy with only 810 parameters
 Demonstrates spatial operations preserve structure
 Beautiful visual output with progress tracking

Key Features:
- Conv2d (1→8 channels, 3×3 kernel) detects local patterns
- MaxPool2d (2×2) provides translation invariance
- 100× fewer parameters than equivalent MLP
- Training completes in ~105 seconds (50 epochs)
- Sample predictions table shows 9/10 correct

Module 09 Spatial Improvements:
- Removed ugly try/except import pattern
- Clean imports: 'from tinytorch.core.tensor import Tensor'
- Matches PyTorch style (simple and professional)
- No fallback logic needed

All 4 milestones now follow consistent 5-Act structure!
2025-09-30 17:04:41 -04:00
Vijay Janapa Reddi
ba6bd79a67 Reset package and export modules 01-07 only (skip broken spatial module) 2025-09-30 13:41:00 -04:00
Vijay Janapa Reddi
8be87d0add Fix nbdev export system across all 20 modules
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)
2025-09-30 11:21:04 -04:00
Vijay Janapa Reddi
ed7b680ad0 feat: implement professional selective export pattern across all modules
BREAKING CHANGE: Refactor from whole-module exports to selective function/class exports

**What Changed:**
- Separate development utilities from production exports
- Each function/class gets individual #| export directive
- Clean Prerequisites & Setup sections in all modules
- Development helpers (import_previous_module) not exported

**Module Export Summary:**
- 01_tensor: Tensor class only
- 02_activations: Sigmoid, ReLU, Tanh, GELU, Softmax only
- 03_layers: Linear, Dropout only
- 04_losses: MSELoss, CrossEntropyLoss, BinaryCrossEntropyLoss, log_softmax only
- 05_autograd: Function class only
- 06_optimizers: SGD, Adam, AdamW only

**Benefits:**
 Clean public API (matches PyTorch/TensorFlow patterns)
 No development utilities in final package
 Professional software education standards
 Clear separation of concerns
 Educational clarity for students

This matches industry standards for educational ML frameworks.
2025-09-30 09:48:47 -04:00
Vijay Janapa Reddi
6ccfa2b352 feat: standardize integration testing with import helpers
- Add import_previous_module() helper function to all core modules (01-07)
- Standardize cross-module imports for integration testing
- Add clear Prerequisites & Setup sections explaining module dependencies
- Update integration tests to use standardized import pattern
- Maintain clean separation between development and production code

This provides a consistent, educational approach to module integration
while keeping the codebase maintainable and student-friendly.
2025-09-30 09:42:58 -04:00
Vijay Janapa Reddi
e1a9541c4b Clean up module imports: convert tinytorch.core to sys.path style
- 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
2025-09-30 08:58:58 -04:00
Vijay Janapa Reddi
d82c75f9dc Renumber modules from 00-13 to 01-14 for natural numbering
 Rename all module directories: 00_setup → 01_setup, etc.
 Update convert_modules.py mappings for new directory names
 Update _toc.yml file paths and titles (1-14 instead of 0-13)
 Regenerate all overview pages with new numbering
 Fix all broken references in usage-paths and intro
 Update chapter references to use natural numbering

Benefits:
- More intuitive course progression starting from 1
- Matches academic course numbering conventions
- Eliminates confusion about 'Module 0' concept
- Cleaner mental model for students and instructors
- All references and links properly updated

Complete transformation: 14 modules now numbered 01-14
2025-07-15 18:51:36 -04:00
Vijay Janapa Reddi
76225baa42 Remove module numbers from headers for cleaner presentation
 Clean source file headers: 'Module X:' → clean descriptive titles
 Regenerate overview pages with clean headers
 More flexible content that works in any context
 Numbers still provided by book TOC structure

Changes:
- Remove 'Module X: ' prefix from all source file headers
- Headers now focus on descriptive content titles
- Book maintains proper chapter ordering via _toc.yml
- Content is more reusable across different presentations
2025-07-15 18:23:18 -04:00
Vijay Janapa Reddi
025869fb6d Verify tito CLI functionality - all commands working correctly
-  tito system info/doctor: Full system health check working
-  tito module status: Shows all 14 modules with proper status
-  tito export --all: Successfully exports all modules to tinytorch package
-  tito test --all: Runs all inline tests (65/66 tests passing)
-  tito nbgrader: All assignment management commands available
-  tito package nbdev: NBDev integration working
-  Global PATH: Added bin/ to PATH for global tito access

Only minor issue: 1 MLOps test failing due to script execution
All core functionality working perfectly for educational use
2025-07-14 19:45:36 -04:00
Vijay Janapa Reddi
d14f92a9b2 Simplify test discovery and clean up test function names across all modules
MAJOR IMPROVEMENT: Simplified test discovery logic
- Removed restrictive valid_patterns requirement from testing framework
- Any function starting with 'test_' is now automatically discovered
- Follows standard pytest conventions - no maintenance overhead
- Eliminates need to manually add patterns for new test functions

CLEANED UP: Test function names across all 10 modules
- Removed redundant '_comprehensive' suffix from all test functions
- Updated 40+ test function names to be more concise and readable:
  * 00_setup: 6 functions (test_personal_info, test_system_info, etc.)
  * 01_tensor: 4 functions (test_tensor_creation, test_tensor_properties, etc.)
  * 02_activations: 1 function (test_activations)
  * 03_layers: 3 functions (test_matrix_multiplication, test_dense_layer, etc.)
  * 04_networks: 4 functions (test_sequential_networks, test_mlp_creation, etc.)
  * 05_cnn: 3 functions (test_convolution_operation, test_conv2d_layer, etc.)
  * 06_dataloader: 4 functions (test_dataset_interface, test_dataloader, etc.)
  * 07_autograd: 6 functions (test_variable_class, test_add_operation, etc.)
  * 08_optimizers: 5 functions (test_gradient_descent_step, test_sgd_optimizer, etc.)
  * 09_training: 6 functions (test_mse_loss, test_crossentropy_loss, etc.)
  * 10_compression: 6 functions (already cleaned up)

VERIFICATION: All tests still pass
- All 10 modules tested successfully with new discovery logic
- Total test count maintained: 47 inline tests across all modules
- No functionality lost, only improved maintainability

RESULT: Much cleaner, more maintainable testing framework following standard conventions
2025-07-14 10:24:04 -04:00
Vijay Janapa Reddi
8c5dd7c600 Rename integration tests to comprehensive tests in _dev files
- Updated all _dev.py files to use 'comprehensive test' instead of 'integration test'
- Changed function names: test_*_integration() → test_*_comprehensive()
- Updated markdown headers, print statements, success/error messages
- Clarifies that these are comprehensive tests of single modules, not cross-module integration
- Real cross-module integration tests remain in tests/ directory
- Updated modules: 00_setup, 01_tensor, 02_activations, 03_layers, 04_networks, 05_cnn, 06_dataloader, 07_autograd
2025-07-14 00:32:16 -04:00
Vijay Janapa Reddi
06ca2ee802 Standardize module.yaml files for instructor/staff workflow
- Remove student-facing bloat (learning objectives, time estimates, pedagogical details)
- Remove assessment sections (not needed for operational metadata)
- Streamline to essential system information only:
  - Module identification and dependencies
  - Package export configuration
  - File structure and component listings

- Updated existing files (6): setup, tensor, activations, layers, autograd, optimizers
- Created missing files (3): networks, cnn, dataloader
- Consistent 25-26 line format across all 9 modules

Result: Pure operational metadata for CLI tools and build systems
Perfect for instructor/staff development workflow
2025-07-14 00:08:05 -04:00
Vijay Janapa Reddi
5264b6aa68 Move testing utilities to tito/tools for better software architecture
- Move testing utilities from tinytorch/utils/testing.py to tito/tools/testing.py
- Update all module imports to use tito.tools.testing
- Remove testing utilities from core TinyTorch package
- Testing utilities are development tools, not part of the ML library
- Maintains clean separation between library code and development toolchain
- All tests continue to work correctly with improved architecture
2025-07-13 21:05:11 -04:00
Vijay Janapa Reddi
4ad611383a 🔬 Complete Unit Test terminology standardization
 Fixed remaining inconsistencies in:
- 01_tensor/tensor_dev.py: Updated all 'Testing X...' → '🔬 Unit Test: X...'
- 00_setup/setup_dev.py: Updated all 'Testing X...' → '🔬 Unit Test: X...'

🎯 All TinyTorch modules now use unified format:
- 00_setup 
- 01_tensor 
- 02_activations 
- 03_layers 
- 04_networks 
- 05_cnn 
- 06_dataloader 
- 07_autograd 
- 08_optimizers 

📊 Result: Complete consistency across all 9 modules with professional '🔬 Unit Test: [Component]...' terminology following tensor_dev.py patterns.
2025-07-13 17:31:57 -04:00
Vijay Janapa Reddi
469af4c3de Remove module-level tests directories, keep only main tests/ for exported package validation
- Remove all tests/ directories under modules/source/
- Keep main tests/ directory for testing exported functionality
- Update status command to check tests in main tests/ directory
- Update documentation to reflect new test structure
- Reduce maintenance burden by eliminating duplicate test systems
- Focus on inline NBGrader tests for development, main tests for package validation
2025-07-13 17:14:14 -04:00
Vijay Janapa Reddi
a7fb897eed Update documentation and cleanup rules
- Enhanced tensor module documentation with mathematical foundations
- Improved explanations for scalars, vectors, and matrices
- Added NBGrader workflow documentation to activations module
- Cleaned up .cursor/rules/ directory structure
- Updated user preferences for better development workflow

These changes improve the educational content and developer experience
while maintaining the core functionality of all modules.
2025-07-13 17:00:21 -04:00
Vijay Janapa Reddi
cd770773f6 feat: Add missing BEGIN/END SOLUTION markers to NBGrader modules
- Add solution markers to 01_tensor module properties (data, shape, size, dtype)
- Add solution markers to 04_networks Sequential.forward method
- Add solution markers to 05_cnn module (conv2d_naive, Conv2D.__init__, Conv2D.forward, flatten)
- Add solution markers to 06_dataloader Dataset class methods (__getitem__, __len__, get_sample_shape)
- Verify existing solution markers in 02_activations (4 pairs), 03_layers (3 pairs), 07_autograd (4 pairs), 00_setup (2 pairs)

Critical for NBGrader functionality:
- BEGIN/END SOLUTION markers identify instructor solutions to hide from students
- Enables proper assignment generation and solution hiding
- Ensures seamless integration with NBGrader grading system
- Maintains pedagogical separation between student TODOs and instructor solutions
2025-07-13 16:52:52 -04:00
Vijay Janapa Reddi
62f8b10e56 chore: Remove unused Python notebooks from modules directory
- Remove all .ipynb files from modules/source/ directories
- Follow Python-first development workflow where .py files are source of truth
- .ipynb files should be temporary outputs generated only for NBGrader work
- Keeps repository clean and follows project conventions

Removed notebooks:
- modules/source/00_setup/setup_dev.ipynb
- modules/source/01_tensor/tensor_dev.ipynb
- modules/source/03_layers/layers_dev.ipynb
- modules/source/04_networks/networks_dev.ipynb
- modules/source/05_cnn/cnn_dev.ipynb
- modules/source/06_dataloader/dataloader_dev.ipynb
- modules/source/07_autograd/autograd_dev.ipynb
2025-07-13 16:44:34 -04:00
Vijay Janapa Reddi
833475c2c7 feat: Transform 7 modules to follow progressive testing pedagogical pattern
- Implement 'explain → code → test → repeat' structure across all modules
- Replace comprehensive end-of-module tests with progressive unit tests
- Add rich scaffolding with detailed implementation guidance
- Transform generic TODOs into step-by-step learning instructions
- Connect educational content to real-world ML systems and PyTorch
- Reduce overall codebase by 37% while enhancing learning experience
- Ensure immediate feedback and skill building for students

Modules transformed:
- 01_tensor: Tensor operations and broadcasting
- 02_activations: Activation functions and derivatives
- 03_layers: Linear layers and forward/backward propagation
- 04_networks: Network building and multi-layer composition
- 05_cnn: Convolution operations and CNN architecture
- 06_dataloader: Data pipeline and batch processing
- 07_autograd: Automatic differentiation and computational graphs
2025-07-13 16:43:27 -04:00
Vijay Janapa Reddi
eafbb4ac8d Fix comprehensive testing and module exports
🔧 TESTING INFRASTRUCTURE FIXES:
- Fixed pytest configuration (removed duplicate timeout)
- Exported all modules to tinytorch package using nbdev
- Converted .py files to .ipynb for proper NBDev processing
- Fixed import issues in test files with fallback strategies

📊 TESTING RESULTS:
- 145 tests passing, 15 failing, 16 skipped
- Major improvement from previous import errors
- All modules now properly exported and testable
- Analysis tool working correctly on all modules

🎯 MODULE QUALITY STATUS:
- Most modules: Grade C, Scaffolding 3/5
- 01_tensor: Grade C, Scaffolding 2/5 (needs improvement)
- 07_autograd: Grade D, Scaffolding 2/5 (needs improvement)
- Overall: Functional but needs educational enhancement

 RESOLVED ISSUES:
- All import errors resolved
- NBDev export process working
- Test infrastructure functional
- Analysis tools operational

🚀 READY FOR NEXT PHASE: Professional report cards and improvements
2025-07-13 09:20:32 -04:00
Vijay Janapa Reddi
f76f416a39 Fix tensor module indentation and test compatibility
- Fixed indentation error in tensor module add method
- Updated networks test import to use correct function name
- Most tests now passing with only minor edge case failures
2025-07-12 22:25:50 -04:00
Vijay Janapa Reddi
7b76a11bcd Enhance tensor module with comprehensive mathematical foundations
- Added detailed mathematical progression from scalars to higher-order tensors
- Enhanced conceptual explanations with real-world ML applications
- Improved tensor class design with comprehensive requirements analysis
- Added extensive arithmetic operations section with broadcasting and performance considerations
- Connected to industry frameworks (PyTorch, TensorFlow, JAX)
- Improved learning scaffolding with step-by-step implementation guidance
2025-07-12 21:10:22 -04:00
Vijay Janapa Reddi
d86eb696b7 Standardize inline test naming and ensure progressive testing structure
 STANDARDIZED TESTING ARCHITECTURE:
- All inline tests now use consistent 'Unit Test: [Component]' naming
- Progressive testing: small portions tested as students implement
- Consistent print statements with �� Unit Test: format

 PROGRESSIVE TESTING STRUCTURE:
- Tensor Module: Unit Test: Creation → Properties → Arithmetic → Comprehensive
- Activations Module: Unit Test: ReLU → Sigmoid → Tanh → Softmax → Comprehensive
- Layers Module: Unit Test: Matrix Multiplication → Dense Layer → Comprehensive
- Networks Module: Unit Test: Sequential → MLP Creation → Comprehensive
- CNN Module: Unit Test: Convolution → Conv2D → Flatten → Comprehensive
- DataLoader Module: Unit Test: Dataset → DataLoader → Pipeline → Comprehensive
- Autograd Module: Unit Test: Variables → Operations → Chain Rule → Comprehensive

 EDUCATIONAL CONSISTENCY:
- Each unit test focuses on one specific component in isolation
- Immediate feedback after each implementation step
- Clear explanations of what each test validates
- Consistent error messages and success indicators

 TESTING GRANULARITY VERIFIED:
- Unit tests test small, specific functionality
- Comprehensive tests cover edge cases and integration
- All tests follow NBGrader-compliant cell structure
- Proper separation between educational and assessment testing

Total: 25+ individual unit tests across 7 modules with consistent naming and structure
2025-07-12 20:38:26 -04:00
Vijay Janapa Reddi
00169e266b Implement comprehensive inline testing for Tensor module
- Replace basic inline tests with comprehensive educational tests
- Add thorough tensor creation testing (8 test cases)
- Add comprehensive property testing (6 test cases)
- Add complete arithmetic testing (8 test cases)
- Add ML integration test with realistic scenarios
- Provide detailed feedback, hints, and progress tracking
- Follow inline-first testing approach for immediate feedback
2025-07-12 19:39:07 -04:00
Vijay Janapa Reddi
9199199845 feat: Add comprehensive intermediate testing across all TinyTorch modules
- Add 17 intermediate test points across 6 modules for immediate student feedback
- Tensor module: Tests after creation, properties, arithmetic, and operators
- Activations module: Tests after each activation function (ReLU, Sigmoid, Tanh, Softmax)
- Layers module: Tests after matrix multiplication and Dense layer implementation
- Networks module: Tests after Sequential class and MLP creation
- CNN module: Tests after convolution, Conv2D layer, and flatten operations
- DataLoader module: Tests after Dataset interface and DataLoader class
- All tests include visual progress indicators and behavioral explanations
- Maintains NBGrader compliance with proper metadata and point allocation
- Enables steady forward progress and better debugging for students
- 100% test success rate across all modules and integration testing
2025-07-12 18:28:35 -04:00
Vijay Janapa Reddi
9247784cb7 feat: Enhanced tensor and activations modules with comprehensive educational content
- Added package structure documentation explaining modules/source/ vs tinytorch.core.
- Enhanced mathematical foundations with linear algebra refresher and Universal Approximation Theorem
- Added real-world applications for each activation function (ReLU, Sigmoid, Tanh, Softmax)
- Included mathematical properties, derivatives, ranges, and computational costs
- Added performance considerations and numerical stability explanations
- Connected to production ML systems (PyTorch, TensorFlow, JAX equivalents)
- Implemented streamlined 'tito export' command with automatic .py → .ipynb conversion
- All functionality preserved: scripts run correctly, tests pass, package integration works
- Ready to continue with remaining modules (layers, networks, cnn, dataloader)
2025-07-12 17:51:00 -04:00
Vijay Janapa Reddi
f1d47330b3 Simplify export workflow: remove module_paths.txt, use dynamic discovery
- Remove unnecessary module_paths.txt file for cleaner architecture
- Update export command to discover modules dynamically from modules/source/
- Simplify nbdev command to support --all and module-specific exports
- Use single source of truth: nbdev settings.ini for module paths
- Clean up import structure in setup module for proper nbdev export
- Maintain clean separation between module discovery and export logic

This implements a proper software engineering approach with:
- Single source of truth (settings.ini)
- Dynamic discovery (no hardcoded paths)
- Clean CLI interface (tito package nbdev --export [--all|module])
- Robust error handling with helpful feedback
2025-07-12 17:19:22 -04:00