From b19acb6266a384d8102f6728c80df20ce7cfbad4 Mon Sep 17 00:00:00 2001 From: Vijay Janapa Reddi Date: Tue, 30 Sep 2025 06:51:30 -0400 Subject: [PATCH] Simplify module test execution for notebook compatibility Removed redundant test calls from all modules: - Eliminated verbose if __name__ == '__main__': blocks - Removed duplicate individual test calls - Each module now simply calls test_module() directly Changes made to all 9 modules: - Module 01 (Tensor): Simplified from 16-line main block to 1 line - Module 02 (Activations): Simplified from 13-line main block to 1 line - Module 03 (Layers): Simplified from 17-line main block to 1 line - Module 04 (Losses): Simplified from 20-line main block to 1 line - Module 05 (Autograd): Simplified from 19-line main block to 1 line - Module 06 (Optimizers): Simplified from 17-line main block to 1 line - Module 07 (Training): Simplified from 16-line main block to 1 line - Module 08 (DataLoader): Simplified from 17-line main block to 1 line - Module 09 (Spatial): Simplified from 14-line main block to 1 line Impact: - Notebook-friendly: Tests run immediately in Jupyter environments - No redundancy: test_module() already runs all unit tests - Cleaner code: ~140 lines of redundant code removed - Better for students: Simpler, more direct execution flow --- modules/01_tensor/tensor_dev.py | 22 ++----------------- modules/02_activations/activations_dev.py | 22 ++----------------- modules/03_layers/layers_dev.py | 24 ++------------------- modules/04_losses/losses_dev.py | 22 ++----------------- modules/05_autograd/autograd_dev.py | 21 ++---------------- modules/06_optimizers/optimizers_dev.py | 22 ++----------------- modules/07_training/training_dev.py | 21 ++---------------- modules/08_dataloader/dataloader_dev.py | 26 ++--------------------- modules/09_spatial/spatial_dev.py | 24 ++------------------- 9 files changed, 18 insertions(+), 186 deletions(-) diff --git a/modules/01_tensor/tensor_dev.py b/modules/01_tensor/tensor_dev.py index be51ba64..82dfb882 100644 --- a/modules/01_tensor/tensor_dev.py +++ b/modules/01_tensor/tensor_dev.py @@ -1636,26 +1636,8 @@ def test_module(): print("๐ŸŽ‰ ALL TESTS PASSED! Module ready for export.") print("Run: tito module complete 01_tensor") -# test_module() # Moved to main block - -# %% -if __name__ == "__main__": - print("๐Ÿš€ Running Tensor Foundation module...") - - # Run all unit tests - test_unit_tensor_creation() - test_unit_arithmetic_operations() - test_unit_matrix_multiplication() - test_unit_shape_manipulation() - test_unit_reduction_operations() - - # Run integration demo - demonstrate_tensor_integration() - - # Run final module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] diff --git a/modules/02_activations/activations_dev.py b/modules/02_activations/activations_dev.py index 72db77da..674edc85 100644 --- a/modules/02_activations/activations_dev.py +++ b/modules/02_activations/activations_dev.py @@ -883,26 +883,8 @@ def test_module(): print("๐ŸŽ‰ ALL TESTS PASSED! Module ready for export.") print("Run: tito module complete 02") -# test_module() # Moved to main block - -# %% -if __name__ == "__main__": - print("๐Ÿš€ Running Activations module...") - - # Run individual unit tests - test_unit_sigmoid() - test_unit_relu() - test_unit_tanh() - test_unit_gelu() - test_unit_softmax() - - # Demonstrate all activations working together - demonstrate_activations() - - # Run comprehensive module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] diff --git a/modules/03_layers/layers_dev.py b/modules/03_layers/layers_dev.py index fa2ef19e..31ee4a05 100644 --- a/modules/03_layers/layers_dev.py +++ b/modules/03_layers/layers_dev.py @@ -1050,28 +1050,8 @@ def test_module(): print("๐ŸŽ‰ ALL TESTS PASSED! Module ready for export.") print("Run: tito module complete 03_layers") -# Module test will be run in main block - -# %% -if __name__ == "__main__": - print("๐Ÿš€ Running Layers module...") - - # Run all unit tests - test_unit_linear_layer() - test_unit_sequential_container() - test_unit_dropout_layer() - - # Run integration demo - model, output = demonstrate_layer_integration() - - # Run systems analysis - analyze_layer_memory() - analyze_layer_performance() - - # Run final module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] diff --git a/modules/04_losses/losses_dev.py b/modules/04_losses/losses_dev.py index f232ad4d..f8bdf6d6 100644 --- a/modules/04_losses/losses_dev.py +++ b/modules/04_losses/losses_dev.py @@ -1300,26 +1300,8 @@ def test_module(): # %% -if __name__ == "__main__": - print("๐Ÿš€ Running Losses module...") - - # Run all unit tests - test_unit_log_softmax() - test_unit_mse_loss() - test_unit_cross_entropy_loss() - test_unit_binary_cross_entropy_loss() - - # Run integration and analysis functions - mse_result, ce_result, bce_result = compare_loss_behaviors() - analyze_loss_sensitivity() - analyze_numerical_stability() - analyze_loss_memory() - analyze_production_patterns() - - # Final module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] diff --git a/modules/05_autograd/autograd_dev.py b/modules/05_autograd/autograd_dev.py index 65715ea0..7e8606d6 100644 --- a/modules/05_autograd/autograd_dev.py +++ b/modules/05_autograd/autograd_dev.py @@ -1345,25 +1345,8 @@ def test_module(): # Test function defined above, will be called in main block # %% -if __name__ == "__main__": - print("๐Ÿš€ Running Autograd module...") - - # Run all unit tests - test_unit_function_base() - test_unit_operation_functions() - test_unit_tensor_autograd() - - # Run demonstration functions - demonstrate_complex_computation_graph() - - # Run analysis functions - analyze_autograd_memory() - analyze_gradient_computation() - - # Run comprehensive module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] diff --git a/modules/06_optimizers/optimizers_dev.py b/modules/06_optimizers/optimizers_dev.py index e87b0f8b..aae09474 100644 --- a/modules/06_optimizers/optimizers_dev.py +++ b/modules/06_optimizers/optimizers_dev.py @@ -1408,26 +1408,8 @@ def test_module(): print("Run: tito module complete 06_optimizers") # %% -if __name__ == "__main__": - print("๐Ÿš€ Running Optimizers module...") - - # Run all unit tests - test_unit_optimizer_base() - test_unit_sgd_optimizer() - test_unit_adam_optimizer() - test_unit_adamw_optimizer() - - # Run integration demonstrations - demonstrate_optimizer_integration() - - # Run analysis functions - analyze_optimizer_memory_usage() - analyze_optimizer_convergence_behavior() - - # Run final module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] """ diff --git a/modules/07_training/training_dev.py b/modules/07_training/training_dev.py index 06a7b5ac..d079af93 100644 --- a/modules/07_training/training_dev.py +++ b/modules/07_training/training_dev.py @@ -1307,25 +1307,8 @@ def test_module(): # test_module() # Moved to main guard # %% nbgrader={"grade": false, "grade_id": "main", "locked": false, "solution": false} -if __name__ == "__main__": - print("๐Ÿš€ Running Training module...") - - # Run all unit tests - test_unit_cosine_schedule() - test_unit_clip_grad_norm() - test_unit_trainer() - - # Run demonstrations - demonstrate_complete_training() - - # Run analysis functions - analyze_training_memory() - analyze_batch_size_effects() - - # Run final integration test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown] """ diff --git a/modules/08_dataloader/dataloader_dev.py b/modules/08_dataloader/dataloader_dev.py index f6913d9a..b66d334f 100644 --- a/modules/08_dataloader/dataloader_dev.py +++ b/modules/08_dataloader/dataloader_dev.py @@ -1163,31 +1163,9 @@ def test_module(): print("๐ŸŽ‰ ALL TESTS PASSED! Module ready for export.") print("Run: tito module complete 08") -# Call before module summary -# test_module() # Moved to main block - - # %% -if __name__ == "__main__": - print("๐Ÿš€ Running DataLoader module...") - - # Run all unit tests - test_unit_dataset() - test_unit_tensordataset() - test_unit_dataloader() - test_unit_download_functions() - - # Run performance analysis - analyze_dataloader_performance() - analyze_memory_usage() - - # Run integration test - test_training_integration() - - # Run final module test - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() diff --git a/modules/09_spatial/spatial_dev.py b/modules/09_spatial/spatial_dev.py index 83648138..ab50431a 100644 --- a/modules/09_spatial/spatial_dev.py +++ b/modules/09_spatial/spatial_dev.py @@ -1667,29 +1667,9 @@ def test_module(): print("๐ŸŽ‰ ALL TESTS PASSED! Module ready for export.") print("Run: tito module complete 09") -# Integration test will be called in main execution - # %% nbgrader={"grade": false, "grade_id": "main-execution", "solution": true} - -if __name__ == "__main__": - print("๐Ÿš€ Running Spatial Operations module...") - - # Run all unit tests - print("\n๐Ÿ”ฌ Running Unit Tests...") - test_unit_conv2d() - test_unit_pooling() - test_unit_simple_cnn() - - # Run systems analysis - print("\n๐Ÿ“Š Running Systems Analysis...") - analyze_convolution_complexity() - analyze_pooling_effects() - - # Run final integration test - print("\n๐Ÿงช Running Integration Test...") - test_module() - - print("โœ… Module validation complete!") +# Run comprehensive module test +test_module() # %% [markdown]