# Test the functions in the notebook
print(hello_tinytorch())
print(f"2 + 3 = {add_numbers(2, 3)}")Module 0: Setup - Tiny๐ฅTorch Development Workflow
Welcome to TinyTorch! This module teaches you the development workflow youโll use throughout the course.
Learning Goals
- Understand the nbdev notebook-to-Python workflow
- Write your first TinyTorch code
- Run tests and use the CLI tools
- Get comfortable with the development rhythm
The TinyTorch Development Cycle
- Write code in this notebook using
#| export - Export code with
python bin/tito.py sync - Run tests with
python bin/tito.py test --module setup - Check progress with
python bin/tito.py info
Letโs get started!
::: {#cell-1 .cell 0=โdโ 1=โeโ 2=โfโ 3=โaโ 4=โuโ 5=โlโ 6=โtโ 7=โ_โ 8=โeโ 9=โxโ 10=โpโ 11=โ โ 12=โcโ 13=โoโ 14=โrโ 15=โeโ 16=โ.โ 17=โuโ 18=โtโ 19=โiโ 20=โlโ 21=โsโ}
# Setup imports and environment
import sys
import platform
from datetime import datetime
print("๐ฅ TinyTorch Development Environment")
print(f"Python {sys.version}")
print(f"Platform: {platform.system()} {platform.release()}")
print(f"Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"):::
Step 1: Understanding the Module โ Package Structure
๐ Teaching vs. ๐ง Building: This course has two sides: - Teaching side: You work in modules/setup/setup_dev.ipynb (learning-focused) - Building side: Your code exports to tinytorch/core/utils.py (production package)
Key Concept: The #| default_exp core.utils directive at the top tells nbdev to export all #| export cells to tinytorch/core/utils.py.
This separation allows us to: - Organize learning by concepts (modules)
- Organize code by function (package structure) - Build a real ML framework while learning systematically
Letโs write a simple โHello Worldโ function with the #| export directive:
::: {#cell-3 .cell 0=โeโ 1=โxโ 2=โpโ 3=โoโ 4=โrโ 5=โtโ}
def hello_tinytorch():
"""A simple hello world function for TinyTorch."""
return "Hello from TinyTorch! ๐ฅ"
def add_numbers(a, b):
"""Add two numbers together."""
return a + b:::
Step 2: A Simple Class
Letโs create a simple class that will help us understand system information. This is still basic, but shows how to structure classes in TinyTorch.
::: {#cell-6 .cell 0=โeโ 1=โxโ 2=โpโ 3=โoโ 4=โrโ 5=โtโ}
import sys
import platform
class SystemInfo:
"""Simple system information class."""
def __init__(self):
self.python_version = sys.version_info
self.platform = platform.system()
self.machine = platform.machine()
def __str__(self):
return f"Python {self.python_version.major}.{self.python_version.minor} on {self.platform} ({self.machine})"
def is_compatible(self):
"""Check if system meets minimum requirements."""
return self.python_version >= (3, 8):::
# Test the SystemInfo class
info = SystemInfo()
print(f"System: {info}")
print(f"Compatible: {info.is_compatible()}")Step 3: Try the Export Process
Now letโs export our code! In your terminal, run:
python bin/tito.py sync --module setupThis will export the code marked with #| export to tinytorch/core/utils.py.
What happens during export: 1. nbdev scans this notebook for #| export cells 2. Extracts the Python code
3. Writes it to tinytorch/core/utils.py (because of #| default_exp core.utils) 4. Handles imports and dependencies automatically
๐ Verification: After export, check tinytorch/core/utils.py - youโll see your functions there with auto-generated headers pointing back to this notebook!
Step 4: Run Tests
After exporting, run the tests:
python bin/tito.py test --module setupThis will run all tests for the setup module and verify your implementation works correctly.
Step 5: Check Your Progress
See your overall progress:
python bin/tito.py infoThis shows which modules are complete and which are pending.
๐ Congratulations!
Youโve learned the TinyTorch development workflow:
- โ
Write code in notebooks with
#| export - โ
Export with
tito sync
- โ
Test with
tito test --module setup - โ
Check progress with
tito info
This is the rhythm youโll use for every module in TinyTorch.
Next Steps
Ready for the real work? Head to Module 1: Tensor where youโll build the core data structures that power everything else in TinyTorch.
Development Tips: - Always test your code in the notebook first - Export frequently to catch issues early
- Read error messages carefully - theyโre designed to help - When stuck, check if your code exports cleanly first
Happy building! ๐ฅ