Files
TinyTorch/modules/setup/setup_dev.ipynb
Vijay Janapa Reddi 6d8fb078f7 🧹 Clean up setup module - NBDev behind the scenes
- Focused on original purpose: just setting up development environment
- Students don't see NBDev educational features explanations
- Simple workflow: hello world, basic class, export, test, progress
- NBDev #|hide directive works behind scenes for instructor solutions
- Clean and simple, just like the original but with hidden solutions

Back to basics: setup is about setup, not teaching NBDev features
2025-07-10 16:30:23 -04:00

271 lines
7.8 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "7dcaa167",
"metadata": {
"cell_marker": "\"\"\""
},
"source": [
"# Module 0: Setup - Tiny🔥Torch Development Workflow\n",
"\n",
"Welcome to TinyTorch! This module teaches you the development workflow you'll use throughout the course.\n",
"\n",
"## Learning Goals\n",
"- Understand the nbdev notebook-to-Python workflow\n",
"- Write your first TinyTorch code\n",
"- Run tests and use the CLI tools\n",
"- Get comfortable with the development rhythm\n",
"\n",
"## The TinyTorch Development Cycle\n",
"\n",
"1. **Write code** in this notebook using `#| export` \n",
"2. **Export code** with `python bin/tito.py sync --module setup`\n",
"3. **Run tests** with `python bin/tito.py test --module setup`\n",
"4. **Check progress** with `python bin/tito.py info`\n",
"\n",
"Let's get started!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "70bc17f4",
"metadata": {},
"outputs": [],
"source": [
"#| default_exp core.utils\n",
"\n",
"# Setup imports and environment\n",
"import sys\n",
"import platform\n",
"from datetime import datetime\n",
"\n",
"print(\"🔥 TinyTorch Development Environment\")\n",
"print(f\"Python {sys.version}\")\n",
"print(f\"Platform: {platform.system()} {platform.release()}\")\n",
"print(f\"Started: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\")"
]
},
{
"cell_type": "markdown",
"id": "d476652e",
"metadata": {
"cell_marker": "\"\"\"",
"lines_to_next_cell": 1
},
"source": [
"## Step 1: Understanding the Module → Package Structure\n",
"\n",
"**🎓 Teaching vs. 🔧 Building**: This course has two sides:\n",
"- **Teaching side**: You work in `modules/setup/setup_dev.ipynb` (learning-focused)\n",
"- **Building side**: Your code exports to `tinytorch/core/utils.py` (production package)\n",
"\n",
"**Key Concept**: The `#| default_exp core.utils` directive at the top tells nbdev to export all `#| export` cells to `tinytorch/core/utils.py`.\n",
"\n",
"This separation allows us to:\n",
"- Organize learning by **concepts** (modules) \n",
"- Organize code by **function** (package structure)\n",
"- Build a real ML framework while learning systematically\n",
"\n",
"Let's write a simple \"Hello World\" function with the `#| export` directive:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ce956cf5",
"metadata": {
"lines_to_next_cell": 1
},
"outputs": [],
"source": [
"#| export\n",
"def hello_tinytorch():\n",
" \"\"\"\n",
" A simple hello world function for TinyTorch.\n",
" \n",
" TODO: Make this return a more welcoming message about TinyTorch.\n",
" \"\"\"\n",
" return \"Hello from TinyTorch! 🔥\"\n",
"\n",
"def add_numbers(a, b):\n",
" \"\"\"Add two numbers together.\"\"\"\n",
" return a + b"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da7b047a",
"metadata": {
"lines_to_next_cell": 1
},
"outputs": [],
"source": [
"#| hide\n",
"#| export\n",
"def hello_tinytorch():\n",
" \"\"\"A simple hello world function for TinyTorch.\"\"\"\n",
" return \"🔥 Welcome to TinyTorch! Ready to build ML systems from scratch? Let's go! 🔥\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffa17648",
"metadata": {},
"outputs": [],
"source": [
"# Test the functions in the notebook\n",
"print(hello_tinytorch())\n",
"print(f\"2 + 3 = {add_numbers(2, 3)}\")"
]
},
{
"cell_type": "markdown",
"id": "98dd35dc",
"metadata": {
"cell_marker": "\"\"\"",
"lines_to_next_cell": 1
},
"source": [
"## Step 2: A Simple Class\n",
"\n",
"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_type": "code",
"execution_count": null,
"id": "8adcd70a",
"metadata": {
"lines_to_next_cell": 1
},
"outputs": [],
"source": [
"#| export\n",
"class SystemInfo:\n",
" \"\"\"Simple system information class.\"\"\"\n",
" \n",
" def __init__(self):\n",
" self.python_version = sys.version_info\n",
" self.platform = platform.system()\n",
" self.machine = platform.machine()\n",
" \n",
" def __str__(self):\n",
" return f\"Python {self.python_version.major}.{self.python_version.minor} on {self.platform} ({self.machine})\"\n",
" \n",
" def is_compatible(self):\n",
" \"\"\"Check if system meets minimum requirements.\"\"\"\n",
" return self.python_version >= (3, 8)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28f33bb2",
"metadata": {},
"outputs": [],
"source": [
"# Test the SystemInfo class\n",
"info = SystemInfo()\n",
"print(f\"System: {info}\")\n",
"print(f\"Compatible: {info.is_compatible()}\")"
]
},
{
"cell_type": "markdown",
"id": "2eae1d7f",
"metadata": {
"cell_marker": "\"\"\""
},
"source": [
"## Step 3: Try the Export Process\n",
"\n",
"Now let's export our code! In your terminal, run:\n",
"\n",
"```bash\n",
"python bin/tito.py sync --module setup\n",
"```\n",
"\n",
"This will export the code marked with `#| export` to `tinytorch/core/utils.py`.\n",
"\n",
"**What happens during export:**\n",
"1. nbdev scans this notebook for `#| export` cells\n",
"2. Extracts the Python code \n",
"3. Writes it to `tinytorch/core/utils.py` (because of `#| default_exp core.utils`)\n",
"4. Handles imports and dependencies automatically\n",
"\n",
"**🔍 Verification**: After export, check `tinytorch/core/utils.py` - you'll see your functions there with auto-generated headers pointing back to this notebook!"
]
},
{
"cell_type": "markdown",
"id": "881a8525",
"metadata": {
"cell_marker": "\"\"\""
},
"source": [
"## Step 4: Run Tests\n",
"\n",
"After exporting, run the tests:\n",
"\n",
"```bash\n",
"python bin/tito.py test --module setup\n",
"```\n",
"\n",
"This will run all tests for the setup module and verify your implementation works correctly.\n",
"\n",
"## Step 5: Check Your Progress\n",
"\n",
"See your overall progress:\n",
"\n",
"```bash\n",
"python bin/tito.py info\n",
"```\n",
"\n",
"This shows which modules are complete and which are pending."
]
},
{
"cell_type": "markdown",
"id": "7a8262c8",
"metadata": {
"cell_marker": "\"\"\""
},
"source": [
"## 🎉 Congratulations!\n",
"\n",
"You've learned the TinyTorch development workflow:\n",
"\n",
"1. ✅ Write code in notebooks with `#| export`\n",
"2. ✅ Export with `tito sync --module setup` \n",
"3. ✅ Test with `tito test --module setup`\n",
"4. ✅ Check progress with `tito info`\n",
"\n",
"**This is the rhythm you'll use for every module in TinyTorch.**\n",
"\n",
"### Next Steps\n",
"\n",
"Ready for the real work? Head to **Module 1: Tensor** where you'll build the core data structures that power everything else in TinyTorch.\n",
"\n",
"**Development Tips:**\n",
"- Always test your code in the notebook first\n",
"- Export frequently to catch issues early \n",
"- Read error messages carefully - they're designed to help\n",
"- When stuck, check if your code exports cleanly first\n",
"\n",
"Happy building! 🔥"
]
}
],
"metadata": {
"jupytext": {
"main_language": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}