mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-04-27 15:47:30 -05:00
- Restore complete setup module with system information and developer profiles - Add NBDev educational patterns with #| export and #| hide directives - Implement SystemInfo class for platform detection and compatibility checking - Add DeveloperProfile class with ASCII art customization and personalization - Include comprehensive educational content with step-by-step learning progression - Expand test suite to 20 comprehensive tests covering all functionality: - Function execution and output validation - Arithmetic operations (basic, negative, floating-point) - System information collection and compatibility - Developer profile creation and customization - ASCII art file loading and fallback behavior - Error recovery and integration testing - Update README with complete feature documentation and usage examples - Convert to executed notebook showing rich output and system information - Maintain file-based ASCII art system with tinytorch_flame.txt - All tests passing with professional pytest structure
911 lines
37 KiB
Plaintext
911 lines
37 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "695331d6",
|
|
"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": 1,
|
|
"id": "77e98f62",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.070182Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.069869Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.076126Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.075657Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"🔥 TinyTorch Development Environment\n",
|
|
"Python 3.13.3 (v3.13.3:6280bb54784, Apr 8 2025, 10:47:54) [Clang 15.0.0 (clang-1500.3.9.4)]\n",
|
|
"Platform: Darwin 24.5.0\n",
|
|
"Started: 2025-07-10 19:28:59\n"
|
|
]
|
|
}
|
|
],
|
|
"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": "a1a9c143",
|
|
"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": 2,
|
|
"id": "d41c28bc",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.078349Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.078166Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.080816Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.080472Z"
|
|
},
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#| export\n",
|
|
"def hello_tinytorch():\n",
|
|
" \"\"\"\n",
|
|
" A simple hello world function for TinyTorch.\n",
|
|
" \n",
|
|
" TODO: Implement this function to display TinyTorch ASCII art and welcome message.\n",
|
|
" Load the flame art from tinytorch_flame.txt file with graceful fallback.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
"\n",
|
|
"def add_numbers(a, b):\n",
|
|
" \"\"\"\n",
|
|
" Add two numbers together.\n",
|
|
" \n",
|
|
" TODO: Implement addition of two numbers.\n",
|
|
" This is the foundation of all mathematical operations in ML.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "0a8001ec",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.082743Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.082583Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.086912Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.086623Z"
|
|
},
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#| hide\n",
|
|
"#| export\n",
|
|
"def hello_tinytorch():\n",
|
|
" \"\"\"Display the TinyTorch ASCII art and welcome message.\"\"\"\n",
|
|
" try:\n",
|
|
" # Get the directory containing this file\n",
|
|
" current_dir = Path(__file__).parent\n",
|
|
" art_file = current_dir / \"tinytorch_flame.txt\"\n",
|
|
" \n",
|
|
" if art_file.exists():\n",
|
|
" with open(art_file, 'r') as f:\n",
|
|
" ascii_art = f.read()\n",
|
|
" print(ascii_art)\n",
|
|
" print(\"Tiny🔥Torch\")\n",
|
|
" print(\"Build ML Systems from Scratch!\")\n",
|
|
" else:\n",
|
|
" print(\"🔥 TinyTorch 🔥\")\n",
|
|
" print(\"Build ML Systems from Scratch!\")\n",
|
|
" except NameError:\n",
|
|
" # Handle case when running in notebook where __file__ is not defined\n",
|
|
" try:\n",
|
|
" art_file = Path(os.getcwd()) / \"tinytorch_flame.txt\"\n",
|
|
" if art_file.exists():\n",
|
|
" with open(art_file, 'r') as f:\n",
|
|
" ascii_art = f.read()\n",
|
|
" print(ascii_art)\n",
|
|
" print(\"Tiny🔥Torch\")\n",
|
|
" print(\"Build ML Systems from Scratch!\")\n",
|
|
" else:\n",
|
|
" print(\"🔥 TinyTorch 🔥\")\n",
|
|
" print(\"Build ML Systems from Scratch!\")\n",
|
|
" except:\n",
|
|
" print(\"🔥 TinyTorch 🔥\")\n",
|
|
" print(\"Build ML Systems from Scratch!\")\n",
|
|
"\n",
|
|
"def add_numbers(a, b):\n",
|
|
" \"\"\"Add two numbers together.\"\"\"\n",
|
|
" return a + b"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b28103af",
|
|
"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": 4,
|
|
"id": "a1beca72",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.088616Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.088506Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.091981Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.091554Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Testing hello_tinytorch():\n",
|
|
". . ... ....... .... ... . . .. .... . .. . . . . . .... \n",
|
|
". . .. .++. .. . . . .. ... . . . .. ... .. \n",
|
|
" . . . .=++=.. . . . .. . . .. . ... .. . . \n",
|
|
". .. ... .++++=. . . . . .. . .. .\n",
|
|
". . . . ....-+++++.... ... .. . .... .. . . . . . . . . . . . . \n",
|
|
" . .. ...-++++++-...... .. . ..... ..-:.. .. . .... .. . . .. . .. . . . \n",
|
|
" .. .. ..++++++++-.. . . ..##... -%#. . . . . . \n",
|
|
". .. .:+++++++++.... ... . ...:%%:............:-:. ..... ...... . . ....... .. . . \n",
|
|
" ..+++++++++++. ... . .. .=#%%##+.-##..#%####%%=.=%%. .*%+.. . . . ... \n",
|
|
" . ..++++++++++++...-++..... . .%%... -##..##=...=%#..*%*..=%#.. . .. ... . . . . .. . ...\n",
|
|
" ..-+++++++++++++..=++++... .....%#.. -##..#%-.. -##. .%%=.%%.. . . . . . ... .\n",
|
|
". .=++++++++++++++-+++++++.... . ...%%:...-##..#%-. .-%#. ..#%#%=.. . .. ... . . . .\n",
|
|
"..=+++++++++++++++++++++++-. . ..=%%%+.-%#..##-. .-%#....-%%*.. . .. . .. .. .. \n",
|
|
".:+++++++++++=+++++++++++++. . ................ .......-%%... . .. . . .. . \n",
|
|
".++++++++++===+++++++++++++: . .................... . ...%%%#:........ . .. ..... ......... ....\n",
|
|
":+++++++++====+++++++++++++=.. ...-----------.....-+#*=:.....-------:.......:=*#+-.. ..--:.....--=.\n",
|
|
":++++++++======++++++++++++=.. ...#%%%%%%%%%#..-#%%###%%#=...#%####%%%=...+%%%###%%#...#%+.. ..#%%.\n",
|
|
".+++++++========+++++++++++- .. .#%%.. ..-%%+.. ..-%%+..#%*.. .*%%..*%%:. ..#%*..#%+... .#%%.\n",
|
|
".=++++++==========+++++++++: . .#%%.....#%#.... .*%#..#%*...-%%*..#%+. ... . ..##%#####%%%.\n",
|
|
"..++++++===========+++++++-. . ...#%%. . .#%#. . .*%#..#%%%%%%#-. .#%+. . ....#%*-----#%%.\n",
|
|
"...+++++===========++++++=. . . . .#%%... -%%+.....=%%+..#%*..+%%-. .*%%-.....#%*..%%+.. ..%%%.\n",
|
|
". ..-+++===========+++++.. . .. ..#%%. .:%%%###%%%=...#%*...+%%=...+%%####%%#...%%+.. ..%%%.\n",
|
|
" . ...-++==========+++:.... ... . .===. ... ..-+++=.. ..-=-....-==: ..:=+++-.. ..==-... .===.\n",
|
|
" ....-+=======+-...... .. . . ... . . .. ... . . .... . . . . ..... . ... ..... .\n",
|
|
" .... . ......:..... ... . .. . ... . . ... . . . ... . . . ... .. ..... . . \n",
|
|
"\n",
|
|
"Tiny🔥Torch\n",
|
|
"Build ML Systems from Scratch!\n",
|
|
"\n",
|
|
"Testing add_numbers():\n",
|
|
"2 + 3 = 5\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Test the functions in the notebook (will fail until implemented)\n",
|
|
"try:\n",
|
|
" print(\"Testing hello_tinytorch():\")\n",
|
|
" hello_tinytorch()\n",
|
|
" print()\n",
|
|
" print(\"Testing add_numbers():\")\n",
|
|
" print(f\"2 + 3 = {add_numbers(2, 3)}\")\n",
|
|
"except NotImplementedError as e:\n",
|
|
" print(f\"⚠️ {e}\")\n",
|
|
" print(\"Implement the functions above first!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "887b9723",
|
|
"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": 5,
|
|
"id": "29b647dc",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.093735Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.093599Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.096084Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.095799Z"
|
|
},
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#| export\n",
|
|
"class SystemInfo:\n",
|
|
" \"\"\"\n",
|
|
" Simple system information class.\n",
|
|
" \n",
|
|
" TODO: Implement this class to collect and display system information.\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" def __init__(self):\n",
|
|
" \"\"\"\n",
|
|
" Initialize system information collection.\n",
|
|
" \n",
|
|
" TODO: Collect Python version, platform, and machine information.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
" \n",
|
|
" def __str__(self):\n",
|
|
" \"\"\"\n",
|
|
" Return human-readable system information.\n",
|
|
" \n",
|
|
" TODO: Format system info as a readable string.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
" \n",
|
|
" def is_compatible(self):\n",
|
|
" \"\"\"\n",
|
|
" Check if system meets minimum requirements.\n",
|
|
" \n",
|
|
" TODO: Check if Python version is >= 3.8\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "d40a8e32",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.097467Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.097350Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.099769Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.099425Z"
|
|
},
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#| hide\n",
|
|
"#| 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": "markdown",
|
|
"id": "a182b8ad",
|
|
"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": 7,
|
|
"id": "bfd7d3c4",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.101366Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.101221Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.103476Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.103228Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Testing SystemInfo class:\n",
|
|
"System: Python 3.13 on Darwin (arm64)\n",
|
|
"Compatible: True\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Test the SystemInfo class (will fail until implemented)\n",
|
|
"try:\n",
|
|
" print(\"Testing SystemInfo class:\")\n",
|
|
" info = SystemInfo()\n",
|
|
" print(f\"System: {info}\")\n",
|
|
" print(f\"Compatible: {info.is_compatible()}\")\n",
|
|
"except NotImplementedError as e:\n",
|
|
" print(f\"⚠️ {e}\")\n",
|
|
" print(\"Implement the SystemInfo class above first!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "9a14de41",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\"",
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"source": [
|
|
"## Step 3: Developer Personalization\n",
|
|
"\n",
|
|
"Let's make TinyTorch yours! Create a developer profile that will identify you throughout your ML systems journey."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"id": "486717dd",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.104998Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.104881Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.107642Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.107356Z"
|
|
},
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#| export\n",
|
|
"class DeveloperProfile:\n",
|
|
" \"\"\"\n",
|
|
" Developer profile for personalizing TinyTorch experience.\n",
|
|
" \n",
|
|
" TODO: Implement this class to store and display developer information.\n",
|
|
" Default to course instructor but allow students to personalize.\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def _load_default_flame():\n",
|
|
" \"\"\"\n",
|
|
" Load the default TinyTorch flame ASCII art from file.\n",
|
|
" \n",
|
|
" TODO: Implement file loading for tinytorch_flame.txt with fallback.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
" \n",
|
|
" def __init__(self, name=\"Vijay Janapa Reddi\", affiliation=\"Harvard University\", \n",
|
|
" email=\"vj@eecs.harvard.edu\", github_username=\"profvjreddi\", ascii_art=None):\n",
|
|
" \"\"\"\n",
|
|
" Initialize developer profile.\n",
|
|
" \n",
|
|
" TODO: Store developer information with sensible defaults.\n",
|
|
" Students should be able to customize this with their own info and ASCII art.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
" \n",
|
|
" def __str__(self):\n",
|
|
" \"\"\"\n",
|
|
" Return formatted developer information.\n",
|
|
" \n",
|
|
" TODO: Format developer info as a professional signature with optional ASCII art.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
" \n",
|
|
" def get_signature(self):\n",
|
|
" \"\"\"\n",
|
|
" Get a short signature for code headers.\n",
|
|
" \n",
|
|
" TODO: Return a concise signature like \"Built by Name (@github)\"\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")\n",
|
|
" \n",
|
|
" def get_ascii_art(self):\n",
|
|
" \"\"\"\n",
|
|
" Get ASCII art for the profile.\n",
|
|
" \n",
|
|
" TODO: Return custom ASCII art or default flame loaded from file.\n",
|
|
" \"\"\"\n",
|
|
" raise NotImplementedError(\"Student implementation required\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"id": "49a5cfed",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.109202Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.109073Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.113144Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.112824Z"
|
|
},
|
|
"lines_to_next_cell": 1
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"#| hide\n",
|
|
"#| export\n",
|
|
"class DeveloperProfile:\n",
|
|
" \"\"\"Developer profile for personalizing TinyTorch experience.\"\"\"\n",
|
|
" \n",
|
|
" @staticmethod\n",
|
|
" def _load_default_flame():\n",
|
|
" \"\"\"Load the default TinyTorch flame ASCII art from file.\"\"\"\n",
|
|
" try:\n",
|
|
" # Try to load from the same directory as this module\n",
|
|
" try:\n",
|
|
" # Try to get the directory of the current file\n",
|
|
" current_dir = os.path.dirname(__file__)\n",
|
|
" except NameError:\n",
|
|
" # If __file__ is not defined (e.g., in notebook), use current directory\n",
|
|
" current_dir = os.getcwd()\n",
|
|
" \n",
|
|
" flame_path = os.path.join(current_dir, 'tinytorch_flame.txt')\n",
|
|
" \n",
|
|
" with open(flame_path, 'r', encoding='utf-8') as f:\n",
|
|
" flame_art = f.read()\n",
|
|
" \n",
|
|
" # Add the Tiny🔥Torch text below the flame\n",
|
|
" return f\"\"\"{flame_art}\n",
|
|
" \n",
|
|
" Tiny🔥Torch\n",
|
|
" Build ML Systems from Scratch!\n",
|
|
" \"\"\"\n",
|
|
" except (FileNotFoundError, IOError):\n",
|
|
" # Fallback to simple flame if file not found\n",
|
|
" return \"\"\"\n",
|
|
" 🔥 TinyTorch Developer 🔥\n",
|
|
" . . . . . .\n",
|
|
" . . . . . .\n",
|
|
" . . . . . . .\n",
|
|
" . . . . . . . .\n",
|
|
" . . . . . . . . .\n",
|
|
" . . . . . . . . . .\n",
|
|
" . . . . . . . . . . .\n",
|
|
" . . . . . . . . . . . .\n",
|
|
" . . . . . . . . . . . . .\n",
|
|
". . . . . . . . . . . . . .\n",
|
|
" \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ \\\\ \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ \\\\ / / / / / /\n",
|
|
" \\\\ / / / / / /\n",
|
|
" \\\\/ / / / / /\n",
|
|
" \\\\/ / / / /\n",
|
|
" \\\\/ / / /\n",
|
|
" \\\\/ / /\n",
|
|
" \\\\/ /\n",
|
|
" \\\\/\n",
|
|
" \n",
|
|
" Tiny🔥Torch\n",
|
|
" Build ML Systems from Scratch!\n",
|
|
" \"\"\"\n",
|
|
" \n",
|
|
" def __init__(self, name=\"Vijay Janapa Reddi\", affiliation=\"Harvard University\", \n",
|
|
" email=\"vj@eecs.harvard.edu\", github_username=\"profvjreddi\", ascii_art=None):\n",
|
|
" self.name = name\n",
|
|
" self.affiliation = affiliation\n",
|
|
" self.email = email\n",
|
|
" self.github_username = github_username\n",
|
|
" self.ascii_art = ascii_art or self._load_default_flame()\n",
|
|
" \n",
|
|
" def __str__(self):\n",
|
|
" return f\"👨💻 {self.name} | {self.affiliation} | @{self.github_username}\"\n",
|
|
" \n",
|
|
" def get_signature(self):\n",
|
|
" \"\"\"Get a short signature for code headers.\"\"\"\n",
|
|
" return f\"Built by {self.name} (@{self.github_username})\"\n",
|
|
" \n",
|
|
" def get_ascii_art(self):\n",
|
|
" \"\"\"Get ASCII art for the profile.\"\"\"\n",
|
|
" return self.ascii_art\n",
|
|
" \n",
|
|
" def get_full_profile(self):\n",
|
|
" \"\"\"Get complete profile with ASCII art.\"\"\"\n",
|
|
" return f\"\"\"{self.ascii_art}\n",
|
|
" \n",
|
|
"👨💻 Developer: {self.name}\n",
|
|
"🏛️ Affiliation: {self.affiliation}\n",
|
|
"📧 Email: {self.email}\n",
|
|
"🐙 GitHub: @{self.github_username}\n",
|
|
"🔥 Ready to build ML systems from scratch!\n",
|
|
"\"\"\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b848981d",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"### 🧪 Test Your Developer Profile\n",
|
|
"\n",
|
|
"Customize your developer profile! Replace the default information with your own:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"id": "5d80e79c",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2025-07-10T23:28:59.114628Z",
|
|
"iopub.status.busy": "2025-07-10T23:28:59.114540Z",
|
|
"iopub.status.idle": "2025-07-10T23:28:59.118055Z",
|
|
"shell.execute_reply": "2025-07-10T23:28:59.117792Z"
|
|
}
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Testing DeveloperProfile (with defaults):\n",
|
|
"Profile: 👨💻 Vijay Janapa Reddi | Harvard University | @profvjreddi\n",
|
|
"Signature: Built by Vijay Janapa Reddi (@profvjreddi)\n",
|
|
"\n",
|
|
"🎨 ASCII Art Preview:\n",
|
|
". . ... ....... .... ... . . .. .... . .. . . . . . .... \n",
|
|
". . .. .++. .. . . . .. ... . . . .. ... .. \n",
|
|
" . . . .=++=.. . . . .. . . .. . ... .. . . \n",
|
|
". .. ... .++++=. . . . . .. . .. .\n",
|
|
". . . . ....-+++++.... ... .. . .... .. . . . . . . . . . . . . \n",
|
|
" . .. ...-++++++-...... .. . ..... ..-:.. .. . .... .. . . .. . .. . . . \n",
|
|
" .. .. ..++++++++-.. . . ..##... -%#. . . . . . \n",
|
|
". .. .:+++++++++.... ... . ...:%%:............:-:. ..... ...... . . ....... .. . . \n",
|
|
" ..+++++++++++. ... . .. .=#%%##+.-##..#%####%%=.=%%. .*%+.. . . . ... \n",
|
|
" . ..++++++++++++...-++..... . .%%... -##..##=...=%#..*%*..=%#.. . .. ... . . . . .. . ...\n",
|
|
" ..-+++++++++++++..=++++... .....%#.. -##..#%-.. -##. .%%=.%%.. . . . . . ... .\n",
|
|
". .=++++++++++++++-+++++++.... . ...%%:...-##..#%-. .-%#. ..#%#%=.. . .. ... . . . .\n",
|
|
"..=+++++++++++++++++++++++-. . ..=%%%+.-%#..##-. .-%#....-%%*.. . .. . .. .. .. \n",
|
|
".:+++++++++++=+++++++++++++. . ................ .......-%%... . .. . . .. . \n",
|
|
".++++++++++===+++++++++++++: . .................... . ...%%%#:........ . .. ..... ......... ....\n",
|
|
":+++++++++====+++++++++++++=.. ...-----------.....-+#*=:.....-------:.......:=*#+-.. ..--:.....--=.\n",
|
|
":++++++++======++++++++++++=.. ...#%%%%%%%%%#..-#%%###%%#=...#%####%%%=...+%%%###%%#...#%+.. ..#%%.\n",
|
|
".+++++++========+++++++++++- .. .#%%.. ..-%%+.. ..-%%+..#%*.. .*%%..*%%:. ..#%*..#%+... .#%%.\n",
|
|
".=++++++==========+++++++++: . .#%%.....#%#.... .*%#..#%*...-%%*..#%+. ... . ..##%#####%%%.\n",
|
|
"..++++++===========+++++++-. . ...#%%. . .#%#. . .*%#..#%%%%%%#-. .#%+. . ....#%*-----#%%.\n",
|
|
"...+++++===========++++++=. . . . .#%%... -%%+.....=%%+..#%*..+%%-. .*%%-.....#%*..%%+.. ..%%%.\n",
|
|
". ..-+++===========+++++.. . .. ..#%%. .:%%%###%%%=...#%*...+%%=...+%%####%%#...%%+.. ..%%%.\n",
|
|
" . ...-++==========+++:.... ... . .===. ... ..-+++=.. ..-=-....-==: ..:=+++-.. ..==-... .===.\n",
|
|
" ....-+=======+-...... .. . . ... . . .. ... . . .... . . . . ..... . ... ..... .\n",
|
|
" .... . ......:..... ... . .. . ... . . ... . . . ... . . . ... .. ..... . . \n",
|
|
"\n",
|
|
"\n",
|
|
" Tiny🔥Torch\n",
|
|
" Build ML Systems from Scratch!\n",
|
|
" \n",
|
|
"\n",
|
|
"🔥 Full Profile Display:\n",
|
|
". . ... ....... .... ... . . .. .... . .. . . . . . .... \n",
|
|
". . .. .++. .. . . . .. ... . . . .. ... .. \n",
|
|
" . . . .=++=.. . . . .. . . .. . ... .. . . \n",
|
|
". .. ... .++++=. . . . . .. . .. .\n",
|
|
". . . . ....-+++++.... ... .. . .... .. . . . . . . . . . . . . \n",
|
|
" . .. ...-++++++-...... .. . ..... ..-:.. .. . .... .. . . .. . .. . . . \n",
|
|
" .. .. ..++++++++-.. . . ..##... -%#. . . . . . \n",
|
|
". .. .:+++++++++.... ... . ...:%%:............:-:. ..... ...... . . ....... .. . . \n",
|
|
" ..+++++++++++. ... . .. .=#%%##+.-##..#%####%%=.=%%. .*%+.. . . . ... \n",
|
|
" . ..++++++++++++...-++..... . .%%... -##..##=...=%#..*%*..=%#.. . .. ... . . . . .. . ...\n",
|
|
" ..-+++++++++++++..=++++... .....%#.. -##..#%-.. -##. .%%=.%%.. . . . . . ... .\n",
|
|
". .=++++++++++++++-+++++++.... . ...%%:...-##..#%-. .-%#. ..#%#%=.. . .. ... . . . .\n",
|
|
"..=+++++++++++++++++++++++-. . ..=%%%+.-%#..##-. .-%#....-%%*.. . .. . .. .. .. \n",
|
|
".:+++++++++++=+++++++++++++. . ................ .......-%%... . .. . . .. . \n",
|
|
".++++++++++===+++++++++++++: . .................... . ...%%%#:........ . .. ..... ......... ....\n",
|
|
":+++++++++====+++++++++++++=.. ...-----------.....-+#*=:.....-------:.......:=*#+-.. ..--:.....--=.\n",
|
|
":++++++++======++++++++++++=.. ...#%%%%%%%%%#..-#%%###%%#=...#%####%%%=...+%%%###%%#...#%+.. ..#%%.\n",
|
|
".+++++++========+++++++++++- .. .#%%.. ..-%%+.. ..-%%+..#%*.. .*%%..*%%:. ..#%*..#%+... .#%%.\n",
|
|
".=++++++==========+++++++++: . .#%%.....#%#.... .*%#..#%*...-%%*..#%+. ... . ..##%#####%%%.\n",
|
|
"..++++++===========+++++++-. . ...#%%. . .#%#. . .*%#..#%%%%%%#-. .#%+. . ....#%*-----#%%.\n",
|
|
"...+++++===========++++++=. . . . .#%%... -%%+.....=%%+..#%*..+%%-. .*%%-.....#%*..%%+.. ..%%%.\n",
|
|
". ..-+++===========+++++.. . .. ..#%%. .:%%%###%%%=...#%*...+%%=...+%%####%%#...%%+.. ..%%%.\n",
|
|
" . ...-++==========+++:.... ... . .===. ... ..-+++=.. ..-=-....-==: ..:=+++-.. ..==-... .===.\n",
|
|
" ....-+=======+-...... .. . . ... . . .. ... . . .... . . . . ..... . ... ..... .\n",
|
|
" .... . ......:..... ... . .. . ... . . ... . . . ... . . . ... .. ..... . . \n",
|
|
"\n",
|
|
"\n",
|
|
" Tiny🔥Torch\n",
|
|
" Build ML Systems from Scratch!\n",
|
|
" \n",
|
|
"\n",
|
|
"👨💻 Developer: Vijay Janapa Reddi\n",
|
|
"🏛️ Affiliation: Harvard University\n",
|
|
"📧 Email: vj@eecs.harvard.edu\n",
|
|
"🐙 GitHub: @profvjreddi\n",
|
|
"🔥 Ready to build ML systems from scratch!\n",
|
|
"\n",
|
|
"\n",
|
|
"🎯 YOUR TURN: Create your own profile!\n",
|
|
"Uncomment and modify the lines below:\n",
|
|
"# my_profile = DeveloperProfile(\n",
|
|
"# name='Your Name',\n",
|
|
"# affiliation='Your University/Company',\n",
|
|
"# email='your.email@example.com',\n",
|
|
"# github_username='yourgithub',\n",
|
|
"# ascii_art='''\n",
|
|
"# Your Custom ASCII Art Here!\n",
|
|
"# Maybe your initials, a logo, or something fun!\n",
|
|
"# '''\n",
|
|
"# )\n",
|
|
"# print(f'My Profile: {my_profile}')\n",
|
|
"# print(f'My Signature: {my_profile.get_signature()}')\n",
|
|
"# print(my_profile.get_full_profile())\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# Test the DeveloperProfile class\n",
|
|
"try:\n",
|
|
" print(\"Testing DeveloperProfile (with defaults):\")\n",
|
|
" # Default profile (instructor)\n",
|
|
" default_profile = DeveloperProfile()\n",
|
|
" print(f\"Profile: {default_profile}\")\n",
|
|
" print(f\"Signature: {default_profile.get_signature()}\")\n",
|
|
" print()\n",
|
|
" \n",
|
|
" print(\"🎨 ASCII Art Preview:\")\n",
|
|
" print(default_profile.get_ascii_art())\n",
|
|
" print()\n",
|
|
" \n",
|
|
" print(\"🔥 Full Profile Display:\")\n",
|
|
" print(default_profile.get_full_profile())\n",
|
|
" print()\n",
|
|
" \n",
|
|
" # TODO: Students should customize this with their own information!\n",
|
|
" print(\"🎯 YOUR TURN: Create your own profile!\")\n",
|
|
" print(\"Uncomment and modify the lines below:\")\n",
|
|
" print(\"# my_profile = DeveloperProfile(\")\n",
|
|
" print(\"# name='Your Name',\")\n",
|
|
" print(\"# affiliation='Your University/Company',\")\n",
|
|
" print(\"# email='your.email@example.com',\")\n",
|
|
" print(\"# github_username='yourgithub',\")\n",
|
|
" print(\"# ascii_art='''\")\n",
|
|
" print(\"# Your Custom ASCII Art Here!\")\n",
|
|
" print(\"# Maybe your initials, a logo, or something fun!\")\n",
|
|
" print(\"# '''\")\n",
|
|
" print(\"# )\")\n",
|
|
" print(\"# print(f'My Profile: {my_profile}')\")\n",
|
|
" print(\"# print(f'My Signature: {my_profile.get_signature()}')\")\n",
|
|
" print(\"# print(my_profile.get_full_profile())\")\n",
|
|
" \n",
|
|
"except NotImplementedError as e:\n",
|
|
" print(f\"⚠️ {e}\")\n",
|
|
" print(\"Implement the DeveloperProfile class above first!\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4f117574",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"### 🎨 Personalization Challenge\n",
|
|
"\n",
|
|
"**For Students**: Make TinyTorch truly yours by:\n",
|
|
"\n",
|
|
"1. **Update your profile** in the cell above with your real information\n",
|
|
"2. **Create custom ASCII art** - your initials, a simple logo, or something that represents you\n",
|
|
"3. **Customize the flame file** - edit `tinytorch_flame.txt` to create your own default art\n",
|
|
"4. **Add your signature** to code you write throughout the course\n",
|
|
"5. **Show off your full profile** with the `get_full_profile()` method\n",
|
|
"\n",
|
|
"This isn't just about customization - it's about taking ownership of your learning journey in ML systems!\n",
|
|
"\n",
|
|
"**ASCII Art Customization Options:**\n",
|
|
"\n",
|
|
"**Option 1: Custom ASCII Art Parameter**\n",
|
|
"```python\n",
|
|
"my_profile = DeveloperProfile(\n",
|
|
" name=\"Your Name\",\n",
|
|
" ascii_art='''\n",
|
|
" Your Custom ASCII Art Here!\n",
|
|
" Maybe your initials, a logo, or something fun!\n",
|
|
" '''\n",
|
|
")\n",
|
|
"```\n",
|
|
"\n",
|
|
"**Option 2: Edit the Default Flame File**\n",
|
|
"- Edit `tinytorch_flame.txt` in this directory\n",
|
|
"- Replace with your own ASCII art design\n",
|
|
"- All students using defaults will see your custom art!\n",
|
|
"\n",
|
|
"**ASCII Art Ideas:**\n",
|
|
"- Your initials in block letters\n",
|
|
"- A simple logo or symbol that represents you\n",
|
|
"- Your university mascot in ASCII\n",
|
|
"- A coding-themed design\n",
|
|
"- Something that motivates you!\n",
|
|
"\n",
|
|
"**Pro Tip**: The `tinytorch_flame.txt` file contains the beautiful default flame art. You can:\n",
|
|
"- Edit it directly for a personalized default\n",
|
|
"- Create your own `.txt` file and modify the code to load it\n",
|
|
"- Use online ASCII art generators for inspiration"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "3e34c7fe",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"## Step 4: 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!\n",
|
|
"\n",
|
|
"**Note**: The export process will use the instructor solutions (from `#|hide` cells) so the package will have working implementations even if you haven't completed the exercises yet."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "641ad5d7",
|
|
"metadata": {
|
|
"cell_marker": "\"\"\""
|
|
},
|
|
"source": [
|
|
"## Step 5: 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 6: 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": "7a09b00d",
|
|
"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"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.13.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|