mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-06-04 06:56:26 -05:00
Introduces a standardized module structure with README, notebooks, tutorials, tests, and solutions. Refactors the project to emphasize a modular learning path, enhancing clarity and consistency across the TinyTorch course. Changes the virtual environment path to ".venv".
346 lines
10 KiB
Plaintext
346 lines
10 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 🔥 Setup Module Development Notebook\n",
|
|
"\n",
|
|
"Welcome to your first TinyTorch implementation! This notebook will guide you through implementing the `hello_tinytorch()` function.\n",
|
|
"\n",
|
|
"## 🎯 Learning Objectives\n",
|
|
"\n",
|
|
"By the end of this notebook, you will:\n",
|
|
"- ✅ Understand the TinyTorch development workflow\n",
|
|
"- ✅ Implement your first function in the system\n",
|
|
"- ✅ Test your implementation\n",
|
|
"- ✅ Be ready for the next module\n",
|
|
"\n",
|
|
"## 📋 What You'll Implement\n",
|
|
"\n",
|
|
"You'll add a simple greeting function to `tinytorch/core/utils.py`:\n",
|
|
"\n",
|
|
"```python\n",
|
|
"def hello_tinytorch() -> str:\n",
|
|
" \"\"\"\n",
|
|
" Return a greeting message for new TinyTorch users.\n",
|
|
" \n",
|
|
" Returns:\n",
|
|
" A welcoming message string\n",
|
|
" \"\"\"\n",
|
|
" return \"🔥 Welcome to TinyTorch! Ready to build ML systems from scratch! 🔥\"\n",
|
|
"```"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🚀 Step 1: Environment Check\n",
|
|
"\n",
|
|
"First, let's make sure your environment is working correctly."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Check Python version\n",
|
|
"import sys\n",
|
|
"print(f\"Python version: {sys.version}\")\n",
|
|
"print(f\"Python executable: {sys.executable}\")\n",
|
|
"\n",
|
|
"# Check if we're in a virtual environment\n",
|
|
"in_venv = (hasattr(sys, 'real_prefix') or \n",
|
|
" (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))\n",
|
|
"print(f\"Virtual environment: {'Active' if in_venv else 'Not detected'}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 📦 Step 2: Import Check\n",
|
|
"\n",
|
|
"Let's verify we can import from the TinyTorch system."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Add the project root to Python path\n",
|
|
"import os\n",
|
|
"import sys\n",
|
|
"project_root = os.path.join(os.getcwd(), '..', '..')\n",
|
|
"sys.path.insert(0, project_root)\n",
|
|
"\n",
|
|
"# Try to import from tinytorch\n",
|
|
"try:\n",
|
|
" from tinytorch.core import utils\n",
|
|
" print(\"✅ Successfully imported tinytorch.core.utils\")\n",
|
|
"except ImportError as e:\n",
|
|
" print(f\"❌ Failed to import: {e}\")\n",
|
|
" print(\"Make sure you're running this from the modules/setup/notebook/ directory\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🔍 Step 3: Examine Current Utils\n",
|
|
"\n",
|
|
"Let's look at what's currently in the utils module."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Check what's currently in utils\n",
|
|
"import inspect\n",
|
|
"from tinytorch.core import utils\n",
|
|
"\n",
|
|
"print(\"Current functions in utils:\")\n",
|
|
"for name, obj in inspect.getmembers(utils):\n",
|
|
" if inspect.isfunction(obj):\n",
|
|
" print(f\" - {name}()\")\n",
|
|
"\n",
|
|
"print(\"\\nLet's look at the current utils.py file:\")\n",
|
|
"with open(os.path.join(project_root, 'tinytorch', 'core', 'utils.py'), 'r') as f:\n",
|
|
" print(f.read())"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ✏️ Step 4: Implement Your Function\n",
|
|
"\n",
|
|
"Now it's time to implement the `hello_tinytorch()` function. You'll need to edit the `tinytorch/core/utils.py` file.\n",
|
|
"\n",
|
|
"**Your Task**: Add the `hello_tinytorch()` function to the utils module.\n",
|
|
"\n",
|
|
"**Requirements**:\n",
|
|
"- Function should return a string\n",
|
|
"- Should contain welcoming content\n",
|
|
"- Should include the 🔥 emoji (TinyTorch branding)\n",
|
|
"- Should have proper docstring and type hints"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# TODO: Edit tinytorch/core/utils.py and add your hello_tinytorch() function\n",
|
|
"# \n",
|
|
"# Here's what you need to add:\n",
|
|
"# \n",
|
|
"# def hello_tinytorch() -> str:\n",
|
|
"# \"\"\"\n",
|
|
"# Return a greeting message for new TinyTorch users.\n",
|
|
"# \n",
|
|
"# Returns:\n",
|
|
"# A welcoming message string\n",
|
|
"# \"\"\"\n",
|
|
"# return \"🔥 Welcome to TinyTorch! Ready to build ML systems from scratch! 🔥\"\n",
|
|
"#\n",
|
|
"# After you've added the function, run the cell below to test it.\n",
|
|
"\n",
|
|
"print(\"📝 Please edit tinytorch/core/utils.py and add your hello_tinytorch() function\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🧪 Step 5: Test Your Implementation\n",
|
|
"\n",
|
|
"Once you've added the function, let's test it!"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Reload the utils module to get your changes\n",
|
|
"import importlib\n",
|
|
"importlib.reload(utils)\n",
|
|
"\n",
|
|
"# Try to import your function\n",
|
|
"try:\n",
|
|
" from tinytorch.core.utils import hello_tinytorch\n",
|
|
" print(\"✅ hello_tinytorch() function found!\")\n",
|
|
" \n",
|
|
" # Test the function\n",
|
|
" result = hello_tinytorch()\n",
|
|
" print(f\"📤 Function returned: {result}\")\n",
|
|
" \n",
|
|
" # Check requirements\n",
|
|
" checks = []\n",
|
|
" checks.append(isinstance(result, str))\n",
|
|
" checks.append(len(result.strip()) > 0)\n",
|
|
" checks.append('🔥' in result)\n",
|
|
" checks.append(any(word in result.lower() for word in ['welcome', 'hello', 'tinytorch', 'ready']))\n",
|
|
" \n",
|
|
" print(\"\\n📋 Requirements Check:\")\n",
|
|
" print(f\" ✅ Returns string: {checks[0]}\")\n",
|
|
" print(f\" ✅ Non-empty: {checks[1]}\")\n",
|
|
" print(f\" ✅ Contains 🔥: {checks[2]}\")\n",
|
|
" print(f\" ✅ Welcoming content: {checks[3]}\")\n",
|
|
" \n",
|
|
" if all(checks):\n",
|
|
" print(\"\\n🎉 All tests passed! Your implementation is complete!\")\n",
|
|
" else:\n",
|
|
" print(\"\\n❌ Some tests failed. Please check your implementation.\")\n",
|
|
" \n",
|
|
"except ImportError as e:\n",
|
|
" print(f\"❌ Function not found: {e}\")\n",
|
|
" print(\"Make sure you've added the hello_tinytorch() function to tinytorch/core/utils.py\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🧪 Step 6: Run Full Test Suite\n",
|
|
"\n",
|
|
"Let's run the complete test suite to make sure everything works."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Run the pytest test suite\n",
|
|
"import subprocess\n",
|
|
"import sys\n",
|
|
"\n",
|
|
"test_file = os.path.join(project_root, 'modules', 'setup', 'test_setup.py')\n",
|
|
"print(f\"Running tests from: {test_file}\")\n",
|
|
"\n",
|
|
"try:\n",
|
|
" result = subprocess.run([sys.executable, '-m', 'pytest', test_file, '-v'], \n",
|
|
" capture_output=True, text=True, timeout=30)\n",
|
|
" \n",
|
|
" if result.returncode == 0:\n",
|
|
" print(\"✅ All tests passed!\")\n",
|
|
" print(\"\\nTest output:\")\n",
|
|
" print(result.stdout)\n",
|
|
" else:\n",
|
|
" print(\"❌ Some tests failed.\")\n",
|
|
" print(\"\\nTest output:\")\n",
|
|
" print(result.stdout)\n",
|
|
" if result.stderr:\n",
|
|
" print(\"\\nError output:\")\n",
|
|
" print(result.stderr)\n",
|
|
" \n",
|
|
"except Exception as e:\n",
|
|
" print(f\"❌ Error running tests: {e}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## ✅ Step 7: Manual Verification\n",
|
|
"\n",
|
|
"Let's run the manual verification script for detailed feedback."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Run the manual verification script\n",
|
|
"check_script = os.path.join(project_root, 'modules', 'setup', 'check_setup.py')\n",
|
|
"print(f\"Running verification script: {check_script}\")\n",
|
|
"\n",
|
|
"try:\n",
|
|
" result = subprocess.run([sys.executable, check_script], \n",
|
|
" capture_output=True, text=True, timeout=30)\n",
|
|
" \n",
|
|
" print(\"\\n\" + \"=\"*50)\n",
|
|
" print(\"VERIFICATION RESULTS\")\n",
|
|
" print(\"=\"*50)\n",
|
|
" print(result.stdout)\n",
|
|
" \n",
|
|
" if result.stderr:\n",
|
|
" print(\"\\nErrors:\")\n",
|
|
" print(result.stderr)\n",
|
|
" \n",
|
|
"except Exception as e:\n",
|
|
" print(f\"❌ Error running verification: {e}\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 🎉 Congratulations!\n",
|
|
"\n",
|
|
"If all tests passed, you've successfully completed the Setup module! You've:\n",
|
|
"\n",
|
|
"✅ **Set up your development environment**\n",
|
|
"✅ **Implemented your first TinyTorch function**\n",
|
|
"✅ **Learned the testing workflow**\n",
|
|
"✅ **Verified your implementation**\n",
|
|
"\n",
|
|
"## 🚀 Next Steps\n",
|
|
"\n",
|
|
"You're now ready to move to the next module:\n",
|
|
"\n",
|
|
"```bash\n",
|
|
"# Navigate to the tensor module\n",
|
|
"cd ../tensor/\n",
|
|
"\n",
|
|
"# Read the overview\n",
|
|
"cat README.md\n",
|
|
"\n",
|
|
"# Start the development notebook\n",
|
|
"tito jupyter --lab\n",
|
|
"```\n",
|
|
"\n",
|
|
"In the tensor module, you'll build the core Tensor class that will be the foundation for everything else in TinyTorch!\n",
|
|
"\n",
|
|
"**Good luck, and happy coding! 🔥**"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"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.8.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|