Skip to content

M9: gradient conformance and training primitives - #18

Merged
ausimian merged 1 commit into
mainfrom
m9-gradient-training
Apr 15, 2026
Merged

M9: gradient conformance and training primitives#18
ausimian merged 1 commit into
mainfrom
m9-gradient-training

Conversation

@ausimian

@ausimian ausimian commented Apr 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • Lifts indexed_add / indexed_put / gather off the via_binary fallback onto native mx::scatter_add / mx::scatter / mx::gather; grad through these ops no longer round-trips to Nx.BinaryBackend.
  • Adds grad-equivalence + finite-difference + curve-matching + training-memory-soak + opt-in MNIST convergence test tiers so a gradient on Emily is trustable.
  • Fixes a latent shape lie in the single-axis gather fast path that only surfaced once Nx.Defn.grad chained dot downstream of gather.
  • Scopes conv-pool training (window reductions) to a future M10; 1.0 release renumbered to M11.

See RELEASE.md for the full M9 entry and PLAN.md § M9 for scope.

Test plan

  • mix precommit — 1 doctest, 64 properties, 219 tests, 0 failures
  • mix test --only conformance — 16 tests, 0 failures (DistilBERT / Qwen3 / ViT / Whisper tiny-random unaffected by the gather shape-lie fix)
  • mix test --only training_full — 1 test, 0 failures; Axon MLP on MNIST converges to ~97% in 5 epochs under Emily.Compiler (~10 s wall time on Apple Silicon)
  • CI precommit green
  • CI conformance green

Lifts indexed_add/indexed_put/gather off the via_binary fallback onto
native mx::scatter_add / mx::scatter / mx::gather, and adds the test
scaffolding needed to trust a gradient on Emily.

Backend: shared apply_scatter/6 + index-split + updates-shape rewrap
helpers translate Nx's {N, rank} indices + {batch ++ non_indexed_dims}
updates into MLX's per-axis index arrays + {batch ++ per_axis_slot}
updates. The single-axis gather fast path now reshapes to out.shape —
fixes a latent shape lie that only surfaced when grad chains dot
downstream of gather.

Tests:
- grad_equivalence_test.exs: 8-property zoo (sum, dot, reshape∘transpose,
  broadcast, gather, indexed_add + two composition cases), each run
  under Emily.Compiler and Nx.Defn.Evaluator, plus a PRNG-key-threading
  test through a grad-computed dropout.
- finite_diff_test.exs + support/grad_helper.ex: 4-op numerical oracle
  with per-op tolerance tables.
- mlp_curve_test.exs + transformer_block_curve_test.exs +
  support/training_helper.ex: 50-step SGD curves matched per-step
  (rtol=1e-3, drift canary) and final-loss (rtol=1e-4, convergence).
- soak/training_test.exs: 1k training-step memory-stability soak.
- mnist_full_test.exs: opt-in `:training_full` MNIST Axon MLP →
  >97% test accuracy in 5 epochs under Emily.Compiler.

Docs: RELEASE.md updated; PLAN.md renumbered — M10 (conv-pool) and
M11 (1.0 release) follow.
@ausimian
ausimian merged commit f069be8 into main Apr 15, 2026
1 check passed
@ausimian
ausimian deleted the m9-gradient-training branch April 18, 2026 02:00
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.

1 participant