Keep loop-local gradients out of the while remover's carried values #4021
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.35) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 168 lines diff across 2 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.307
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4021"
general
weight: 0.35
wsmoses
Fixes EnzymeAD/Reactant.jl#3842.
WhileOpEnzymeOpsRemoveris meant to skip gradients created inside the loop body, but the check tested the shadowing loop variableop(theenzyme.set) instead of the while, soop->isProperAncestor(initOp)was always false. Such a gradient then became a loop-carried value: anenzyme.getwas hoisted before the loop, where itsenzyme.initdoes not dominate.Since #3971, the reverse body of a checkpointed loop creates these gradients. Most are simplified away before the while remover runs, but one updated inside a
stablehlo.ifsurvives. That is what happens with the OceananigansSplitRungeKutta3model in the issue when the trip count is not a multiple of the checkpoint period.The fix skips loop-local gradients in two places: when collecting the values to carry across iterations, and when hoisting gets out of the body.
Testing:
while_local_gradient_removal.mlirfails with the issue's dominance error without the fix.@code_hloand run through the default raise-first pipeline, now compiles forNt = 5.Nt = 4still compiles.diffrules/{stablehlo,enzymexla},removeandwhilelit tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01DHpsQ6Q1tXwBWWzLEFkpS3