Skip to content
This repository was archived by the owner on Jul 17, 2026. It is now read-only.

tests: pin full-fp32 matmuls in the torch↔JAX goldens (GPU TF32 trap)#970

Open
claude-spd1 wants to merge 1 commit into
bridge/task-regen-residual-fed-goldensfrom
bridge/task-pin-golden-matmul-precision
Open

tests: pin full-fp32 matmuls in the torch↔JAX goldens (GPU TF32 trap)#970
claude-spd1 wants to merge 1 commit into
bridge/task-regen-residual-fed-goldensfrom
bridge/task-pin-golden-matmul-precision

Conversation

@claude-spd1

Copy link
Copy Markdown
Collaborator

Description

Stacked on #936 (base is its branch; will retarget to feature/jax when it merges). Two changes:

  1. Pin jax.default_matmul_precision("highest") in every fp32-golden test harnesstests/equivalence, tests/stacked_parity, and tests/simple_mlp_equivalence (same fp32-golden class, same trap), as an autouse fixture per module, plus the same pin in jax_equivalence.py main() (the CLI path). Test-scope only: train numerics stay bf16 by design, and the bf16 imp-min seam test is deliberately not pinned.
  2. vendored_jax.llama.attn_implementation now dispatches on dtype. cuDNN flash attention rejects fp32, so the fp32 goldens previously could not run on GPU at all — every numeric test crashed with NotImplementedError on H100. bf16/fp16 keep cuDNN (production path unchanged); fp32 takes the XLA composite. Without this, the precision pin is unreachable on GPU.

Related Issue

Compile-audit finding M6 (board task pin-golden-matmul-precision, promoted from the 2026-07-10 JAX compile audit).

Motivation and Context

XLA's f32 matmul default on GPU tensor cores is TF32 (~1e-3 rel). The goldens are the only remaining torch↔JAX parity oracle (torch is retired at tag torch-oracle) and assert fp32 tolerances. CPU-only CI never sees the difference — "highest" is already the CPU default — but a GPU dev-box run does. #936 removes the _PENDING_REGEN xfail that currently masks this, so the pin should land with/right after it.

Measured on H100 against the committed goldens (per-term rel err, RTOL 2e-4):

term default (TF32) pinned
faith 1.8e-5 0
imp 0 0
stoch 4.1e-5 6.1e-8
ppgd 1.4e-4 8.0e-8

Unpinned, TF32 noise alone eats 70% of ppgd's tolerance budget — that's the "real port bug written off as TF32 noise" masquerade the audit flagged. Pinned, headroom is four orders of magnitude.

How Has This Been Tested?

  • CPU: all three suites — 17 passed, 1 xfailed (the still-pending trajectory golden), identical before/after (the pin is a CPU no-op).
  • GPU (H100, 1×, via SLURM): before this PR — 11 of 18 tests fail (cuDNN fp32 crash); after — 17 passed, 1 xfailed, matching CPU exactly.
  • basedpyright and ruff clean.

Does this PR introduce a breaking change?

No. Production numerics untouched: the bf16 attention path still uses cuDNN; the dtype dispatch only enables the previously-crashing fp32 GPU path.

Crew-Address: task/pin-golden-matmul-precision

🤖 Generated with Claude Code

XLA's f32 matmul default on GPU tensor cores is TF32 (~1e-3 rel). The
equivalence/parity goldens assert fp32 tolerances (RTOL 2e-4 / 1e-4, abs
1e-5), so an unpinned GPU run burns most of the tolerance budget on
precision noise: measured on H100, the ppgd term sits at rel 1.4e-4 of
its 2e-4 RTOL under TF32 vs 8e-8 pinned — room for a real port bug to
masquerade as TF32 noise (compile-audit finding M6). CPU CI never sees
this ("highest" is already the CPU default), which is why it stayed
latent.

- autouse `jax.default_matmul_precision("highest")` fixture in
  tests/equivalence, tests/stacked_parity, and
  tests/simple_mlp_equivalence (all three assert fp32 goldens); the same
  pin in jax_equivalence.main(), the CLI path. Test-scope only: train
  numerics stay bf16 by design, and the bf16 imp-min seam test is
  deliberately not pinned.
- vendored_jax: `attn_implementation` dispatches on dtype — cuDNN flash
  attention rejects fp32, so the fp32 goldens previously could not run
  on GPU at all (NotImplementedError on H100). bf16/fp16 keep cuDNN;
  fp32 takes the XLA composite. Dispatch-only; the production bf16 path
  is unchanged.

Verified on H100: all three suites 17 passed / 1 xfailed (identical to
CPU), per-term golden rel err ≤ 8e-8 pinned vs up to 1.4e-4 unpinned.

Crew-Address: task/pin-golden-matmul-precision
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant