Skip to content

Add C training driver plus worked MNIST example (closes #44) - #56

Merged
w4ffl35 merged 1 commit into
masterfrom
fix/nir-train-driver
Oct 14, 2026
Merged

w4ffl35 merged 1 commit into
masterfrom
fix/nir-train-driver

Conversation

@w4ffl35

@w4ffl35 w4ffl35 commented Oct 14, 2026

Copy link
Copy Markdown
Member

Closes #44.

Driver (driver.h/driver.c/driver_loop.c): nir_driver_t wires the merged pieces with zero Python at train time — IDX (data.h), repeat/rate encoding (encode.h), tape forward/backward (tape.h), minibatch mean reduction (minibatch.h), SGD/Adam steps (train.h) with LR schedules (schedule.h), and v2 checkpoints with optimizer resume (checkpoint.h). Per-node accumulators plus one optimizer instance per weight/bias buffer; seeded shuffle/encode streams; step counter persisted as checkpoint meta step.

Example (examples/mnist_train + mnist_tiny_graph.json): 4-step LI network (Flatten 4→Affine 8→LI 8→Affine 10) trains the committed 2×2 3-sample fixture for 20 Adam epochs, printing loss/accuracy per epoch and saving a v2 checkpoint. Deterministic from seed 7: initial 2.387/0.000 → epoch 20 1.163/0.667, step 40.

Acceptance:

  • Example builds via CMake and runs on committed fixtures only (graph + tiny IDX, no downloads).
  • Loss decreases: test asserts 20-epoch eval beats init by 0.5 (observed 1.22).
  • README Training section documents the flow; no Python required at train time.

Tests:

  • test_driver: decrease bound, bit-identical checkpoint resume with matching step, SGD/rate/schedule smoke, error paths.
  • mnist_train_example ctest runs the binary; CI also runs it with PATH=/nonexistent to prove no Python dependency.
  • Local: 45/45 ctest green in Debug, Release, and ASan/UBSan, warning-clean (-Wall -Wextra -Werror).

Docs: README Scope marks #39-#47 done; train.h stale tape comment refreshed. No changes to merged tape/minibatch/checkpoint/backward modules.

driver.h/driver.c/driver_loop.c: nir_driver_t wires IDX loading, repeat/rate encoding, tape forward/backward, minibatch mean reduction, SGD/Adam steps with LR schedules, and checkpoint save/load with optimizer resume. Per-node accumulators and optimizer instances, seeded shuffle/encode streams, step counter persisted as checkpoint meta step.

examples/mnist_train plus mnist_tiny_graph.json: 4-step LI network (Flatten 4->Affine 8->LI 8->Affine 10) trains the committed 2x2 3-sample fixture for 20 Adam epochs, printing loss/accuracy per epoch and saving a v2 checkpoint. Deterministic from seed 7: 2.39/0.000 to 1.16/0.667, step 40.

Tests: test_driver asserts 20-epoch loss beats init by 0.5, checkpoint resume is bit-identical with matching step, SGD/rate/schedule smoke paths run finite, and config/data error paths fail cleanly. mnist_train_example runs the binary via ctest; CI also runs it with PATH=/nonexistent to prove zero Python at train time.

Docs: README Training section with flow diagram, example invocation, expected output, and zero-Python proof; Scope marks tape/backward/minibatch/checkpoint/init/schedule/loss/driver done. train.h comment refresh for tape/driver.
@w4ffl35
w4ffl35 merged commit fad15e9 into master Oct 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

End-to-end C training driver plus worked MNIST example (zero Python at train time)

1 participant