This repository was archived by the owner on Jul 17, 2026. It is now read-only.
perf(llama8b): batch weight_deltas per kind (224 site matmul groups → 7)#973
Open
claude-spd1 wants to merge 2 commits into
Open
perf(llama8b): batch weight_deltas per kind (224 site matmul groups → 7)#973claude-spd1 wants to merge 2 commits into
claude-spd1 wants to merge 2 commits into
Conversation
llama8b's weight_deltas Python-looped over all 224 sites emitting a
per-site fp32 W − (V@U).T matmul group into the loss graph (train step
faith term + faith-warmup step). Per-kind dims are uniform across layers
(already asserted by _per_kind_dims — the scan forward's precondition)
and the frozen weights are already layer-stacked, so compute one batched
fp32 matmul per KIND and return {kind: [n_sites, d_out, d_in]} stacks
(rows layer-ascending; per_kind_delta_index maps site → (kind, row)).
SPEC N2/S17 pin the math (fp32 deltas, global mean of squared entries),
not the grouping: faithfulness_loss was already grouping-agnostic, its
annotation and the DecomposedModel.weight_deltas contract now say so.
Toy targets and llama_simple_mlp keep per-site returns (a valid
grouping; their site counts are small).
Parity (test_weight_deltas_match_per_site_reference, 3 site sets incl.
heterogeneous C and a partial layer range): per-site delta values and
V/U faithfulness grads BIT-IDENTICAL to the per-site loop; the loss
scalar differs only by fp32 summation regrouping (224 → 7 partial sums,
rtol 1e-6) and feeds no gradient, so trajectories are unchanged.
Isolated-region compile A/B (faith-warmup step AOT at production 8B
shapes, 224 sites, CPU backend): optimized-HLO dots 672 → 21, lines
41590 → 27506.
Crew-Address: task/batch-weight-deltas-per-kind
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…ackward The faith reduce's backward needs the deltas (grad = 2Δ/N); with per-kind stacked weight_deltas XLA stored every [n_sites, d_out, d_in] fp32 stack from forward to backward — +3.3GiB/rank static temp measured at dp32 vs the per-site loop. jax.checkpoint at the two faith call sites (train step + faith warmup) recomputes them in the backward instead: one matmul per kind, numerics identical (SPEC N2/S17 unchanged). Crew-Address: task/batch-weight-deltas-per-kind Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
llama8b.weight_deltasPython-looped over all 224 sites, emitting a per-site fp32W − (V@U).Tmatmul group into the loss graph (train-step faith term + faith-warmup step). Per-kind dims are uniform across layers (already asserted by_per_kind_dims) and the frozen weights are layer-stacked, so it now computes one batched fp32 matmul per kind and returns{kind: [n_sites, d_out, d_in]}stacks (rows layer-ascending;per_kind_delta_indexmaps site → (kind, row)).SPEC N2/S17 pin the math (fp32 deltas, global mean of squared entries), not the grouping:
faithfulness_losswas already grouping-agnostic; its annotation and theDecomposedModel.weight_deltascontract now say so. Toys andllama_simple_mlpkeep per-site returns (valid grouping, small site counts).Second commit:
jax.checkpointat the two faith call sites — the loss reduce's backward needs the deltas (grad = 2Δ/N), and without remat XLA stores every per-kind stack from forward to backward (measured +3.3GiB/rank static temp at dp32). With remat they're recomputed (one matmul per kind) and the change is memory-neutral.Motivation and Context
2026-07-10 JAX compile audit finding M4 (ledger: lore
2026-07-10--jax-compile-audit-remaining-findings); bridge taskbatch-weight-deltas-per-kind.Measurements
Isolated region (faith-warmup step AOT at production 8B shapes/224 sites, CPU backend): optimized-HLO dots 672 → 21, lines 41590 → 27506 (−34%).
GPU A/B at production dp32 (full32L PROFILE config +
profile.mem_profile, isolated compile caches; old arm =eb786f7d9):jit(step)compilejit(step)compile time is flat within noise — consistent with the repo's prior "compile is ~83% priority-fusion, flat across graph structure" finding. The win is the graph itself (651 fewer matmul groups + 224→7 dict entries in this region), not the dp32 step-compile wall clock; the warmup-step graph shrinks the same way. (The A/B runs OOM in the 2-real-step phase ofmem_profilein both arms — pre-existing for this config on H100-80GB, arm-independent.)Step-time impact should be nil (the faith term is a negligible fraction of step FLOPs; remat adds 7 matmuls to the backward) but was not measurable in this config for the same OOM reason.
How Has This Been Tested?
test_weight_deltas_match_per_site_reference(3 site sets: all kinds × all layers, partial MLP layer range, heterogeneous per-site C): per-site delta values and V/U faithfulness grads bit-identical to the per-site loop; loss scalar differs only by fp32 summation regrouping (224 → 7 partial sums; feeds no gradient, so trajectories are unchanged).test_llama8b.py,stacked_parity,test_generic_model_io.py,test_eval.py,test_llama_simple_mlp.pygreen;make checkclean.Does this PR introduce a breaking change?
weight_deltasconsumers that indexed by site name must go throughper_kind_delta_index(in-tree: two test files, updated here). The engine seam (faithfulness_loss) is unchanged.Crew-Address: task/batch-weight-deltas-per-kind
🤖 Generated with Claude Code