diff --git a/docs/development/module-template.md b/docs/development/module-template.md new file mode 100644 index 00000000..d28bb53f --- /dev/null +++ b/docs/development/module-template.md @@ -0,0 +1,55 @@ +# Module Template: "Where This Code Lives" Section + +## 📦 Where This Code Lives in the Final Package + +**Learning Side:** You work in `modules/{module_name}/{module_name}_dev.py` +**Building Side:** Code exports to `tinytorch.core.{destination}` + +```python +# Final package structure: +from tinytorch.core.{destination} import {exported_classes} +from tinytorch.core.tensor import Tensor +``` + +**Why this matters:** +- **Learning:** Focused modules for deep understanding +- **Production:** Proper organization like industry frameworks +- **Consistency:** Related functionality grouped together + +## Template Variables + +Replace these placeholders in each module: + +- `{module_name}`: The module directory name (e.g., "tensor", "layers", "cnn") +- `{destination}`: Where the code exports in the final package (e.g., "tensor", "layers", "activations") +- `{exported_classes}`: The main classes/functions being exported (e.g., "Tensor", "Dense, Conv2D", "ReLU, Sigmoid") + +## Examples + +### Tensor Module +```python +# Learning Side: modules/tensor/tensor_dev.py +# Building Side: tinytorch.core.tensor +from tinytorch.core.tensor import Tensor +``` + +### Layers Module +```python +# Learning Side: modules/layers/layers_dev.py +# Building Side: tinytorch.core.layers +from tinytorch.core.layers import Dense, Conv2D +``` + +### CNN Module +```python +# Learning Side: modules/cnn/cnn_dev.py +# Building Side: tinytorch.core.layers (Conv2D lives with Dense) +from tinytorch.core.layers import Dense, Conv2D +``` + +## Usage Instructions + +1. Copy this template section into each module's `*_dev.py` file +2. Replace the template variables with module-specific values +3. Update the `#| default_exp` directive to match the destination +4. Ensure the exported classes match what's actually being exported \ No newline at end of file diff --git a/modules/activations/activations_dev.py b/modules/activations/activations_dev.py index 582933ff..162a03cf 100644 --- a/modules/activations/activations_dev.py +++ b/modules/activations/activations_dev.py @@ -41,6 +41,23 @@ Linear → Activation → Linear = Can learn complex patterns! Each function serves different purposes and has different mathematical properties. +## 📦 Where This Code Lives in the Final Package + +**Learning Side:** You work in `modules/activations/activations_dev.py` +**Building Side:** Code exports to `tinytorch.core.activations` + +```python +# Final package structure: +from tinytorch.core.activations import ReLU, Sigmoid, Tanh +from tinytorch.core.tensor import Tensor +from tinytorch.core.layers import Dense, Conv2D +``` + +**Why this matters:** +- **Learning:** Focused modules for deep understanding +- **Production:** Proper organization like PyTorch's `torch.nn.functional` +- **Consistency:** All activation functions live together in `core.activations` + --- Let's start building! 🚀 diff --git a/modules/cnn/cnn_dev.py b/modules/cnn/cnn_dev.py index c36a3bc3..a6a94c79 100644 --- a/modules/cnn/cnn_dev.py +++ b/modules/cnn/cnn_dev.py @@ -22,6 +22,26 @@ Welcome to the CNN module! Here you'll implement the core building block of mode - (Stretch) Explore stride, padding, pooling, and multi-channel input """ +# %% [markdown] +""" +## 📦 Where This Code Lives in the Final Package + +**Learning Side:** You work in `modules/cnn/cnn_dev.py` +**Building Side:** Code exports to `tinytorch.core.layers` + +```python +# Final package structure: +from tinytorch.core.layers import Dense, Conv2D # Both layers together! +from tinytorch.core.activations import ReLU +from tinytorch.core.tensor import Tensor +``` + +**Why this matters:** +- **Learning:** Focused modules for deep understanding +- **Production:** Proper organization like PyTorch's `torch.nn` +- **Consistency:** All layers (Dense, Conv2D) live together in `core.layers` +""" + # %% #| default_exp core.cnn diff --git a/modules/layers/layers_dev.py b/modules/layers/layers_dev.py index 816c4318..04f18fa3 100644 --- a/modules/layers/layers_dev.py +++ b/modules/layers/layers_dev.py @@ -30,13 +30,26 @@ Welcome to the Layers module! This is where neural networks begin. You'll implem This module builds on the **activations** module: - **activations** → **layers** → **networks** - Clean separation of concerns: math functions → layer building blocks → full networks +""" -## Module → Package Structure -**🎓 Teaching vs. 🔧 Building**: -- **Learning side**: Work in `modules/layers/layers_dev.py` -- **Building side**: Exports to `tinytorch/core/layers.py` +# %% [markdown] +""" +## 📦 Where This Code Lives in the Final Package -This module builds the fundamental transformations that compose into neural networks. +**Learning Side:** You work in `modules/layers/layers_dev.py` +**Building Side:** Code exports to `tinytorch.core.layers` + +```python +# Final package structure: +from tinytorch.core.layers import Dense, Conv2D # All layers together! +from tinytorch.core.activations import ReLU, Sigmoid, Tanh +from tinytorch.core.tensor import Tensor +``` + +**Why this matters:** +- **Learning:** Focused modules for deep understanding +- **Production:** Proper organization like PyTorch's `torch.nn` +- **Consistency:** All layers (Dense, Conv2D) live together in `core.layers` """ # %% diff --git a/modules/tensor/tensor_dev.py b/modules/tensor/tensor_dev.py index 68494408..eea6bbf8 100644 --- a/modules/tensor/tensor_dev.py +++ b/modules/tensor/tensor_dev.py @@ -20,12 +20,27 @@ Welcome to the Tensor module! This is where TinyTorch really begins. You'll impl - Handle shape management, data types, and memory layout - Build the foundation for neural networks and automatic differentiation -## Module → Package Structure -**🎓 Teaching vs. 🔧 Building**: -- **Learning side**: Work in `modules/tensor/tensor_dev.py` -- **Building side**: Exports to `tinytorch/core/tensor.py` +""" -This module builds the core data structure that all other TinyTorch components will use. +# %% [markdown] +""" +## 📦 Where This Code Lives in the Final Package + +**Learning Side:** You work in `modules/tensor/tensor_dev.py` +**Building Side:** Code exports to `tinytorch.core.tensor` + +```python +# Final package structure: +from tinytorch.core.tensor import Tensor +from tinytorch.core.layers import Dense, Conv2D +from tinytorch.core.activations import ReLU, Sigmoid, Tanh +``` + +**Why this matters:** +- **Learning:** Focused modules for deep understanding +- **Production:** Proper organization like PyTorch's `torch.tensor` +- **Consistency:** Core data structure lives in `core.tensor` +""" """ # %%