mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-04-29 06:22:32 -05:00
Restore comprehensive setup module with full educational content
- 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
This commit is contained in:
@@ -4,31 +4,67 @@ Welcome to TinyTorch! This is your first module in the Machine Learning Systems
|
||||
|
||||
## Overview
|
||||
|
||||
The setup module is a simple introduction to TinyTorch that displays beautiful ASCII art to get you started on your ML systems journey.
|
||||
The setup module teaches you the complete TinyTorch development workflow while introducing fundamental programming concepts. You'll learn to write code with NBDev directives, implement classes and functions, and understand the module-to-package export system.
|
||||
|
||||
## Learning Goals
|
||||
|
||||
- Understand the nbdev notebook-to-Python workflow
|
||||
- Write your first TinyTorch code with `#| export` directives
|
||||
- Implement system information collection and developer profiles
|
||||
- Run tests and use the CLI tools
|
||||
- Get comfortable with the development rhythm
|
||||
|
||||
## Files
|
||||
|
||||
- `setup_dev.py` - Main development file with the hello_tinytorch() function
|
||||
- `setup_dev.ipynb` - Jupyter notebook version (auto-generated)
|
||||
- `setup_dev.py` - Main development file (Jupytext format with full educational content)
|
||||
- `setup_dev.ipynb` - Jupyter notebook version (auto-generated and executed)
|
||||
- `tinytorch_flame.txt` - ASCII art file containing the TinyTorch flame design
|
||||
- `tests/test_setup.py` - pytest test suite for the module
|
||||
- `tests/test_setup.py` - Comprehensive pytest test suite
|
||||
- `README.md` - This file
|
||||
|
||||
## What You'll Implement
|
||||
|
||||
### 1. Basic Functions
|
||||
- `hello_tinytorch()` - Display ASCII art and welcome message
|
||||
- `add_numbers()` - Basic arithmetic (foundation of ML operations)
|
||||
|
||||
### 2. System Information Class
|
||||
- `SystemInfo` - Collect and display Python version, platform, and machine info
|
||||
- Compatibility checking for minimum requirements
|
||||
|
||||
### 3. Developer Profile Class
|
||||
- `DeveloperProfile` - Personalized developer information and signatures
|
||||
- ASCII art customization and file loading
|
||||
- Professional code attribution system
|
||||
|
||||
## Usage
|
||||
|
||||
### Python Script
|
||||
```python
|
||||
from setup_dev import hello_tinytorch
|
||||
from setup_dev import hello_tinytorch, add_numbers, SystemInfo, DeveloperProfile
|
||||
|
||||
# Display welcome message
|
||||
hello_tinytorch()
|
||||
|
||||
# Basic arithmetic
|
||||
result = add_numbers(2, 3)
|
||||
|
||||
# System information
|
||||
info = SystemInfo()
|
||||
print(f"System: {info}")
|
||||
print(f"Compatible: {info.is_compatible()}")
|
||||
|
||||
# Developer profile
|
||||
profile = DeveloperProfile()
|
||||
print(profile.get_full_profile())
|
||||
```
|
||||
|
||||
### Jupyter Notebook
|
||||
Open `setup_dev.ipynb` and run the cells to see the ASCII art displayed.
|
||||
Open `setup_dev.ipynb` and work through the educational content step by step.
|
||||
|
||||
## Testing
|
||||
|
||||
Run the tests using pytest:
|
||||
Run the comprehensive test suite using pytest:
|
||||
|
||||
```bash
|
||||
# Using the TinyTorch CLI (recommended)
|
||||
@@ -40,29 +76,66 @@ python -m pytest modules/setup/tests/test_setup.py -v
|
||||
|
||||
### Test Coverage
|
||||
|
||||
The test suite includes:
|
||||
- ✅ Function execution without errors
|
||||
- ✅ Correct output content (ASCII art and branding)
|
||||
- ✅ ASCII art file existence and content validation
|
||||
- ✅ Graceful handling of missing files
|
||||
- ✅ Error recovery and fallback behavior
|
||||
The test suite includes **20 comprehensive tests** covering:
|
||||
- ✅ **Function execution** - All functions run without errors
|
||||
- ✅ **Output validation** - Correct content and formatting
|
||||
- ✅ **Arithmetic operations** - Basic, negative, and floating-point math
|
||||
- ✅ **System information** - Platform detection and compatibility
|
||||
- ✅ **Developer profiles** - Default and custom configurations
|
||||
- ✅ **ASCII art handling** - File loading and fallback behavior
|
||||
- ✅ **Error recovery** - Graceful handling of missing files
|
||||
- ✅ **Integration testing** - All components work together
|
||||
|
||||
## ASCII Art Customization
|
||||
## Development Workflow
|
||||
|
||||
This module teaches the core TinyTorch development cycle:
|
||||
|
||||
1. **Write code** in the notebook using `#| export` directives
|
||||
2. **Export code** with `python bin/tito.py sync --module setup`
|
||||
3. **Run tests** with `python bin/tito.py test --module setup`
|
||||
4. **Check progress** with `python bin/tito.py info`
|
||||
|
||||
## Key Concepts
|
||||
|
||||
- **NBDev workflow** - Write in notebooks, export to Python packages
|
||||
- **Export directives** - Use `#| export` to mark code for export
|
||||
- **Module → Package mapping** - This module exports to `tinytorch/core/utils.py`
|
||||
- **Teaching vs. Building** - Learn by modules, build by function
|
||||
- **Student implementation** - TODO sections with instructor solutions hidden
|
||||
|
||||
## Personalization Features
|
||||
|
||||
### ASCII Art Customization
|
||||
The ASCII art is loaded from `tinytorch_flame.txt`. You can customize it by:
|
||||
|
||||
1. **Edit the file directly**: Modify `tinytorch_flame.txt` with your own ASCII art
|
||||
2. **Create your own design**: Replace the flame with your initials, logo, or any design you like
|
||||
1. **Edit the file directly** - Modify `tinytorch_flame.txt` with your own ASCII art
|
||||
2. **Custom parameter** - Pass your own ASCII art to `DeveloperProfile`
|
||||
3. **Create your own design** - Your initials, logo, or motivational art
|
||||
|
||||
### Developer Profile Customization
|
||||
```python
|
||||
my_profile = DeveloperProfile(
|
||||
name="Your Name",
|
||||
affiliation="Your University",
|
||||
email="your.email@example.com",
|
||||
github_username="yourgithub",
|
||||
ascii_art="Your custom ASCII art here!"
|
||||
)
|
||||
```
|
||||
|
||||
## What You'll Learn
|
||||
|
||||
This simple module introduces:
|
||||
- Basic Python file structure
|
||||
- File I/O operations
|
||||
- Error handling (fallback when file not found)
|
||||
- pytest testing framework and best practices
|
||||
- The TinyTorch development workflow
|
||||
This comprehensive module introduces:
|
||||
- **NBDev educational patterns** - `#| export`, `#| hide` directives
|
||||
- **File I/O operations** - Loading ASCII art with error handling
|
||||
- **Object-oriented programming** - Classes, methods, and properties
|
||||
- **System programming** - Platform detection and compatibility
|
||||
- **Testing with pytest** - Professional test structure and assertions
|
||||
- **Code organization** - Module structure and package exports
|
||||
- **The TinyTorch development workflow** - Complete cycle from code to tests
|
||||
|
||||
## Next Steps
|
||||
|
||||
Once you've explored this module, you're ready to move on to the tensor module where you'll build the core data structures for TinyTorch!
|
||||
Once you've completed this module and all tests pass, you're ready to move on to the **tensor module** where you'll build the core data structures that power TinyTorch neural networks!
|
||||
|
||||
The skills you learn here - the development workflow, testing patterns, and code organization - will be used throughout every module in TinyTorch.
|
||||
@@ -2,36 +2,149 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8de2eafa",
|
||||
"metadata": {},
|
||||
"id": "695331d6",
|
||||
"metadata": {
|
||||
"cell_marker": "\"\"\""
|
||||
},
|
||||
"source": [
|
||||
"# TinyTorch Setup Module\n",
|
||||
"# Module 0: Setup - Tiny🔥Torch Development Workflow\n",
|
||||
"\n",
|
||||
"Welcome to TinyTorch! This is your first module in the Machine Learning Systems course.\n",
|
||||
"Welcome to TinyTorch! This module teaches you the development workflow you'll use throughout the course.\n",
|
||||
"\n",
|
||||
"This module simply displays our beautiful ASCII art to get you started."
|
||||
"## 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": "4d47a76e",
|
||||
"id": "77e98f62",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-07-10T23:21:19.056010Z",
|
||||
"iopub.status.busy": "2025-07-10T23:21:19.055652Z",
|
||||
"iopub.status.idle": "2025-07-10T23:21:19.073438Z",
|
||||
"shell.execute_reply": "2025-07-10T23:21:19.072589Z"
|
||||
"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": [
|
||||
"import os\n",
|
||||
"from pathlib import Path\n",
|
||||
"\n",
|
||||
"#| export\n",
|
||||
"def hello_tinytorch():\n",
|
||||
" \"\"\"Display the TinyTorch ASCII art\"\"\"\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",
|
||||
@@ -61,29 +174,35 @@
|
||||
" print(\"Build ML Systems from Scratch!\")\n",
|
||||
" except:\n",
|
||||
" print(\"🔥 TinyTorch 🔥\")\n",
|
||||
" print(\"Build ML Systems from Scratch!\")"
|
||||
" 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": "885e6df3",
|
||||
"metadata": {},
|
||||
"id": "b28103af",
|
||||
"metadata": {
|
||||
"cell_marker": "\"\"\""
|
||||
},
|
||||
"source": [
|
||||
"## Test the Setup\n",
|
||||
"### 🧪 Test Your Implementation\n",
|
||||
"\n",
|
||||
"Let's run our hello function to see the ASCII art:"
|
||||
"Once you implement the functions above, run this cell to test them:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "bfe5bac0",
|
||||
"execution_count": 4,
|
||||
"id": "a1beca72",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-07-10T23:21:19.077086Z",
|
||||
"iopub.status.busy": "2025-07-10T23:21:19.076813Z",
|
||||
"iopub.status.idle": "2025-07-10T23:21:19.080935Z",
|
||||
"shell.execute_reply": "2025-07-10T23:21:19.080437Z"
|
||||
"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": [
|
||||
@@ -91,6 +210,7 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Testing hello_tinytorch():\n",
|
||||
". . ... ....... .... ... . . .. .... . .. . . . . . .... \n",
|
||||
". . .. .++. .. . . . .. ... . . . .. ... .. \n",
|
||||
" . . . .=++=.. . . . .. . . .. . ... .. . . \n",
|
||||
@@ -118,21 +238,659 @@
|
||||
" .... . ......:..... ... . .. . ... . . ... . . . ... . . . ... .. ..... . . \n",
|
||||
"\n",
|
||||
"Tiny🔥Torch\n",
|
||||
"Build ML Systems from Scratch!\n"
|
||||
"Build ML Systems from Scratch!\n",
|
||||
"\n",
|
||||
"Testing add_numbers():\n",
|
||||
"2 + 3 = 5\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"if __name__ == \"__main__\":\n",
|
||||
" hello_tinytorch()"
|
||||
"# 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": {
|
||||
"cell_metadata_filter": "-all",
|
||||
"main_language": "python",
|
||||
"notebook_metadata_filter": "-all"
|
||||
"main_language": "python"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
@@ -144,7 +902,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.19"
|
||||
"version": "3.13.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
@@ -1,16 +1,93 @@
|
||||
# ---
|
||||
# jupyter:
|
||||
# jupytext:
|
||||
# text_representation:
|
||||
# extension: .py
|
||||
# format_name: percent
|
||||
# format_version: '1.3'
|
||||
# jupytext_version: 1.17.1
|
||||
# ---
|
||||
|
||||
# %% [markdown]
|
||||
# # TinyTorch Setup Module
|
||||
#
|
||||
# Welcome to TinyTorch! This is your first module in the Machine Learning Systems course.
|
||||
#
|
||||
# This module simply displays our beautiful ASCII art to get you started.
|
||||
"""
|
||||
# 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
|
||||
|
||||
1. **Write code** in this notebook using `#| export`
|
||||
2. **Export code** with `python bin/tito.py sync --module setup`
|
||||
3. **Run tests** with `python bin/tito.py test --module setup`
|
||||
4. **Check progress** with `python bin/tito.py info`
|
||||
|
||||
Let's get started!
|
||||
"""
|
||||
|
||||
# %%
|
||||
#| default_exp core.utils
|
||||
|
||||
# Setup imports and environment
|
||||
import sys
|
||||
import platform
|
||||
from datetime import datetime
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
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')}")
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## 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:
|
||||
"""
|
||||
|
||||
# %%
|
||||
#| export
|
||||
def hello_tinytorch():
|
||||
"""Display the TinyTorch ASCII art"""
|
||||
"""
|
||||
A simple hello world function for TinyTorch.
|
||||
|
||||
TODO: Implement this function to display TinyTorch ASCII art and welcome message.
|
||||
Load the flame art from tinytorch_flame.txt file with graceful fallback.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def add_numbers(a, b):
|
||||
"""
|
||||
Add two numbers together.
|
||||
|
||||
TODO: Implement addition of two numbers.
|
||||
This is the foundation of all mathematical operations in ML.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
# %%
|
||||
#| hide
|
||||
#| export
|
||||
def hello_tinytorch():
|
||||
"""Display the TinyTorch ASCII art and welcome message."""
|
||||
try:
|
||||
# Get the directory containing this file
|
||||
current_dir = Path(__file__).parent
|
||||
@@ -42,11 +119,417 @@ def hello_tinytorch():
|
||||
print("🔥 TinyTorch 🔥")
|
||||
print("Build ML Systems from Scratch!")
|
||||
|
||||
def add_numbers(a, b):
|
||||
"""Add two numbers together."""
|
||||
return a + b
|
||||
|
||||
# %% [markdown]
|
||||
# ## Test the Setup
|
||||
#
|
||||
# Let's run our hello function to see the ASCII art:
|
||||
"""
|
||||
### 🧪 Test Your Implementation
|
||||
|
||||
Once you implement the functions above, run this cell to test them:
|
||||
"""
|
||||
|
||||
# %%
|
||||
if __name__ == "__main__":
|
||||
# Test the functions in the notebook (will fail until implemented)
|
||||
try:
|
||||
print("Testing hello_tinytorch():")
|
||||
hello_tinytorch()
|
||||
print()
|
||||
print("Testing add_numbers():")
|
||||
print(f"2 + 3 = {add_numbers(2, 3)}")
|
||||
except NotImplementedError as e:
|
||||
print(f"⚠️ {e}")
|
||||
print("Implement the functions above first!")
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## 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.
|
||||
"""
|
||||
|
||||
# %%
|
||||
#| export
|
||||
class SystemInfo:
|
||||
"""
|
||||
Simple system information class.
|
||||
|
||||
TODO: Implement this class to collect and display system information.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initialize system information collection.
|
||||
|
||||
TODO: Collect Python version, platform, and machine information.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Return human-readable system information.
|
||||
|
||||
TODO: Format system info as a readable string.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def is_compatible(self):
|
||||
"""
|
||||
Check if system meets minimum requirements.
|
||||
|
||||
TODO: Check if Python version is >= 3.8
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
# %%
|
||||
#| hide
|
||||
#| export
|
||||
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)
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
### 🧪 Test Your SystemInfo Class
|
||||
|
||||
Once you implement the SystemInfo class above, run this cell to test it:
|
||||
"""
|
||||
|
||||
# %%
|
||||
# Test the SystemInfo class (will fail until implemented)
|
||||
try:
|
||||
print("Testing SystemInfo class:")
|
||||
info = SystemInfo()
|
||||
print(f"System: {info}")
|
||||
print(f"Compatible: {info.is_compatible()}")
|
||||
except NotImplementedError as e:
|
||||
print(f"⚠️ {e}")
|
||||
print("Implement the SystemInfo class above first!")
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## Step 3: Developer Personalization
|
||||
|
||||
Let's make TinyTorch yours! Create a developer profile that will identify you throughout your ML systems journey.
|
||||
"""
|
||||
|
||||
# %%
|
||||
#| export
|
||||
class DeveloperProfile:
|
||||
"""
|
||||
Developer profile for personalizing TinyTorch experience.
|
||||
|
||||
TODO: Implement this class to store and display developer information.
|
||||
Default to course instructor but allow students to personalize.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def _load_default_flame():
|
||||
"""
|
||||
Load the default TinyTorch flame ASCII art from file.
|
||||
|
||||
TODO: Implement file loading for tinytorch_flame.txt with fallback.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def __init__(self, name="Vijay Janapa Reddi", affiliation="Harvard University",
|
||||
email="vj@eecs.harvard.edu", github_username="profvjreddi", ascii_art=None):
|
||||
"""
|
||||
Initialize developer profile.
|
||||
|
||||
TODO: Store developer information with sensible defaults.
|
||||
Students should be able to customize this with their own info and ASCII art.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
Return formatted developer information.
|
||||
|
||||
TODO: Format developer info as a professional signature with optional ASCII art.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def get_signature(self):
|
||||
"""
|
||||
Get a short signature for code headers.
|
||||
|
||||
TODO: Return a concise signature like "Built by Name (@github)"
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
def get_ascii_art(self):
|
||||
"""
|
||||
Get ASCII art for the profile.
|
||||
|
||||
TODO: Return custom ASCII art or default flame loaded from file.
|
||||
"""
|
||||
raise NotImplementedError("Student implementation required")
|
||||
|
||||
# %%
|
||||
#| hide
|
||||
#| export
|
||||
class DeveloperProfile:
|
||||
"""Developer profile for personalizing TinyTorch experience."""
|
||||
|
||||
@staticmethod
|
||||
def _load_default_flame():
|
||||
"""Load the default TinyTorch flame ASCII art from file."""
|
||||
try:
|
||||
# Try to load from the same directory as this module
|
||||
try:
|
||||
# Try to get the directory of the current file
|
||||
current_dir = os.path.dirname(__file__)
|
||||
except NameError:
|
||||
# If __file__ is not defined (e.g., in notebook), use current directory
|
||||
current_dir = os.getcwd()
|
||||
|
||||
flame_path = os.path.join(current_dir, 'tinytorch_flame.txt')
|
||||
|
||||
with open(flame_path, 'r', encoding='utf-8') as f:
|
||||
flame_art = f.read()
|
||||
|
||||
# Add the Tiny🔥Torch text below the flame
|
||||
return f"""{flame_art}
|
||||
|
||||
Tiny🔥Torch
|
||||
Build ML Systems from Scratch!
|
||||
"""
|
||||
except (FileNotFoundError, IOError):
|
||||
# Fallback to simple flame if file not found
|
||||
return """
|
||||
🔥 TinyTorch Developer 🔥
|
||||
. . . . . .
|
||||
. . . . . .
|
||||
. . . . . . .
|
||||
. . . . . . . .
|
||||
. . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . . .
|
||||
. . . . . . . . . . . .
|
||||
. . . . . . . . . . . . .
|
||||
. . . . . . . . . . . . . .
|
||||
\\ \\ \\ \\ \\ \\ \\ \\ \\ / / / / / /
|
||||
\\ \\ \\ \\ \\ \\ \\ \\ / / / / / /
|
||||
\\ \\ \\ \\ \\ \\ \\ / / / / / /
|
||||
\\ \\ \\ \\ \\ \\ / / / / / /
|
||||
\\ \\ \\ \\ \\ / / / / / /
|
||||
\\ \\ \\ \\ / / / / / /
|
||||
\\ \\ \\ / / / / / /
|
||||
\\ \\ / / / / / /
|
||||
\\ / / / / / /
|
||||
\\/ / / / / /
|
||||
\\/ / / / /
|
||||
\\/ / / /
|
||||
\\/ / /
|
||||
\\/ /
|
||||
\\/
|
||||
|
||||
Tiny🔥Torch
|
||||
Build ML Systems from Scratch!
|
||||
"""
|
||||
|
||||
def __init__(self, name="Vijay Janapa Reddi", affiliation="Harvard University",
|
||||
email="vj@eecs.harvard.edu", github_username="profvjreddi", ascii_art=None):
|
||||
self.name = name
|
||||
self.affiliation = affiliation
|
||||
self.email = email
|
||||
self.github_username = github_username
|
||||
self.ascii_art = ascii_art or self._load_default_flame()
|
||||
|
||||
def __str__(self):
|
||||
return f"👨💻 {self.name} | {self.affiliation} | @{self.github_username}"
|
||||
|
||||
def get_signature(self):
|
||||
"""Get a short signature for code headers."""
|
||||
return f"Built by {self.name} (@{self.github_username})"
|
||||
|
||||
def get_ascii_art(self):
|
||||
"""Get ASCII art for the profile."""
|
||||
return self.ascii_art
|
||||
|
||||
def get_full_profile(self):
|
||||
"""Get complete profile with ASCII art."""
|
||||
return f"""{self.ascii_art}
|
||||
|
||||
👨💻 Developer: {self.name}
|
||||
🏛️ Affiliation: {self.affiliation}
|
||||
📧 Email: {self.email}
|
||||
🐙 GitHub: @{self.github_username}
|
||||
🔥 Ready to build ML systems from scratch!
|
||||
"""
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
### 🧪 Test Your Developer Profile
|
||||
|
||||
Customize your developer profile! Replace the default information with your own:
|
||||
"""
|
||||
|
||||
# %%
|
||||
# Test the DeveloperProfile class
|
||||
try:
|
||||
print("Testing DeveloperProfile (with defaults):")
|
||||
# Default profile (instructor)
|
||||
default_profile = DeveloperProfile()
|
||||
print(f"Profile: {default_profile}")
|
||||
print(f"Signature: {default_profile.get_signature()}")
|
||||
print()
|
||||
|
||||
print("🎨 ASCII Art Preview:")
|
||||
print(default_profile.get_ascii_art())
|
||||
print()
|
||||
|
||||
print("🔥 Full Profile Display:")
|
||||
print(default_profile.get_full_profile())
|
||||
print()
|
||||
|
||||
# TODO: Students should customize this with their own information!
|
||||
print("🎯 YOUR TURN: Create your own profile!")
|
||||
print("Uncomment and modify the lines below:")
|
||||
print("# my_profile = DeveloperProfile(")
|
||||
print("# name='Your Name',")
|
||||
print("# affiliation='Your University/Company',")
|
||||
print("# email='your.email@example.com',")
|
||||
print("# github_username='yourgithub',")
|
||||
print("# ascii_art='''")
|
||||
print("# Your Custom ASCII Art Here!")
|
||||
print("# Maybe your initials, a logo, or something fun!")
|
||||
print("# '''")
|
||||
print("# )")
|
||||
print("# print(f'My Profile: {my_profile}')")
|
||||
print("# print(f'My Signature: {my_profile.get_signature()}')")
|
||||
print("# print(my_profile.get_full_profile())")
|
||||
|
||||
except NotImplementedError as e:
|
||||
print(f"⚠️ {e}")
|
||||
print("Implement the DeveloperProfile class above first!")
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
### 🎨 Personalization Challenge
|
||||
|
||||
**For Students**: Make TinyTorch truly yours by:
|
||||
|
||||
1. **Update your profile** in the cell above with your real information
|
||||
2. **Create custom ASCII art** - your initials, a simple logo, or something that represents you
|
||||
3. **Customize the flame file** - edit `tinytorch_flame.txt` to create your own default art
|
||||
4. **Add your signature** to code you write throughout the course
|
||||
5. **Show off your full profile** with the `get_full_profile()` method
|
||||
|
||||
This isn't just about customization - it's about taking ownership of your learning journey in ML systems!
|
||||
|
||||
**ASCII Art Customization Options:**
|
||||
|
||||
**Option 1: Custom ASCII Art Parameter**
|
||||
```python
|
||||
my_profile = DeveloperProfile(
|
||||
name="Your Name",
|
||||
ascii_art='''
|
||||
Your Custom ASCII Art Here!
|
||||
Maybe your initials, a logo, or something fun!
|
||||
'''
|
||||
)
|
||||
```
|
||||
|
||||
**Option 2: Edit the Default Flame File**
|
||||
- Edit `tinytorch_flame.txt` in this directory
|
||||
- Replace with your own ASCII art design
|
||||
- All students using defaults will see your custom art!
|
||||
|
||||
**ASCII Art Ideas:**
|
||||
- Your initials in block letters
|
||||
- A simple logo or symbol that represents you
|
||||
- Your university mascot in ASCII
|
||||
- A coding-themed design
|
||||
- Something that motivates you!
|
||||
|
||||
**Pro Tip**: The `tinytorch_flame.txt` file contains the beautiful default flame art. You can:
|
||||
- Edit it directly for a personalized default
|
||||
- Create your own `.txt` file and modify the code to load it
|
||||
- Use online ASCII art generators for inspiration
|
||||
"""
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## Step 4: Try the Export Process
|
||||
|
||||
Now let's export our code! In your terminal, run:
|
||||
|
||||
```bash
|
||||
python bin/tito.py sync --module setup
|
||||
```
|
||||
|
||||
This 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!
|
||||
|
||||
**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.
|
||||
"""
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## Step 5: Run Tests
|
||||
|
||||
After exporting, run the tests:
|
||||
|
||||
```bash
|
||||
python bin/tito.py test --module setup
|
||||
```
|
||||
|
||||
This will run all tests for the setup module and verify your implementation works correctly.
|
||||
|
||||
## Step 6: Check Your Progress
|
||||
|
||||
See your overall progress:
|
||||
|
||||
```bash
|
||||
python bin/tito.py info
|
||||
```
|
||||
|
||||
This shows which modules are complete and which are pending.
|
||||
"""
|
||||
|
||||
# %% [markdown]
|
||||
"""
|
||||
## 🎉 Congratulations!
|
||||
|
||||
You've learned the TinyTorch development workflow:
|
||||
|
||||
1. ✅ Write code in notebooks with `#| export`
|
||||
2. ✅ Export with `tito sync --module setup`
|
||||
3. ✅ Test with `tito test --module setup`
|
||||
4. ✅ 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! 🔥
|
||||
"""
|
||||
|
||||
@@ -12,11 +12,11 @@ from io import StringIO
|
||||
# Add the parent directory to the path so we can import setup_dev
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from setup_dev import hello_tinytorch
|
||||
from setup_dev import hello_tinytorch, add_numbers, SystemInfo, DeveloperProfile
|
||||
|
||||
|
||||
class TestSetupModule:
|
||||
"""Test suite for the setup module."""
|
||||
class TestSetupFunctions:
|
||||
"""Test setup module functions."""
|
||||
|
||||
def test_hello_tinytorch_executes(self):
|
||||
"""Test that hello_tinytorch runs without error."""
|
||||
@@ -32,6 +32,165 @@ class TestSetupModule:
|
||||
assert "Tiny🔥Torch" in captured.out
|
||||
assert "Build ML Systems from Scratch!" in captured.out
|
||||
|
||||
def test_add_numbers_basic(self):
|
||||
"""Test basic addition functionality."""
|
||||
assert add_numbers(2, 3) == 5
|
||||
assert add_numbers(10, 15) == 25
|
||||
assert add_numbers(0, 0) == 0
|
||||
|
||||
def test_add_numbers_negative(self):
|
||||
"""Test addition with negative numbers."""
|
||||
assert add_numbers(-5, 3) == -2
|
||||
assert add_numbers(-10, -15) == -25
|
||||
assert add_numbers(10, -5) == 5
|
||||
|
||||
def test_add_numbers_floats(self):
|
||||
"""Test addition with floating point numbers."""
|
||||
assert abs(add_numbers(2.5, 3.7) - 6.2) < 1e-9
|
||||
assert abs(add_numbers(1.1, 2.2) - 3.3) < 1e-9
|
||||
|
||||
|
||||
class TestSystemInfo:
|
||||
"""Test SystemInfo class."""
|
||||
|
||||
def test_system_info_creation(self):
|
||||
"""Test SystemInfo class instantiation."""
|
||||
info = SystemInfo()
|
||||
assert hasattr(info, 'python_version')
|
||||
assert hasattr(info, 'platform')
|
||||
assert hasattr(info, 'machine')
|
||||
|
||||
def test_system_info_properties(self):
|
||||
"""Test SystemInfo properties."""
|
||||
info = SystemInfo()
|
||||
|
||||
# Check python_version is a version tuple
|
||||
assert hasattr(info.python_version, 'major')
|
||||
assert hasattr(info.python_version, 'minor')
|
||||
assert isinstance(info.python_version.major, int)
|
||||
assert isinstance(info.python_version.minor, int)
|
||||
|
||||
# Check platform is a string
|
||||
assert isinstance(info.platform, str)
|
||||
assert len(info.platform) > 0
|
||||
|
||||
# Check machine is a string
|
||||
assert isinstance(info.machine, str)
|
||||
assert len(info.machine) > 0
|
||||
|
||||
def test_system_info_str(self):
|
||||
"""Test SystemInfo string representation."""
|
||||
info = SystemInfo()
|
||||
str_repr = str(info)
|
||||
|
||||
assert isinstance(str_repr, str)
|
||||
assert "Python" in str_repr
|
||||
assert str(info.python_version.major) in str_repr
|
||||
assert str(info.python_version.minor) in str_repr
|
||||
assert info.platform in str_repr
|
||||
assert info.machine in str_repr
|
||||
|
||||
def test_is_compatible(self):
|
||||
"""Test SystemInfo compatibility check."""
|
||||
info = SystemInfo()
|
||||
compatible = info.is_compatible()
|
||||
|
||||
# Should return a boolean
|
||||
assert isinstance(compatible, bool)
|
||||
|
||||
# Since we're running this test, Python should be >= 3.8
|
||||
assert compatible is True
|
||||
|
||||
|
||||
class TestDeveloperProfile:
|
||||
"""Test DeveloperProfile class."""
|
||||
|
||||
def test_developer_profile_creation_defaults(self):
|
||||
"""Test DeveloperProfile with default values."""
|
||||
profile = DeveloperProfile()
|
||||
|
||||
# Check default values
|
||||
assert profile.name == "Vijay Janapa Reddi"
|
||||
assert profile.affiliation == "Harvard University"
|
||||
assert profile.email == "vj@eecs.harvard.edu"
|
||||
assert profile.github_username == "profvjreddi"
|
||||
assert profile.ascii_art is not None # Should have default flame
|
||||
|
||||
def test_developer_profile_creation_custom(self):
|
||||
"""Test DeveloperProfile with custom values."""
|
||||
custom_art = """
|
||||
Custom ASCII Art
|
||||
****************
|
||||
"""
|
||||
profile = DeveloperProfile(
|
||||
name="Test Student",
|
||||
affiliation="Test University",
|
||||
email="test@example.com",
|
||||
github_username="teststudent",
|
||||
ascii_art=custom_art
|
||||
)
|
||||
|
||||
assert profile.name == "Test Student"
|
||||
assert profile.affiliation == "Test University"
|
||||
assert profile.email == "test@example.com"
|
||||
assert profile.github_username == "teststudent"
|
||||
assert profile.ascii_art == custom_art
|
||||
|
||||
def test_developer_profile_str(self):
|
||||
"""Test DeveloperProfile string representation."""
|
||||
profile = DeveloperProfile()
|
||||
str_repr = str(profile)
|
||||
|
||||
assert isinstance(str_repr, str)
|
||||
assert "👨💻" in str_repr
|
||||
assert "Vijay Janapa Reddi" in str_repr
|
||||
assert "Harvard University" in str_repr
|
||||
assert "@profvjreddi" in str_repr
|
||||
|
||||
def test_developer_profile_signature(self):
|
||||
"""Test DeveloperProfile signature method."""
|
||||
profile = DeveloperProfile()
|
||||
signature = profile.get_signature()
|
||||
|
||||
assert isinstance(signature, str)
|
||||
assert "Built by" in signature
|
||||
assert "Vijay Janapa Reddi" in signature
|
||||
assert "@profvjreddi" in signature
|
||||
|
||||
def test_developer_profile_ascii_art(self):
|
||||
"""Test DeveloperProfile ASCII art functionality."""
|
||||
# Test default ASCII art
|
||||
profile = DeveloperProfile()
|
||||
ascii_art = profile.get_ascii_art()
|
||||
|
||||
assert isinstance(ascii_art, str)
|
||||
assert "Tiny🔥Torch" in ascii_art
|
||||
assert "Build ML Systems from Scratch!" in ascii_art
|
||||
assert len(ascii_art) > 100 # Should be substantial ASCII art
|
||||
|
||||
# Test custom ASCII art
|
||||
custom_art = "My Custom Art!"
|
||||
custom_profile = DeveloperProfile(ascii_art=custom_art)
|
||||
assert custom_profile.get_ascii_art() == custom_art
|
||||
|
||||
def test_developer_profile_full_profile(self):
|
||||
"""Test DeveloperProfile full profile display."""
|
||||
profile = DeveloperProfile()
|
||||
full_profile = profile.get_full_profile()
|
||||
|
||||
assert isinstance(full_profile, str)
|
||||
assert "Tiny🔥Torch" in full_profile
|
||||
assert "Build ML Systems from Scratch!" in full_profile
|
||||
assert "👨💻 Developer: Vijay Janapa Reddi" in full_profile
|
||||
assert "🏛️ Affiliation: Harvard University" in full_profile
|
||||
assert "📧 Email: vj@eecs.harvard.edu" in full_profile
|
||||
assert "🐙 GitHub: @profvjreddi" in full_profile
|
||||
assert "🔥 Ready to build ML systems from scratch!" in full_profile
|
||||
|
||||
|
||||
class TestFileOperations:
|
||||
"""Test file-related operations."""
|
||||
|
||||
def test_ascii_art_file_exists(self):
|
||||
"""Test that the ASCII art file exists."""
|
||||
art_file = Path(__file__).parent.parent / "tinytorch_flame.txt"
|
||||
@@ -60,4 +219,33 @@ class TestSetupModule:
|
||||
|
||||
# Should still print the branding text
|
||||
assert "🔥 TinyTorch 🔥" in captured.out
|
||||
assert "Build ML Systems from Scratch!" in captured.out
|
||||
assert "Build ML Systems from Scratch!" in captured.out
|
||||
|
||||
|
||||
class TestModuleIntegration:
|
||||
"""Test integration between different parts of the setup module."""
|
||||
|
||||
def test_all_functions_work_together(self):
|
||||
"""Test that all setup functions work without conflicts."""
|
||||
# Test functions
|
||||
hello_tinytorch() # Should not raise
|
||||
sum_result = add_numbers(5, 10)
|
||||
|
||||
# Test classes
|
||||
info = SystemInfo()
|
||||
profile = DeveloperProfile()
|
||||
|
||||
# All should work without errors
|
||||
assert sum_result == 15
|
||||
assert str(info) # Should not be empty
|
||||
assert str(profile) # Should not be empty
|
||||
assert profile.get_signature() # Should not be empty
|
||||
assert profile.get_ascii_art() # Should not be empty
|
||||
|
||||
def test_no_import_errors(self):
|
||||
"""Test that imports work correctly."""
|
||||
# If we got here, imports worked
|
||||
assert callable(hello_tinytorch)
|
||||
assert callable(add_numbers)
|
||||
assert callable(SystemInfo)
|
||||
assert callable(DeveloperProfile)
|
||||
Reference in New Issue
Block a user