mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-04-30 02:17:31 -05:00
🎯 NBGRADER STRUCTURE IMPLEMENTED: - Added proper NBGrader cell metadata to modules/00_setup/setup_dev.py - Solution cells: nbgrader={'solution': true, 'locked': false} - Test cells: nbgrader={'grade': true, 'locked': true, 'points': X} - Proper grade_id for each cell for tracking 🧹 CLEAN STUDENT ASSIGNMENTS: - No hidden instructor solutions in student version - Only TODO stubs with clear instructions and hints - NBGrader automatically replaces with 'YOUR CODE HERE' - Proper point allocation: hello_tinytorch (3pts), add_numbers (2pts), SystemInfo (5pts) 🔧 WORKING WORKFLOW VERIFIED: 1. Edit modules/XX/XX_dev.py (Python source) 2. tito nbgrader generate XX (Python → Jupyter with NBGrader metadata) 3. tito nbgrader release XX (Clean student version generated) 4. Students work on assignments/release/XX/XX.ipynb 5. tito nbgrader collect/autograde for grading ✅ TESTED COMPONENTS: - Python file with proper Jupytext headers ✅ - NBGrader cell metadata generation ✅ - Student assignment generation ✅ - Clean TODO stubs without solutions ✅ - Release process working ✅ 🎓 EDUCATIONAL STRUCTURE: - Clear learning objectives and explanations - Step-by-step TODO instructions with hints - Immediate testing with auto-graded cells - Progressive difficulty (functions → classes → optional challenges) - Real-world context and examples Perfect implementation of Python-first development with NBGrader compliance
418 lines
12 KiB
Plaintext
418 lines
12 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "e09ac9b8",
|
|
"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": "f884eb8d",
|
|
"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",
|
|
"import os\n",
|
|
"from pathlib import Path\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": "57dae96e",
|
|
"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": "374b47e9",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"lines_to_next_cell": 1,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "82d6855522ae64c022b6cc1585668590",
|
|
"grade": false,
|
|
"grade_id": "hello-function",
|
|
"locked": false,
|
|
"schema_version": 3,
|
|
"solution": true,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# YOUR CODE HERE\n",
|
|
"raise NotImplementedError()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "66131eb2",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"lines_to_next_cell": 1,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "24f63eb78c3d96dda7f72a4583d14db3",
|
|
"grade": false,
|
|
"grade_id": "add-function",
|
|
"locked": false,
|
|
"schema_version": 3,
|
|
"solution": true,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# YOUR CODE HERE\n",
|
|
"raise NotImplementedError()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "9fe4d562",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"### 🧪 Test Your Implementation\n",
|
|
"\n",
|
|
"Once you implement the functions above, run this cell to test them:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "26efee28",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"editable": false,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "8a1b2fee6b8ce8608d25236f6f73d86e",
|
|
"grade": true,
|
|
"grade_id": "test-hello-function",
|
|
"locked": true,
|
|
"points": 3,
|
|
"schema_version": 3,
|
|
"solution": false,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Test hello_tinytorch function\n",
|
|
"print(\"Testing hello_tinytorch():\")\n",
|
|
"try:\n",
|
|
" hello_tinytorch()\n",
|
|
" print(\"✅ hello_tinytorch() executed successfully!\")\n",
|
|
"except NotImplementedError:\n",
|
|
" print(\"❌ hello_tinytorch() not implemented yet\")\n",
|
|
" raise"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "85d77269",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"editable": false,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "6d20b99d17de8236877c792f1234bb7a",
|
|
"grade": true,
|
|
"grade_id": "test-add-function",
|
|
"locked": true,
|
|
"points": 2,
|
|
"schema_version": 3,
|
|
"solution": false,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Test add_numbers function\n",
|
|
"print(\"Testing add_numbers():\")\n",
|
|
"assert add_numbers(2, 3) == 5, \"add_numbers(2, 3) should return 5\"\n",
|
|
"assert add_numbers(0, 0) == 0, \"add_numbers(0, 0) should return 0\"\n",
|
|
"assert add_numbers(-1, 1) == 0, \"add_numbers(-1, 1) should return 0\"\n",
|
|
"assert abs(add_numbers(1.5, 2.5) - 4.0) < 1e-10, \"add_numbers(1.5, 2.5) should return 4.0\"\n",
|
|
"print(\"✅ All addition tests passed!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3a78485f",
|
|
"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": "25514369",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"lines_to_next_cell": 1,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "72a2cd7502f98c53fa0a3347b7d7dd4d",
|
|
"grade": false,
|
|
"grade_id": "systeminfo-class",
|
|
"locked": false,
|
|
"schema_version": 3,
|
|
"solution": true,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# YOUR CODE HERE\n",
|
|
"raise NotImplementedError()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "34df8a39",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"### 🧪 Test Your SystemInfo Class\n",
|
|
"\n",
|
|
"Once you implement the SystemInfo class above, run this cell to test it:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "7063bc1b",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"editable": false,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "fac2b261e84d2bb5699047dcaeb40a7b",
|
|
"grade": true,
|
|
"grade_id": "test-systeminfo-creation",
|
|
"locked": true,
|
|
"points": 2,
|
|
"schema_version": 3,
|
|
"solution": false,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Test SystemInfo creation\n",
|
|
"print(\"Testing SystemInfo creation...\")\n",
|
|
"info = SystemInfo()\n",
|
|
"assert hasattr(info, 'python_version'), \"SystemInfo should have python_version attribute\"\n",
|
|
"assert hasattr(info, 'platform'), \"SystemInfo should have platform attribute\"\n",
|
|
"assert hasattr(info, 'machine'), \"SystemInfo should have machine attribute\"\n",
|
|
"print(\"✅ SystemInfo creation test passed!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "bb5becb5",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"editable": false,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "f88e6bbeb4a7f16f627fd94b76813aef",
|
|
"grade": true,
|
|
"grade_id": "test-systeminfo-str",
|
|
"locked": true,
|
|
"points": 2,
|
|
"schema_version": 3,
|
|
"solution": false,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Test SystemInfo string representation\n",
|
|
"print(\"Testing SystemInfo string representation...\")\n",
|
|
"info = SystemInfo()\n",
|
|
"info_str = str(info)\n",
|
|
"assert isinstance(info_str, str), \"SystemInfo.__str__() should return a string\"\n",
|
|
"assert len(info_str) > 0, \"SystemInfo string should not be empty\"\n",
|
|
"assert 'Python' in info_str, \"SystemInfo string should contain 'Python'\"\n",
|
|
"print(f\"✅ SystemInfo string: {info_str}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5794302f",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"editable": false,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "12946d9773aa33029e450c56acc0c040",
|
|
"grade": true,
|
|
"grade_id": "test-systeminfo-compatibility",
|
|
"locked": true,
|
|
"points": 1,
|
|
"schema_version": 3,
|
|
"solution": false,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Test SystemInfo compatibility check\n",
|
|
"print(\"Testing SystemInfo compatibility...\")\n",
|
|
"info = SystemInfo()\n",
|
|
"compatible = info.is_compatible()\n",
|
|
"assert isinstance(compatible, bool), \"is_compatible() should return a boolean\"\n",
|
|
"# Since we're running this test, Python should be >= 3.8\n",
|
|
"assert compatible == True, \"Current Python version should be compatible (>= 3.8)\"\n",
|
|
"print(\"✅ SystemInfo compatibility test passed!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "29aec3ad",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\"",
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"source": [
|
|
"## Step 3: Developer Profile (Optional Challenge)\n",
|
|
"\n",
|
|
"For students who want an extra challenge, implement a DeveloperProfile class:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5a495cf8",
|
|
"metadata": {
|
|
"deletable": false,
|
|
"lines_to_next_cell": 1,
|
|
"nbgrader": {
|
|
"cell_type": "code",
|
|
"checksum": "35c7dde39a02195892c886c937343401",
|
|
"grade": false,
|
|
"grade_id": "developer-profile",
|
|
"locked": false,
|
|
"schema_version": 3,
|
|
"solution": true,
|
|
"task": false
|
|
}
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# YOUR CODE HERE\n",
|
|
"raise NotImplementedError()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "a98989f9",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"## 🎯 Module Summary\n",
|
|
"\n",
|
|
"Congratulations! You've completed the TinyTorch setup module:\n",
|
|
"\n",
|
|
"### What You've Accomplished\n",
|
|
"✅ **Environment Setup**: Learned the development workflow \n",
|
|
"✅ **First Function**: Implemented hello_tinytorch() with file handling \n",
|
|
"✅ **Math Operations**: Built add_numbers() for ML foundations \n",
|
|
"✅ **Object-Oriented Programming**: Created SystemInfo class with properties \n",
|
|
"✅ **Testing**: Verified your implementations with automated tests \n",
|
|
"✅ **Package Export**: Used nbdev to build the tinytorch package \n",
|
|
"\n",
|
|
"### Key Concepts You've Learned\n",
|
|
"- **nbdev workflow**: From notebook to production package\n",
|
|
"- **File handling**: Reading ASCII art with graceful fallbacks\n",
|
|
"- **System information**: Collecting platform and version data\n",
|
|
"- **Object-oriented design**: Classes, properties, and methods\n",
|
|
"- **Error handling**: Using try/except and fallback strategies\n",
|
|
"\n",
|
|
"### Next Steps\n",
|
|
"1. **Export your code**: Run `python bin/tito.py sync --module setup`\n",
|
|
"2. **Run tests**: Use `python bin/tito.py test --module setup`\n",
|
|
"3. **Check your work**: Import your functions with `from tinytorch.core.utils import hello_tinytorch`\n",
|
|
"\n",
|
|
"**Ready for the next challenge?** Let's move on to building tensors!"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"jupytext": {
|
|
"main_language": "python"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|