Repository navigation
Eval forward: remove host syncs so it compiles as one graph - #73
Thunderblok wants to merge 3 commits into
Conversation
_canonical_eval_hidden checked int(n.max()) > seq_len on every call. Since n <= L, the check needs the data only when L > seq_len; for L <= seq_len it is now a shape-only branch (no device sync, no torch.compile graph break). The ACT early exit in the recurrent loop (`halted.all()`) was the other data-dependent break. It now runs only in eager mode; under torch.compile the fixed n_loops run. Skipped loops add weight 0, so outputs are unchanged. Eager outputs are bit-identical to before (checked for L = 1..400, left and right padding, and L > seq_len packed and raw paths). The eval forward now compiles with fullgraph=True and matches eager. The 2048-token canonical layout cost per call is unchanged; it is what makes eval match training. test_eval_compile.py fails on 7e4dd59 and passes here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RmsBBBg4SD8FZFAJnebLt9
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🔵 Needs a closer look
The change impacts torch.compile capture behavior (SymInt guards and ACT early-exit under compile), and the evidence indicates it still needs validation on the target backend/hardware to confirm single-graph fullgraph capture, avoid recompiles, and maintain acceptable performance.
No open issues 🎉
What changed in this PR
Updates the eval/generation forward path to eliminate host sync–triggered torch.compile(fullgraph=True) graph breaks so eval can compile as a single graph in the common case.
Changes:
- Refactors canonical eval length handling to keep the
L <= seq_lenpath shape-only (no device→host sync), preserving the data-dependent check forL > seq_len. - Disables ACT’s data-dependent early-exit during compilation to avoid graph breaks, while keeping eager-mode behavior.
- Adds a regression test that compiles eval forward with
fullgraph=Trueand checks compiled vs eager equivalence, including coverage for the raw-layout long-row path.
| File | Description |
|---|---|
| test_eval_compile.py | Adds unit coverage that compiles the eval forward with fullgraph=True and asserts compiled outputs match eager, including a L > seq_len raw-layout regression check. |
| helix_lm/recurrent.py | Gates ACT’s halted.all() early-exit so it only runs in eager mode, preventing a data-dependent graph break when the eval forward is compiled. |
| helix_lm/hf_model.py | Adjusts canonical eval length logic to avoid host-syncing length checks for the common L <= seq_len case while retaining the data-dependent fallback for L > seq_len. |
Review effort: Balanced
Verdict: technically sound, ship it, but not into 72Both graph breaks are real; I saw Tensor.item() at hf_model.py:361 in the log myself, and the halted.all() sync is the same class of defect. The reasoning for each fix is correct: The training path is untouched, and the run has generated_example_length=0 — it never generates. There is literally nothing for this PR to improve in the job that is queued right now. Three things I'd want before merge(a) "0 graph breaks" ≠ "0 recompiles." The branch still specialises on L ≤ T vs L > T, and generation grows L one token at a time (1, 2, 3 … T). That's a shape guard firing per length. Count them with TORCH_LOGS=recompiles over a 100-token generation — if it thrashes, the fix has traded a sync for a recompile storm, which is worse. If so, torch._dynamo.mark_dynamic(input_ids, 1) is the usual remedy. One expectation to setThis removes per-step syncs and recompiles; it does not reduce the per-call cost of the canonical 2048-token layout the PR says so, and it's the right call. So generative throughput will barely move. If the on-device story is the goal, the KV cache is still the item that matters, and this PR is a prerequisite for it rather than a substitute. |
|
TLDR: hold it. Merge after the run, not before. It cannot improve the training, and it can only add risk to a job that hasn't started yet. The timing fact that decides it: the queued job hasn't been placed — 31m so far — and the launcher downloads the branch when the container starts, not when you submitted. So merging 73 into 72 right now wouldn't be a neutral act; it would silently change what the queued job pulls and records as its
Why "it can't affect training" isn't a good enough reason to merge now: that sentence is precisely the shape of every bug in this project. "Training always uses autocast, so bf16 can't matter." "The config is fine, save_pretrained can't fail." Both were true until they weren't. The difference here is that I can afford to be wrong — the fix is pure performance, so the run loses nothing by not having it. What I'd do:
If you'd rather merge now anyway, the safe sequence is: cancel the queued job first, merge, then submit a 2-minute startup-only run (imports, token check, bf16 gate, one optimizer step) to prove 73 doesn't break anything, then fire the real run. That costs the queue position and buys the provenance — but it buys nothing for the model. |
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
The workflow step in .github/workflows/python-app.yml has a critical command-continuation error where a trailing backslash on the final unittest line causes the subsequent python pretrain_data_court.py line to be appended to the unittest invocation, breaking the CI step until the backslash is removed.
1 open issue
Review effort: Balanced
Added a new test for evaluating graph equivalence to the CI workflow.
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🔵 Needs a closer look
A hidden review note indicates the test’s determinism setup is potentially misleading because torch.manual_seed(1) may be overridden by model construction auto-seeding, coupling generated ids to internal initialization behavior and warranting human scrutiny before approval.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
All checks pass. Note this branch is 1 bug fix behind branch #72 so the integration plan:
|

Follow-up to the
int(n.max())graph break you found in_canonical_eval_hidden.Changes
hf_model.py:n <= Lalways holds, so the length check needs data only whenL > seq_len. ForL <= seq_len(every generation step inside the training context), it is now a shape-only branch: no device sync and no graph break. The data-dependent check stays for the rareL > seq_lencase.recurrent.py: the ACT early exit (halted.all()) was a second data-dependent graph break in the eval forward. It now runs in eager mode only (not torch.compiler.is_compiling()). Under compile, the fixedn_loopsrun. Loops after all tokens halt add weight 0, so the output does not change.test_eval_compile.py: compiles the eval forward withfullgraph=Trueand checks it against eager. Also checks the raw-layout path for rows longer thanseq_len. This test fails on 7e4dd59 and passes here.Checks
L > seq_lenon both the packed and the raw paths.torch._dynamo.explainreports 0 graph breaks on the eval forward. Before this change: 2 (Tensor.item(), thenhalted.all()).Not changed
🤖 Generated with Claude Code