Keep large subcall tapes in heap memory #3949
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 367 lines diff across 4 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.353
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #3949"
general
weight: 0.35
vchuravy
<!-- claude-projects-attribution: {"github_login":"vchuravy"} -->
_Requested by Valentin · project thread_
The augmented forward pass returns the tape of a non-recursive callee by value, and that tape is nested by value into the tape of every enclosing call. In MITgcm's
offline_exf_seaice,augmented_forward_step_ended up returning a struct with ~69.6k scalar fields (8 levels of nesting). That is more than the 65535 operands a SelectionDAG node can hold, sollcasserts; other configurations stall optimizing the resultinginsertvaluechains.With
-enzyme-max-tape-fields=N, a tape with more than N scalar fields (struct leaves, array and fixed-vector elements counted) is kept in heap memory, the way the tape of a recursive function already is:CreateAugmentedPrimaltreats such a tape like a recursive one: it is allocated withCreateAllocationand the augmented function returns the pointer.forceAnonymousTape, which loads and frees it. The tape is never loaded into SSA in the caller. ForwardModeSplit keeps the existing load.__enzyme_augmentfwd/__enzyme_reversewithenzyme_allocated) stores the pointer in that memory, and the reverse is requested with an anonymous tape. This dropsassert(!aug->tapeType), which also fired for recursive functions there.Because the limit applies per tape, every tape that is still returned by value has at most N scalar fields. The default, -1, never moves a tape to the heap, so behavior is unchanged unless the flag is set. MITgcm used N = 1024.
This is independent of #3280, which passes already-heap (recursive) tapes by pointer above a configurable threshold. Both touch the same block in
AdjointGenerator.h, so whichever lands second needs a small rebase.For Enzyme.jl, such a tape is reported like a recursive one (underlying tape type set, i.e.
EnzymeTapeToLoad).Testing
test/Enzyme/ReverseMode/largetape.ll: with-enzyme-max-tape-fields=1024, a 1280-scalar tape in a loop goes through the heap, a small tape is still returned by value, plus top-level split mode;llichecks the derivative values. A third RUN line checks that without the flag the tape is returned by value.test/Enzyme): all pass exceptReverseMode/cache_for_reverse_arg.ll, which also fails on main.offline_exf_seaice(full LTO, with the local study fixes): builds in 10 min (Enzyme opt 36 → 7 min, llc no longer asserts). The gradient matches TAF exactly for the default andthsiceinputs;obcsis 7.5e-3 from TAF and 1.9e-4 from finite differences.🤖 Generated with Claude Code