Add vmap reset() regression test for nnx.metrics (#5483) #5491
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 268 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.335
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5491"
general
weight: 0.35
samanklesaria
What does this PR do?
This adds a regression test for the
nnx.metricsbehavior reported in #5483.nnx.metrics.Average.reset()(andWelford.reset()) re-zero their state by assigning a scalar (jnp.array(0, ...)). When a metric is built undernnx.vmap, its state carries a leading batch axis of shape(N,). On the reporter's versions (flax 0.12.0 / jax 0.7.2) the scalar assignment replaced the whole array, collapsing(N,)to(), so a later vmappedupdatefailed with:ValueError: vmap was requested to map its argument along axis 0, which implies that its rank should be at least 1, but is only 0 (its shape is ())
While investigating I found the crash no longer reproduces on
main: theVariablestate layer has since changed so a full-index assignment broadcasts a scalar into the existing array in place instead of replacing it, soreset()preserves the batch axis today. I confirmed it still reproduces on flax 0.12.0 / jax 0.7.2 and is gone onmainindependent of any single commit.Since there is no longer a live crash to fix on
main, this PR is scoped as a regression test only, to lock in the current vmapreset()behavior so it can't silently break again.What's in this PR
tests/nnx/metrics_test.py—test_vmap_reset_preserves_shape: construct aMultiMetric(loss=Average('loss'))undernnx.vmap(state shape(N,)), callreset(), assert the state stays shape(N,), then run a vmappedupdateand assertcompute()['loss']returns the expected per-batch values.Checklist