Commit Graph

139 Commits

Author SHA1 Message Date
Vijay Janapa Reddi
23c5eb2b51 refactor: implement strict progressive disclosure for autograd
- Module 01: Remove requires_grad, grad, backward() from Tensor class
  Students learn pure tensor math first without gradient concepts

- Module 02: Remove requires_grad propagation from Softmax
  Activations are now forward-only until autograd is enabled

- Module 03: Remove requires_grad=True from layer weights
  Layers store parameters without gradient flags

- Module 05: Update enable_autograd() to ADD gradient infrastructure
  Now adds requires_grad, grad, and backward() to Tensor class
  Uses helper functions for tensors created before autograd

- Module 09: Remove Conv2dBackward, MaxPool2dBackward classes
  Convolutions are now forward-only, no Module 05 import

- Module 11: Remove EmbeddingBackward import and usage
  Embeddings are now forward-only

- Modules 12, 13: Remove requires_grad from mask/param tensors

This implements true progressive disclosure: concepts are introduced
only when students are ready to learn them. Gradient tracking is now
completely absent from Modules 01-04 and added in Module 05.
2025-12-17 15:09:38 -05:00
Vijay Janapa Reddi
08ff168328 feat: add Binder/Source/Audio grid cards to module pages
Adds interactive launch cards to all 20 TinyTorch module ABOUT.md files:
- Launch Binder button for browser-based exploration
- View Source link to GitHub implementation
- Audio Overview placeholder for NotebookLM content

Cards wrapped in {only} html directive to exclude from PDF output.
Also removes duplicate README.md files from src modules.
2025-12-17 14:33:04 -05:00
Vijay Janapa Reddi
ea246cf4e2 Renames "Spatial" module to "Convolutions"
Refactors the module name from "Spatial" to "Convolutions" to better reflect its content and purpose, which focuses on convolutional neural networks.

This change ensures consistency and clarity across the codebase, documentation, and examples.
2025-12-17 07:35:32 -05:00
Vijay Janapa Reddi
82984bbff2 refactor(tinytorch): remove section numbers from markdown headers
Standardize header format across all 20 module files by removing
numbered prefixes. Headers now use descriptive titles only, making
maintenance easier when reordering sections.

Changes:
- `## 1. Introduction` → `## Introduction`
- `## Part N: Title` → `## Title`
- `## N.N Subsection` → `## Subsection`

Header hierarchy preserved (H1 for module title, H2 for sections).
2025-12-16 07:18:29 -05:00
Vijay Janapa Reddi
a6f9bc3b0b feat(tinytorch): add module.yaml metadata files for CLI module descriptions
Add machine-readable module.yaml files to each of the 20 modules with
title, subtitle, and description fields. Update tito CLI to read from
these files instead of parsing Python files.

- Create module.yaml in src/NN_*/ directories
- Add YAML parser with validation in tito/core/modules.py
- Update list_modules() to display descriptions from YAML
2025-12-15 20:30:32 -05:00
Vijay Janapa Reddi
5b0959d63b fix(tinytorch): standardize markdown header levels in module files
- Fix H1 headers that should be H2 in 04_losses.py (Part 1-6)
- Fix H1 headers that should be H2 in 19_benchmarking.py (sections 1-5)
- Fix duplicate Part 4 numbering in 08_dataloader.py (now Part 4b)
- Fix duplicate Part 3 numbering in 17_memoization.py (now Part 3b)
- Fix out-of-order subsection numbering in 16_compression.py (8.1-8.4)

These are cosmetic changes to markdown headers inside triple-quoted
strings. They ensure proper hierarchy when exported to Jupyter notebooks.
2025-12-15 20:15:08 -05:00
Vijay Janapa Reddi
daabc04910 refactor(tinytorch): standardize export naming conventions
- bench → perf.benchmarking (consistent with other perf modules)
- capstone → olympics (sets vision for competition system)
- Update all import references across milestones, tests, and CLI
2025-12-15 19:28:43 -05:00
Vijay Janapa Reddi
d6a96ca2d2 fix(tinytorch): correct Binder URLs and remove broken Colab links
- Update Binder URLs to use urlpath parameter pointing to generated
  notebooks in modules/ directory instead of raw .py files
- Remove Colab links since they cannot run postBuild to generate notebooks
- Fix View Source links to include tinytorch/ prefix
2025-12-15 13:45:31 -05:00
Vijay Janapa Reddi
eec214e335 fix: resolve Jupyter Book build warnings and PDF diagram readability
- Fix broken symlink for 09_convolutions_ABOUT.md
- Fix header level warnings (H1 to H3 jumps) in community.md and intro.md
- Remove broken cross-references to deleted files across site pages
- Fix lexing errors by using text blocks for Unicode characters
- Update mermaid diagram in big-picture.md to use light fill colors
  for PDF compatibility (mermaid-cli does not respect inline color styles)
2025-12-14 14:58:47 -05:00
Vijay Janapa Reddi
5305cdb032 chore: clean up unused files and fix paper competency matrix
- Fix competency coverage counts: 36 full (90%), 3 partial (7.5%), 1 gap (2.5%)
- Remove Deployment-Debugs from intentional gaps (was listed twice)
- Remove unused site markdown files not in TOC
- Remove src/LEARNING_PATH.md (not referenced)
- Update module flow diagram to LR layout

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-12-14 14:32:34 -05:00
Vijay Janapa Reddi
f5f1615840 fix: restore pedagogical prerequisites for proper learning progression
Prerequisites now reflect intended learning sequence rather than just
code imports. Understanding why matters as much as what imports.

Pedagogical structure:
- Phase 1 Foundation (01-04): Sequential chain building core concepts
- Phase 2 Training (05-07): Autograd needs loss context, optimizers need gradients
- Phase 3 Architecture: CV track (08-09), NLP track (10-13) branch from foundation
- Phase 4 Optimization (14-19): All require models to optimize (01-13)

Key insight: A student could technically run memoization code with only
Tensor knowledge, but would not understand WHY KV caching matters without
first building attention and transformers. Prerequisites guide learning,
not just code execution.
2025-12-14 14:05:57 -05:00
Vijay Janapa Reddi
672e21e30a fix: update module prerequisites to reflect actual import dependencies
Prerequisites now match code imports rather than pedagogical sequencing.
Each module lists only the modules it actually imports from, making
dependencies accurate and reducing unnecessary barriers to entry.

Key changes:
- Modules 05, 06, 08, 10, 17: Only require Module 01 (Tensor)
- Module 07 Training: Requires 01, 03, 04, 06 (not 01-06)
- Modules 09, 11: Require 01, 05 (Tensor + Autograd)
- Module 12 Attention: Requires 01, 02, 03 (not 01-05, 10-11)
- Module 13 Transformers: Requires 01, 02, 03, 11, 12
- Modules 15, 16: Require 01, 02, 03 (not full stack)
- Module 18: Requires 01, 14 (Tensor + Profiling)
- Module 19: Requires only 14 (Profiling)
2025-12-14 14:00:06 -05:00
Vijay Janapa Reddi
0c3c75678e refactor: rename Module 09 from Spatial to Convolutions
- Rename directories: src/09_spatial → src/09_convolutions,
  tests/09_spatial → tests/09_convolutions
- Rename files: 09_spatial.py → 09_convolutions.py,
  test_spatial_*.py → test_convolutions_*.py
- Update TOC files, TITO CLI mappings, and documentation
- Update navigation links between modules
- Remove misplaced duplicate test file from tests/06_optimizers/
- Use "CNNs" in diagrams, "Convolutions" in prose for consistency

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-12-14 13:13:18 -05:00
Vijay Janapa Reddi
fcf3d8bd12 fix: update all GitHub URLs from mlsysbook/TinyTorch to harvard-edge/cs249r_book
- Update all repository references to point to harvard-edge/cs249r_book
- Fix Binder URLs to include tinytorch/ path prefix
- Fix Colab URLs to include tinytorch/ path prefix
- Update marimo-badges.js with correct repo and path
- Fix dataset documentation URLs
- Update module ABOUT.md files with correct source links

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-12-14 12:36:10 -05:00
Vijay Janapa Reddi
c2598e827d docs: improve orientation files based on expert review
Critical fixes:
- Add getting-started.md to PDF TOC (students need setup instructions)
- Move Course Orientation to position #2 in website TOC (better discoverability)
- Add prerequisites warning note at top of getting-started.md

High priority improvements:
- Add "What if validation fails?" troubleshooting section
- Add per-module time estimates table (60-80 hours total)
- Clarify autograd prerequisites (chain rule conceptual knowledge needed)
- Standardize Quick Start terminology (fix links to getting-started.md)
- Add persona-based routing in "What to Read Next" sections

Content cleanup:
- Remove redundant prerequisites from preface.md
- Remove tier overview duplication from preface.md
- Remove MLSysBook from prerequisites.md (already in preface)
- Convert prerequisites.md from 65% bullets to 90% prose
- Simplify learning-journey.md intro (remove awkward meta-section)
- Fix checkpoints -> modules terminology in learning-journey.md
- Restore instructor "coming soon" section in getting-started.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 16:48:59 -05:00
Vijay Janapa Reddi
69a3e19f2f style: rebrand "Your TinyTorch" to "Your Tiny🔥Torch" across codebase
Consistent branding with flame emoji in all module ABOUTs,
milestone files, site documentation, and Python scripts.
2025-12-13 15:23:28 -05:00
Vijay Janapa Reddi
2e476722ae fix: improve PDF admonition colors and convert to native Sphinx directives
- Add sphinxsetup configuration with distinct colors for each admonition type
  (tip=green, warning=orange, note=blue, caution=red, etc.)
- Convert {admonition} with :class: attribute to native {tip}, {warning},
  {seealso} directives for proper Sphinx type detection in LaTeX output
- Remove unsupported emojis from site markdown files for LaTeX compatibility
- Update codespell ignore list for font names (Heros) and PDF options (FitH)
- Update 20 ABOUT.md files and 16 site/*.md files
2025-12-13 14:58:59 -05:00
Vijay Janapa Reddi
853eb03ee8 style: apply consistent whitespace and formatting across codebase 2025-12-13 14:05:34 -05:00
Vijay Janapa Reddi
efc577f53f fix: improve ABOUT.md accuracy and PDF-compatible Get Started sections
- Fix API signatures to match actual implementations across all modules
- Correct loop counts (Module 09: 6→7 nested loops)
- Fix import paths (Module 14, 18: perf.* not nn.*)
- Clarify vectorized vs explicit loop implementations (Modules 05, 12)
- Replace {grid} cards with admonition-based links for PDF rendering
- Add missing API documentation (Modules 06, 08, 10, 13, 16)
- Update about-generator agent with accuracy requirements
2025-12-13 14:03:15 -05:00
Vijay Janapa Reddi
5e26319fbc style: remove extra blank lines from markdown files
Clean up documentation by collapsing multiple consecutive blank lines
into single blank lines for consistency.
2025-12-13 13:32:53 -05:00
Vijay Janapa Reddi
3d926463d9 fix: minor improvements to ABOUT.md files based on parallel review
Fixes identified during parallel review of all 19 ABOUT.md files:

- Module 07: Add emojis to Get Started cards for consistency
- Module 10: Spell out "NMT" as "neural machine translation"
- Module 12: Fix positional encoding reference (Module 11, not 13)
- Module 15: Fix docstring comment (asymmetric, not symmetric)
- Module 16: Clarify scope of excluded features
2025-12-13 11:28:43 -05:00
Vijay Janapa Reddi
d7ac86fa82 docs: generate standardized ABOUT.md files for all 19 modules (02-20)
Generated comprehensive ABOUT.md companion documents for all TinyTorch
modules following the canonical Module 01 template structure:

Foundation Tier (Modules 02-07):
- Activations: ReLU, Sigmoid, Tanh, GELU, Softmax with numerical stability
- Layers: Linear, Dropout, Sequential with Xavier/He initialization
- Losses: MSE, CrossEntropy with log-sum-exp stability
- Autograd: Computation graphs, chain rule, backward pass
- Optimizers: SGD, Adam, AdamW with momentum and weight decay
- Training: Training loops, schedulers, gradient clipping, checkpointing

Architecture Tier (Modules 08-13):
- DataLoader: Dataset abstraction, batching, shuffling, iterator protocol
- Spatial: Conv2d, MaxPool2d, AvgPool2d with explicit loops
- Tokenization: Character and BPE tokenizers with vocabulary building
- Embeddings: Embedding tables, positional encoding, lookup operations
- Attention: Scaled dot-product, multi-head attention, causal masking
- Transformers: LayerNorm, MLP, TransformerBlock, complete GPT model

Optimization Tier (Modules 14-20):
- Profiling: Timing, memory measurement, bottleneck identification
- Quantization: INT8 quantization, scale/zero-point, PTQ
- Compression: Magnitude pruning, structured pruning, knowledge distillation
- Memoization: KV cache, gradient checkpointing, cache invalidation
- Acceleration: Vectorization, BLAS, kernel fusion, tiled operations
- Benchmarking: Statistical validity, reproducibility, MLPerf methodology
- Capstone: Complete benchmarking system, submission generation

Each ABOUT.md includes:
- 13 standardized sections matching Module 01 structure
- Embedded code snippets from actual .py implementations
- Progressive terminology (only uses terms from prior modules)
- Mermaid architecture diagrams
- Quantitative questions with calculations
- Production context comparisons (TinyTorch vs PyTorch)
- Seminal paper references in Further Reading
- Tab-set code comparisons with "Your Tiny🔥Torch" branding
2025-12-13 11:24:45 -05:00
Vijay Janapa Reddi
77a40ffea8 feat: add ABOUT.md generation system with agent instructions
- Create about-generator.md agent with YAML frontmatter
- Create about-guidelines.md with 13-section template
- Update Module 01 ABOUT.md as canonical reference
- Add embedded code snippets from .py files
- Add Q5 (views vs copies) and BLAS paper reference
- Use 'Your Tiny🔥Torch' branding in tab-sets
- Remove chapter-level TOC (master TOC handles navigation)
- Configure PDF TOC depth to 3 in _config.yml
2025-12-13 11:14:48 -05:00
Vijay Janapa Reddi
7af42694fb refactor: consolidate ABOUT.md files using symlinks
- Replace site/modules/*_ABOUT.md files with symlinks to src/*/ABOUT.md
- src/ is now the single source of truth for module documentation
- Sync cleaned-up versions (emoji removal) from site/ back to src/
- Remove sync target from Makefile since symlinks handle everything
- Jupyter Book works with symlinks, no build changes needed
2025-12-12 16:43:16 -05:00
Vijay Janapa Reddi
d21dd1dca0 fix: correct invalid tito CLI commands in documentation
- Fix 56+ invalid CLI references across markdown files
- Replace nonexistent commands with valid alternatives:
  - tito checkpoint → tito module status
  - tito milestones → tito milestone
  - tito system check/doctor → tito system health
  - tito community leave → tito community logout
  - tito reset all → tito module reset XX
  - tito status → tito module status / tito milestone status
- Add pre-commit hook to prevent future CLI documentation drift
- Organize pre-commit config for monorepo (book + tinytorch sections)
2025-12-12 15:56:26 -05:00
Vijay Janapa Reddi
509c404bea fix: replace SimpleModel with Sequential in quantization and compression modules
SimpleModel was never exported from tinytorch.core.layers. Sequential
provides the same functionality (.layers, .parameters()) and is the
industry-standard name that students should learn.
2025-12-11 19:19:38 -08:00
Vijay Janapa Reddi
ceb384e863 refactor(paper): improve consistency and add memory_footprint to Tensor
- Add memory_footprint() method to Tensor class matching paper Listing 1
- Fix milestone numbering: use 'Milestone 1-6' instead of confusing 'M03/M06' format
- Remove unvalidated hour estimates (60-80 hours) from abstract and configurations
- Simplify NBGrader language, removing 'unvalidated' caveats
- Clean up time-to-completion language in validation roadmap
2025-12-07 13:35:42 -08:00
Vijay Janapa Reddi
24178f6cbd fix(tinytorch): remove unused matplotlib import from memoization module
The matplotlib import in profile_naive_generation() was unused and causing
import errors when matplotlib is not installed. Removed to fix module tests.
2025-12-07 12:06:20 -08:00
Vijay Janapa Reddi
a774c7e4bb refactor(tinytorch): standardize all module ABOUT.md structure
- Move 'Getting Started' section earlier (position 6, after Build → Use → Reflect)
- Add 'Common Pitfalls' section to all modules (3-5 pitfalls with code examples)
- Add 'Production Context' section to all modules (framework comparisons, real-world usage)
- Verify professional emoji usage (no emoji in section headers)
- Apply consistent structure across all 20 modules
2025-12-07 11:13:11 -08:00
Vijay Janapa Reddi
11a55101be refactor(module 03): remove redundant code and fix docstrings
Additional cleanup following module review:
- Removed redundant __call__ method from Linear (inherits from Layer)
- Fixed Dropout docstrings to correctly describe inference behavior
- Simplified Sequential.parameters() by removing unnecessary hasattr check

All 61 tests still passing after cleanup
2025-12-07 06:05:32 -08:00
Vijay Janapa Reddi
c0af0eb36b refactor(tinytorch): cleanup modules 02, 09, 12, 17, 18 following module 03 principles
Applied API simplification and consistency improvements across multiple modules:

Module 02 (Activations):
- Added __all__ export list to control public API
- Removed redundant import statement
- Prevents internal constants from polluting namespace

Module 09 (Spatial):
- Fixed test naming to use PyTorch conventions (Conv2d not Conv2D)
- Fixed AvgPool2d gradient tracking (added requires_grad parameter)
- Updated all test imports to use lowercase 'd' naming

Module 12 (Attention):
- Fixed progressive integration tests to use correct Trainer API
- Added missing loss_fn parameter to Trainer calls

Module 17 (Memoization):
- Removed redundant create_kv_cache() function (use KVCache() directly)
- Made internal constants private (_BYTES_PER_FLOAT32, _MB_TO_BYTES)
- Simplified API from 6 exports to 3 core components
- 50% reduction in public API surface

Module 18 (Acceleration):
- Fixed test suite to match function-based API
- Added tests for vectorized_matmul, fused_gelu, tiled_matmul
- All 6 tests now passing

Rationale:
- API simplicity: one clear way to do things
- Progressive disclosure: hide implementation details
- Consistent naming: follow established conventions
- Test coverage: validate all exported functionality

All module tests passing after changes
2025-12-07 06:05:15 -08:00
Vijay Janapa Reddi
0cf91ee0c3 refactor(tinytorch): simplify module 03 API and remove confusing aliases
Simplifies the layers module API by removing alias proliferation that could confuse students in a pedagogical framework.

Changes:
- Rename SimpleModel → Sequential (matches PyTorch naming)
- Remove create_mlp() and MLP alias (taught in milestones, not core modules)
- Remove input_size/output_size aliases from Linear (keep only in_features/out_features)
- Update all tests to use explicit Sequential composition
- Fix dtype test to validate float32 normalization (TinyTorch's design)

Module focus: Individual building blocks (Linear, Dropout, Sequential container)
MLP construction: Taught in Milestone 03 (1986 MLP) using manual composition

Rationale:
- Progressive disclosure: students learn explicit composition first
- API clarity: one way to do things reduces cognitive load
- Separation of concerns: modules teach primitives, milestones teach patterns

All tests passing: 48/48 in module 03, 214/221 across all modules
2025-12-07 05:31:05 -08:00
Vijay Janapa Reddi
edfe9d9a77 fix(tinytorch): add missing exports and fix benchmark tests
- Module 19: Add #| export to import block so dataclass is exported
- Fix benchmark tests to use correct Benchmark API (requires models/datasets)
2025-12-06 21:42:14 -08:00
Vijay Janapa Reddi
85393c66bc fix(tinytorch): update benchmarking demo to use correct API
- Add missing imports for Tensor and Linear
- Fix parameter names: warmup_iterations -> warmup_runs
- Fix attribute names: min/max -> min_val/max_val
- Use run_latency_benchmark method with input_shape parameter
2025-12-06 21:20:24 -08:00
Vijay Janapa Reddi
e839e9658f feat(tinytorch): add SimpleModel utility class to layers module
Add SimpleModel as a minimal container for explicit layer composition.
Used by quantization, compression, and capstone modules for:
- Collecting parameters from multiple layers
- Running integration tests
- Enabling optimization functions that need a model object

This consolidates SimpleModel definitions that were scattered across modules.
2025-12-06 21:19:19 -08:00
Vijay Janapa Reddi
4556d225b5 fix(tinytorch): add missing export directives for quantization/compression functions
Add #| export directives to ensure functions are properly exported to package:
- Module 15: quantize_int8, dequantize_int8, quantize_model
- Module 16: measure_sparsity

These functions were defined but not exported, causing import errors when
using the perf/ package path.
2025-12-06 21:12:14 -08:00
Vijay Janapa Reddi
744f1499e6 feat(tinytorch): add verify_quantization_works and verify_pruning_works functions
Port verification functions from mlsysbook/TinyTorch standalone repo.
These functions prove optimizations work using real .nbytes measurements.

Module 15 (quantization):
- Add verify_quantization_works() function
- Measures actual FP32 vs INT8 memory reduction
- Asserts >= 3.5x reduction (targeting 4x)

Module 16 (compression):
- Add verify_pruning_works() function
- Counts actual zeros in parameter arrays
- Honestly reports memory unchanged (dense storage)
- Explains compute savings vs memory savings

Both functions:
- Are exported to tinytorch package
- Return dicts with verification results
- Include educational messaging about production usage
2025-12-06 21:05:52 -08:00
Vijay Janapa Reddi
14c7b58c02 fix(tinytorch): resolve function shadowing in modules 15 and 16
Modules 15 (quantization) and 16 (compression) had a bug where
'convenience wrapper' functions at the end of the file shadowed
the main implementations, causing test failures.

Changes:
- Module 15: Import SimpleModel from tinytorch.core.layers
- Module 15: Quantizer class now delegates to standalone functions
- Module 15: Remove shadowing wrappers (quantize_model, dequantize_int8)
- Module 16: Import SimpleModel from tinytorch.core.layers
- Module 16: Compressor class now delegates to standalone functions
- Module 16: Remove shadowing wrappers (measure_sparsity, magnitude_prune, etc.)

The pattern now is:
- Standalone functions: Primary implementations students build
- Quantizer/Compressor classes: OOP interface that delegates to standalone functions
- No duplicate definitions that could shadow each other

All 20 modules now pass their tests.
2025-12-06 21:00:56 -08:00
Vijay Janapa Reddi
c602f97364 feat: integrate TinyTorch into MLSysBook repository
TinyTorch educational deep learning framework now lives at tinytorch/

Structure:
- tinytorch/src/         - Source modules (single source of truth)
- tinytorch/tito/        - CLI tool
- tinytorch/tests/       - Test suite
- tinytorch/site/        - Jupyter Book website
- tinytorch/milestones/  - Historical ML implementations
- tinytorch/datasets/    - Educational datasets (tinydigits, tinytalks)
- tinytorch/assignments/ - NBGrader assignments
- tinytorch/instructor/  - Teaching materials

Workflows (with tinytorch- prefix):
- tinytorch-ci.yml           - CI/CD pipeline
- tinytorch-publish-dev.yml  - Dev site deployment
- tinytorch-publish-live.yml - Live site deployment
- tinytorch-build-pdf.yml    - PDF generation
- tinytorch-release-check.yml - Release validation

Repository Variables added:
- TINYTORCH_ROOT  = tinytorch
- TINYTORCH_SRC   = tinytorch/src
- TINYTORCH_SITE  = tinytorch/site
- TINYTORCH_TESTS = tinytorch/tests

All workflows use \${{ vars.TINYTORCH_* }} for path configuration.

Note: tinytorch/site/_static/favicon.svg kept as SVG (valid for favicons)
2025-12-05 19:23:18 -08:00