diff --git a/modules/source/01_setup/setup_dev.py b/modules/source/01_setup/setup_dev.py index 0db553f6..2d771746 100644 --- a/modules/source/01_setup/setup_dev.py +++ b/modules/source/01_setup/setup_dev.py @@ -456,6 +456,13 @@ Now let's test your configuration functions! Once you implement both functions above, run this cell to test them: """ +# %% [markdown] +""" +### 🧪 Unit Test: Personal Information Configuration + +This test validates your `personal_info()` function implementation, ensuring it returns properly formatted developer information for system attribution and collaboration. +""" + # %% def test_unit_personal_info_basic(): """Test personal_info function implementation.""" @@ -493,6 +500,13 @@ def test_unit_personal_info_basic(): # Run the test test_unit_personal_info_basic() +# %% [markdown] +""" +### 🧪 Unit Test: System Information Query + +This test validates your `system_info()` function implementation, ensuring it accurately detects and reports hardware and software specifications for performance optimization and debugging. +""" + # %% def test_unit_system_info_basic(): """Test system_info function implementation.""" diff --git a/modules/source/02_tensor/tensor_dev.py b/modules/source/02_tensor/tensor_dev.py index 2100dd12..43f02d39 100644 --- a/modules/source/02_tensor/tensor_dev.py +++ b/modules/source/02_tensor/tensor_dev.py @@ -820,6 +820,13 @@ Congratulations! You've successfully implemented the core Tensor class for TinyT **Ready for the next challenge?** Let's add the mathematical functions that make neural networks powerful! """ +# %% [markdown] +""" +### 🧪 Unit Test: Tensor Creation + +This test validates your `Tensor` class constructor, ensuring it correctly handles scalars, vectors, matrices, and higher-dimensional arrays with proper shape detection. +""" + # %% def test_unit_tensor_creation(): """Comprehensive test of tensor creation with all data types and shapes.""" @@ -841,6 +848,13 @@ def test_unit_tensor_creation(): # Run the test test_unit_tensor_creation() +# %% [markdown] +""" +### 🧪 Unit Test: Tensor Properties + +This test validates your tensor property methods (shape, size, dtype, data), ensuring they correctly reflect the tensor's dimensional structure and data characteristics. +""" + # %% def test_unit_tensor_properties(): """Comprehensive test of tensor properties (shape, size, dtype, data access).""" @@ -864,6 +878,13 @@ def test_unit_tensor_properties(): # Run the test test_unit_tensor_properties() +# %% [markdown] +""" +### 🧪 Unit Test: Tensor Arithmetic Operations + +This test validates your tensor arithmetic implementation (addition, multiplication, subtraction, division) and operator overloading, ensuring mathematical operations work correctly with proper broadcasting. +""" + # %% def test_unit_tensor_arithmetic(): """Comprehensive test of tensor arithmetic operations.""" diff --git a/modules/source/12_compression/compression_dev.py b/modules/source/12_compression/compression_dev.py index f21b8237..080f3994 100644 --- a/modules/source/12_compression/compression_dev.py +++ b/modules/source/12_compression/compression_dev.py @@ -365,6 +365,13 @@ class CompressionMetrics: 'dtype': dtype } +# %% [markdown] +""" +### 🧪 Unit Test: Compression Metrics Analysis + +This test validates your `CompressionMetrics` class implementation, ensuring it accurately calculates model parameters, memory usage, and compression statistics for optimization analysis. +""" + # %% nbgrader={"grade": false, "grade_id": "test-compression-metrics", "locked": false, "schema_version": 3, "solution": false, "task": false} def test_unit_compression_metrics(): """Unit test for the CompressionMetrics class.""" @@ -572,6 +579,13 @@ def calculate_sparsity(layer: Dense) -> float: return zero_weights / total_weights if total_weights > 0 else 0.0 ### END SOLUTION +# %% [markdown] +""" +### 🧪 Unit Test: Magnitude-Based Pruning + +This test validates your pruning implementation, ensuring it correctly identifies and removes the smallest weights while maintaining model functionality and calculating accurate sparsity metrics. +""" + # %% nbgrader={"grade": false, "grade_id": "test-pruning", "locked": false, "schema_version": 3, "solution": false, "task": false} def test_unit_magnitude_pruning(): """Unit test for the magnitude-based pruning functionality.""" @@ -759,6 +773,13 @@ def quantize_layer_weights(layer: Dense, bits: int = 8) -> Tuple[Dense, Dict[str return layer, quantization_info ### END SOLUTION +# %% [markdown] +""" +### 🧪 Unit Test: Weight Quantization + +This test validates your quantization implementation, ensuring it correctly converts FP32 weights to INT8 representation while minimizing accuracy loss and achieving significant memory reduction. +""" + # %% nbgrader={"grade": false, "grade_id": "test-quantization", "locked": false, "schema_version": 3, "solution": false, "task": false} def test_unit_quantization(): """Unit test for the weight quantization functionality.""" @@ -976,6 +997,13 @@ class DistillationLoss: probs = self._softmax(logits) return -np.mean(np.sum(labels * np.log(probs + 1e-10), axis=-1)) +# %% [markdown] +""" +### 🧪 Unit Test: Knowledge Distillation + +This test validates your knowledge distillation implementation, ensuring the student model learns effectively from teacher predictions while maintaining computational efficiency. +""" + # %% nbgrader={"grade": false, "grade_id": "test-distillation", "locked": false, "schema_version": 3, "solution": false, "task": false} def test_unit_distillation(): """Unit test for the DistillationLoss class.""" @@ -1260,6 +1288,13 @@ def prune_layer_neurons(layer: Dense, keep_ratio: float = 0.7, return pruned_layer, pruning_info ### END SOLUTION +# %% [markdown] +""" +### 🧪 Unit Test: Structured Pruning + +This test validates your structured pruning implementation, ensuring it correctly removes entire neurons or channels while maintaining model architecture integrity and computational efficiency. +""" + # %% nbgrader={"grade": false, "grade_id": "test-structured-pruning", "locked": false, "schema_version": 3, "solution": false, "task": false} def test_unit_structured_pruning(): """Unit test for the structured pruning (neuron pruning) functionality.""" @@ -1590,6 +1625,13 @@ Each compression technique includes comprehensive unit tests: This module teaches the essential skills for deploying AI in resource-constrained environments! """ +# %% [markdown] +""" +### 🧪 Unit Test: Comprehensive Compression Comparison + +This test validates the complete compression pipeline, comparing different techniques (pruning, quantization, distillation) to analyze their effectiveness and trade-offs in model optimization. +""" + # %% nbgrader={"grade": false, "grade_id": "test-comprehensive-comparison", "locked": false, "schema_version": 3, "solution": false, "task": false} def test_unit_comprehensive_comparison(): """Unit test for the comparison of different compression techniques.""" @@ -1661,6 +1703,13 @@ def test_unit_comprehensive_comparison(): # Run the test test_unit_comprehensive_comparison() +# %% [markdown] +""" +### 🧪 Integration Test: Compression with Sequential Models + +This integration test validates that all compression techniques work seamlessly with TinyTorch's Sequential models, ensuring proper layer integration and end-to-end functionality. +""" + # %% def test_compression_integration(): """Integration test for applying compression to a Sequential model.""" @@ -1693,6 +1742,13 @@ def test_compression_integration(): print("✅ Integration Test Passed: Pruning correctly modified a layer in a Sequential model.") +# %% [markdown] +""" +### 🧪 Integration Test: Comprehensive Compression Pipeline + +This comprehensive integration test validates the complete compression workflow, applying multiple techniques in sequence and ensuring proper interaction between compression methods and model architectures. +""" + # %% def test_comprehensive_compression_integration(): """