Commit Graph

676 Commits

Author SHA1 Message Date
Vijay Janapa Reddi
26a362ec2d style(milestones): minor formatting fixes in milestone files
- Fixed ASCII art alignment in xor_crisis.py
- Fixed table alignment in rumelhart_tinydigits.py
- Fixed table alignment in generation_speedup.py
2026-01-24 19:04:22 -05:00
Vijay Janapa Reddi
56c05085d0 style(modules): standardize unit test emoji to test tube
Update unit test markers across all 20 modules for consistency:
- Changed header emoji from microscope to test tube
- Maintains visual consistency across module test sections
2026-01-24 19:04:04 -05:00
Vijay Janapa Reddi
f4a748fd78 fix(optimizers,tokenization): set gradients after optimizer init, make vocab_size optional
Module 07 (optimizers):
- Fixed bug where param.grad was set before optimizer creation
- Optimizer.__init__ resets param.grad to None for all parameters
- Moved all gradient assignments to occur AFTER optimizer creation
- Fixes GitHub issue #1131

Module 10 (tokenization):
- Made BPETokenizer.train() vocab_size parameter optional with default None
- Fixes test failure when calling train() without explicit vocab_size

All 20 inline tests pass (verified via tito dev test --inline --ci)
2026-01-24 19:03:50 -05:00
Vijay Janapa Reddi
103545ee23 Merge remote-tracking branch 'origin/dev' into feature/volume-restructure
# Conflicts:
#	.codespell-ignore-words.txt
#	README.md
2026-01-24 18:41:46 -05:00
Vijay Janapa Reddi
2c9b0dccbf fix: restore Conv2dBackward and MaxPool2dBackward for CNN gradient flow
- Restore Conv2dBackward class removed in commit 23c5eb2b5
- Restore MaxPool2dBackward class for pooling gradient routing
- Update Conv2d/MaxPool2d forward() to attach _grad_fn
- Set requires_grad=True on Conv2d weights and bias
- Add enable_autograd() to Module 11 (Embeddings) for progressive disclosure
- Remove skip markers from convolution gradient tests

CNN training now works correctly - conv weights receive gradients and update
during training. All 40 convolution tests pass.
2026-01-24 17:39:11 -05:00
Vijay Janapa Reddi
b217f7c552 test: skip Conv2d/MaxPool2d gradient tests (known limitation)
Conv2d and MaxPool2d use raw numpy operations internally rather than
Tensor operations, so they don't participate in the autograd computation
graph. The forward pass works correctly and requires_grad propagates,
but backward() doesn't compute gradients through these operations.

This is a known architectural limitation of the educational implementation.
Proper autograd support would require either:
1. Rewriting conv/pool to use Tensor ops throughout, OR
2. Manually implementing backward functions

Skip these tests with clear documentation of why.
2026-01-24 14:42:18 -05:00
Vijay Janapa Reddi
7169ad6529 fix(ci): remove milestone stage and fix interactive prompt in CI
- Remove Stage 6 (milestone tests) from CI workflow since test files were
  removed as redundant with integration tests
- Renumber Stage 7 (release) to Stage 6
- Update summary job to remove milestone references
- Fix _trigger_submission() to skip interactive prompts in CI mode
  by checking CI, GITHUB_ACTIONS env vars and stdin.isatty()

The milestone demo scripts remain available for student use via
'tito milestone run', but are no longer run as automated tests.
2026-01-24 14:30:22 -05:00
Vijay Janapa Reddi
ea6a638431 refactor(tests): remove tests for unimplemented attention components
Remove test_attention_pipeline_integration.py and test_tensor_attention_integration.py
which test SelfAttention, create_causal_mask, and other components that do not exist
in the attention module. These were always skipped and provided no test value.

The existing attention tests (test_attention_core.py) properly test the actual
implemented components: scaled_dot_product_attention and MultiHeadAttention.
2026-01-24 14:07:48 -05:00
Vijay Janapa Reddi
e233814a63 refactor(tests): remove performance benchmark tests
Performance benchmark tests are inherently timing-sensitive and flaky
in CI environments. They were already skipped by default. Removing them
entirely as they provide no CI value - performance testing should be
done locally or in dedicated performance regression infrastructure.
2026-01-24 13:57:26 -05:00
Vijay Janapa Reddi
e409d5a94b refactor(tests): remove redundant milestone tests
Remove test_milestones_run.py and test_learning_verification.py as they
duplicate functionality already covered by module and integration tests.
The milestone demo scripts remain for student use, but running them as
tests adds no value beyond the existing test coverage.
2026-01-24 13:57:06 -05:00
Vijay Janapa Reddi
d53722eb81 fix(tests): skip flaky performance and transformer training tests in CI
- Skip test_performance.py by default (timing-sensitive benchmarks)
- Skip test_attention_runs (non-deterministic transformer training)

Both can be run manually when needed. This ensures CI passes reliably.

Test results: 845 passed, 36 skipped in ~4 minutes
2026-01-24 13:42:32 -05:00
Vijay Janapa Reddi
999fd13447 refactor(tests): reorganize test folders and fix misplaced files
Folder consolidation:
- Merge system/ into integration/ (removed duplicate folder)
- Remove performance/ (only had framework, no tests)

File relocations:
- Move test_dense_layer.py, test_dense_integration.py from 04_losses/ to 03_layers/
- Move test_network_capability.py from 04_losses/ to integration/
- Move test_kv_cache_integration.py from 14_profiling/ to 18_memoization/
- Move system/ tests (forward_passes, gradients, shapes, etc.) to integration/

Removed duplicates:
- system/test_gradient_flow_overall.py (duplicate of integration version)
- system/test_integration.py (redundant with integration/ folder)
- system/test_milestones.py (duplicate of milestones/ tests)

Final structure: 26 folders, 100 test files
2026-01-24 12:44:40 -05:00
Vijay Janapa Reddi
389989ece7 refactor(tests): clean up test folder and fix gradient flow issues
Test Cleanup (113 files, -22,000 lines):
- Remove 21 redundant run_all_tests.py files
- Remove checkpoints/ folder (22 obsolete checkpoint files)
- Remove progressive/, debugging/, diagnostic/ folders
- Remove duplicate integration tests and examples
- Remove orphaned dev artifacts and generated outputs
- Consolidate test_gradient_flow_overall.py into system/

Documentation Cleanup (4 files removed):
- Remove duplicate HOW_TO_USE.md, WORKFLOW.md, SYSTEM_DESIGN.md
- Trim environment/README.md from 334 to 86 lines
- Update capstone/README.md removing outdated bug references

Test Fixes:
- Add requires_grad=True to layer parameters in gradient tests
- Fix PositionalEncoding argument order in test_shapes.py
- Adjust performance thresholds for realistic expectations
- Fix gradient clipping to handle memoryview correctly
- Update zero_grad assertions to accept None or zeros
2026-01-24 12:22:37 -05:00
Vijay Janapa Reddi
aafd7a8c67 refactor(modules): standardize formatting and fix NBGrader directives
- Standardize test emoji usage (🔬 for unit tests, 🧪 for module tests)
- Restore missing NBGrader solution blocks in Module 15 (quantization)
- Fix missing #| default_exp directives in modules 05, 12, 13, 15, 17
- Remove duplicate #| default_exp directives
- Ensure all exports are only for core functionality (no tests/demos)
- Apply consistent styling across all 20 modules via module-developer agent
2026-01-24 10:07:18 -05:00
Vijay Janapa Reddi
975c92a1c6 fix(cli): resolve Rich markup rendering in module completion message
Text.append() does not interpret Rich markup - it treats strings as
literal text. Split the markup into separate append calls with proper
style parameters so the 'Next: tito module start XX' hint renders
correctly instead of showing literal [bold cyan] tags.
2026-01-24 09:29:51 -05:00
Vijay Janapa Reddi
1dab26b16c fix(tests): add optimizer creation to enable gradient flow in tests
The progressive disclosure design means layer parameters have
requires_grad=False until an optimizer is created. The optimizer
__init__ sets requires_grad=True on all parameters it receives.

Tests were checking gradient flow without creating an optimizer,
which does not reflect real usage. Students always create an optimizer
before training. Fixed tests to create optimizers first.

Remaining failures are real autograd limitations:
- Conv2d backward does not compute weight gradients
- Embedding backward does not compute weight gradients
- LayerNorm backward does not compute weight gradients

These are honest test failures that expose real bugs.
2026-01-24 08:35:56 -05:00
Vijay Janapa Reddi
770dac3469 fix(tests): correct API calls in system milestone tests
- Fix Tensor() call to not use dtype kwarg (use float literals instead)
- Fix PositionalEncoding to use max_seq_len param
- Fix TransformerBlock to use ff_dim instead of hidden_dim
2026-01-24 07:47:32 -05:00
Vijay Janapa Reddi
f524506d19 fix(tests): resolve API mismatches and fix test infrastructure
- Fix BenchmarkSuite instantiation (requires models, datasets params)
- Delete test_checkpoint_integration.py (tests non-existent APIs)
- Limit environment tests to main requirements.txt only
- Fix variable name bug in integration_simple_test.py
- Fix PositionalEncoding, TransformerBlock, LayerNorm API calls
- Fix milestone CLI tests to use 'tito milestone' not 'milestones'
- Add TITO_ALLOW_SYSTEM env var for CLI tests
2026-01-24 00:26:41 -05:00
Vijay Janapa Reddi
ed709c95a5 fix(tests): resolve import errors for honest test execution
- Fix test_capstone_core.py: use BenchmarkSuite instead of non-existent BenchmarkReport
- Remove test_integration_01_setup.py: references non-existent setup_dev module

These fixes allow the test suite to run without collection errors.
Gradient tests now correctly fail, exposing real autograd integration issues.
2026-01-23 23:27:30 -05:00
Vijay Janapa Reddi
9b3e9cb8dd cleanup(tests): remove redundant performance tests and aliases
- Delete test_module_15/16/17/19/20 files (duplicates of module-specific tests)
- Remove backward-compat aliases from performance_test_framework.py
- Update run_all_performance_tests.py to use pytest on module directories
- Replace PerformanceTestSuite alias with PerformanceTester

Tests now run from their proper locations in tests/{module}/ directories.
2026-01-23 23:13:54 -05:00
Vijay Janapa Reddi
42face28fb refactor(tests): remove all pytest.skip patterns for honest test results
- Move imports to module level in all *_core.py test files (16 files)
- Remove try/except/skip patterns from integration tests
- Remove @pytest.mark.skip decorators from gradient flow tests
- Convert environment validation skips to warnings for optional checks
- Change milestone tests from skip to fail when scripts missing

Tests now either pass or fail - no silent skipping that hides issues.
This ensures the test suite provides accurate feedback about what works.
2026-01-23 23:06:23 -05:00
Vijay Janapa Reddi
acb5142fd7 fix(tests): resolve import issues and test naming collisions
- Fix incorrect imports (tinytorch.text/nn/data → tinytorch.core.*)
- Fix MeanSquaredError → MSELoss imports
- Fix learning_rate= → lr= for optimizer arguments
- Rename test_progressive_integration.py files to unique names
- Add missing PerformanceTestSuite classes to performance framework
- Add pytest config to tinytorch/pyproject.toml to override coverage

This resolves the pytest collection errors caused by module name conflicts.
2026-01-23 17:59:43 -05:00
Vijay Janapa Reddi
e19be54703 debug(tests): show import errors in CI output for debugging 2026-01-23 17:15:52 -05:00
Vijay Janapa Reddi
918f72e6a2 fix(tests): add PYTHONPATH to pytest subprocess for CI imports
The _run_pytest method was missing PYTHONPATH in the subprocess
environment, causing tinytorch imports to fail in CI where the
package isn't installed system-wide.
2026-01-23 17:11:21 -05:00
Vijay Janapa Reddi
8127671bae fix(tests): correct import paths in milestone learning verification
- tinytorch.text.embeddings → tinytorch.core.embeddings
- tinytorch.data.loader → tinytorch.core.dataloader
2026-01-23 16:59:29 -05:00
Vijay Janapa Reddi
42bc991d75 fix(tests): add PYTHONPATH to inline test subprocess
Source files like src/02_activations/02_activations.py import from
tinytorch.core.tensor. When running these as subprocesses, the Python
path needs to include the project root so the imports resolve correctly.

This was causing CI to fail at module 02 because it couldn't find
tinytorch.core.tensor even though module 01 had exported it.
2026-01-23 16:56:17 -05:00
Vijay Janapa Reddi
102eacaaa2 feat(cli): implement tito module complete --all
- Added complete_all_modules() method that iterates through all modules
- Runs tests + export for each module in sequence (01 → 20)
- Stops on first failure for fail-fast behavior
- Skips modules without notebooks (shows as 'skipped')
- Useful for CI validation and students exporting all work

Distinction from dev export --all:
- dev export --all: Rebuilds from src/ (overwrites student notebooks)
- module complete --all: Tests + exports existing notebooks (safe for students)
2026-01-23 16:52:36 -05:00
Vijay Janapa Reddi
c4c64ebc9a fix(ci): use dev export --all for package builds instead of module complete
- _build_package now uses 'tito dev export --all' which properly:
  1. Converts src/*.py to modules/*.ipynb (jupytext)
  2. Exports to tinytorch/core/ (nbdev_export)

- Fixes issue where 'module complete --all' didn't iterate through modules
- Added CI streaming output for better visibility during builds
- Each CI stage that needs the package will build it independently
2026-01-23 15:00:34 -05:00
Vijay Janapa Reddi
a44e76131b fix(ci): inline tests must export notebooks before module complete
The inline tests were calling 'module complete' directly, but the notebook
doesn't exist until 'dev export' creates it from src/.

Now the flow is:
1. tito dev export <module>  - Creates notebook from src/
2. tito module complete <module> - Runs tests and exports to core/

This matches the proper progressive build workflow.
2026-01-23 14:55:15 -05:00
Vijay Janapa Reddi
7f01c24f09 feat: add 'tito system reset' command for pristine state reset
New command that resets TinyTorch to a clean state:
- Clears modules/ directory (all numbered module folders)
- Clears tinytorch/core/ (all .py except __init__.py)
- Optionally resets progress tracking (--keep-progress to skip)

Usage:
  tito system reset           # Interactive confirmation
  tito system reset --force   # Skip confirmation
  tito system reset --ci      # CI mode with exit codes
  tito system reset --keep-progress  # Keep completion history

This is useful for:
- Testing fresh install experience
- CI/CD pipeline resets
- Starting over with a clean slate
2026-01-23 14:54:07 -05:00
Vijay Janapa Reddi
03417e2101 fix(ci): use 'module complete --all' to fully build package before tests
The previous approach used 'dev export --all' which only exports notebooks
but doesn't run inline tests or copy code to tinytorch/core/.

Now uses 'module complete --all' which:
1. Exports notebooks from src/ to modules/
2. Runs inline tests in each module
3. Copies tested code to tinytorch/core/

This ensures 'from tinytorch import Tensor' works in unit tests.
2026-01-23 14:52:09 -05:00
Vijay Janapa Reddi
e7fc890842 fix(ci): proper exit codes and error counting in test output
Critical fixes:
1. bin/tito now uses sys.exit(main()) to propagate exit codes
   - Previously the exit code was discarded, causing CI to pass even on failures

2. Collection errors are now counted and displayed
   - 'ERROR tests/...' lines (collection failures) are now tracked
   - Summary shows 'X errors, Y failed, Z passed' for clarity

Without these fixes, CI stages could show green even when tests failed.
2026-01-23 14:51:26 -05:00
Vijay Janapa Reddi
eea7f690dc feat(tinytorch): single source of truth for version management
- install.sh now fetches version from GitHub tags API instead of hardcoding
- README.md badge uses dynamic shields.io GitHub tag filter
- Add release.sh script for version bumping and tagging workflow

Version is now managed solely in pyproject.toml. Other files read it at
runtime or via GitHub API, eliminating version drift across files.
2026-01-23 14:48:55 -05:00
Vijay Janapa Reddi
840eae5178 feat(ci): add verbose streaming output for all pytest-based tests
In CI mode, all test types (unit, CLI, integration, E2E, milestone) now show:
- Header with test type and path
- Per-test progress as they run (✓ PASSED / ✗ FAILED)
- Summary footer with counts

This makes CI logs much more informative - you can see exactly which tests
are running and their status in real-time.
2026-01-23 14:40:26 -05:00
Vijay Janapa Reddi
64444e41d3 Merge remote-tracking branch 'origin/dev' into feature/tinytorch 2026-01-23 14:31:09 -05:00
Vijay Janapa Reddi
e1880011ff feat(ci): add verbose per-module output for inline tests
In CI mode, inline tests now show:
- Header with total module count
- Per-module progress: [1/20] Module 01: tensor... ✓ PASSED
- Error details if a module fails
- Summary footer with result

This makes CI logs much more informative for debugging.
2026-01-23 14:21:17 -05:00
Didier Durand
72adaae229 [Doc]: fixing some typos (#1133) 2026-01-23 14:00:43 -05:00
Vijay Janapa Reddi
906e344ad4 feat(ci): comprehensive CI/CD testing infrastructure
- Rewrite tinytorch-ci.yml with parallel test jobs for each test type
- Add configure job that dynamically selects tests based on trigger:
  * Push to dev: quick (unit + cli)
  * Push to main: standard (unit + cli + integration + e2e)
  * PR: standard tests
  * workflow_call: all tests (pre-release gate)
  * Manual: any selected type
- Add summary job with detailed results table
- Fix publish workflow preflight_level → test_type input mismatch
- Add fresh-install-test.yml workflow for student experience simulation
- Add test-fresh-install.sh script (Docker-based clean environment test)

Test hierarchy from fast to comprehensive:
1. Unit + CLI (~1 min) - Fast feedback
2. Integration (~2 min) - Cross-module validation
3. E2E (~3 min) - User journey validation
4. Inline (~10 min) - Progressive module build from src/
5. Milestone (~5 min) - Historical ML recreations
6. Release (~20 min) - Destructive full validation
2026-01-23 13:47:32 -05:00
Vijay Janapa Reddi
71b754037a feat: apply stashed improvements after merge
Key improvements from local development:
- conftest.py: Add package export validation before tests run
- preflight.py: Stricter Tensor import check (fail if None)
- 06_autograd.py: Set requires_grad manually in tests (progressive disclosure)
- 08_training.py, 09_convolutions.py: Add enable_autograd() calls
- install.sh: Environment variable overrides for testing
- nbdev.py: Fix import path for DevExportCommand

Also syncs CI/publish workflows from origin/dev
2026-01-23 13:31:27 -05:00
Vijay Janapa Reddi
65f67c94e6 Merge origin/dev into feature/tinytorch
Resolve conflicts:
- .github/workflows/contributors/generate_main_readme.py: take dev's width_pct parameter
- .vscode/settings.json: keep worktree-specific orange Peacock color
2026-01-23 13:29:17 -05:00
Vijay Janapa Reddi
54f91331af fix(docs): replace non-existent tito src with tito dev export
The `tito src` command was never implemented. All documentation
references have been updated to use the correct commands:

- `tito src export` → `tito dev export`
- `tito src test` → `tito dev test`

Also removed 'src' from developer_commands list in main.py since
it doesn't exist as a registered command.
2026-01-23 13:21:34 -05:00
Vijay Janapa Reddi
8a39107461 docs(toc): add Developer Testing to TITO CLI Reference section
Add testing.md to both web and PDF table of contents.
2026-01-23 13:17:57 -05:00
Vijay Janapa Reddi
77ccc29877 docs(tito): update overview.md with new test commands
- Replace deprecated tito dev validate with tito dev test flags
- Add all test type commands to Developer Commands table
- Update Developer Workflow section with testing examples
- Add link to new Developer Testing Guide
2026-01-23 13:17:51 -05:00
Vijay Janapa Reddi
36dc99055f docs(tito): add comprehensive Developer Testing Guide
New testing.md documentation covers:
- Test hierarchy diagram (inline → unit → integration → e2e → milestone → release)
- Quick reference table for all test flags
- Detailed explanations of each test type
- Module-specific testing with --module flag
- CI/CD integration examples
- Test directory structure reference
- Common workflows for daily/feature/release development
- Troubleshooting section
2026-01-23 13:17:45 -05:00
Vijay Janapa Reddi
a8d6f1de55 refactor(cli): update dev command group for new test infrastructure
- Remove validate subcommand import and handler
- Update help text to show all new test flags
- Update DevTestCommand usage in __init__.py
2026-01-23 13:17:37 -05:00
Vijay Janapa Reddi
12af47b635 feat(cli): add unified tito dev test command
Introduces a comprehensive testing command with explicit test type flags:
- --inline: Progressive inline tests from src/ (nbgrader tests)
- --unit: Pytest unit tests
- --cli: CLI command tests
- --integration: Cross-module tests
- --e2e: End-to-end user journey tests
- --milestone: Historical milestone tests
- --all: Run all test types (except release)
- --release: Full destructive release validation
- --module N: Test specific module

Default behavior runs unit tests only.

This consolidates validate, provides clear test hierarchy, and
matches PyTorch's explicit, predictable interface philosophy.
2026-01-23 13:17:30 -05:00
Vijay Janapa Reddi
0ce0703c67 refactor(cli): remove standalone validate command
The validate command functionality has been consolidated into
`tito dev test --release` for a unified testing interface.

This follows the PyTorch philosophy: one clear way to do things.
2026-01-23 13:17:22 -05:00
Vijay Janapa Reddi
44e5822fbc fix(tests): correct MODULE_NUMBER and MODULE_NAME in all run_all_tests.py
Fixed copy-paste errors where MODULE metadata was incorrect:
- 01_tensor: 02 → 01
- 02_activations: 03 → 02
- 03_layers: 04 → 03
- 04_losses: Dense/Networks → Losses
- 05_dataloader: 09/Autograd → 05/DataLoader
- 06_autograd: XX → 06/Autograd
- 07_optimizers: 06/Spatial/CNN → 07/Optimizers
- 08_training: XX → 08/Training
- 09_convolutions: XX → 09/Convolutions
- 10_tokenization: XX → 10/Tokenization
- 11_embeddings: XX → 11/Embeddings
- 12_attention: XX → 12/Attention
- 13_transformers: XX → 13/Transformers
- 14_profiling: KV Caching → Profiling
- 15_quantization: Module 16 → Module 15
- 18_memoization: XX → 18/Memoization
2026-01-23 13:17:15 -05:00
Vijay Janapa Reddi
ea0919718c fix(tests): add guards for requires_grad usage in integration tests
test_autograd_integration() and test_loss_backward_integration() now
gracefully skip if requires_grad is not available (i.e., autograd
hasn't been enabled yet).

This prevents false failures when running integration tests before
Module 06 has been completed.
2026-01-23 13:17:04 -05:00
Vijay Janapa Reddi
41023a17ca fix(tests): remove misplaced autograd tests from 05_dataloader
test_autograd_core.py was incorrectly placed in the 05_dataloader test
directory. These tests belong in 06_autograd since they test autograd
functionality that doesn't exist until Module 06.

This was causing test failures when students ran tests progressively
through the modules (issues #1127, #1112).
2026-01-23 13:16:58 -05:00