Repository navigation
[compiler] Preserve expression bindings when coalescing device variables - #4749
Merged
Merged
Conversation
choijon5
force-pushed
the
choijon5/helion-b200/shared/1
branch
from
November 26, 2026 16:22
a0ca54e to
3d5fd78
Compare
This was referenced Nov 26, 2026
Coalescing an outer variable could change 2 * 3 to 7 * 3 in a closed lambda, or turn an outer 7 into a local 2. The same name can appear as both a bound and a free read in a single generated device expression. Keep lambda arguments and comprehension targets local. Defaults and the first iterable use their defining scope. For a real free-to-bound collision, rename the comprehension target or give the lambda a getter so it retains its keyword arguments and observes later outer assignments. Plain code takes one iterative walk; closed callback shapes stay intact. Helion templates may splice the same AST node twice. Detach affected expression occurrences before changing outer names, preserve source metadata and FX-owned argument lists, and process replacements without recursing into either the scoped body or an unrelated deep expression. This is an internal expression transform. The kernel's own variables still coalesce; outlined named functions explicitly rewrite their own formals before passing their body to this pass. Use the returned value for a bare lambda, which may need a wrapper. Testing: scripts/run_tests.py passed 351 focused CuTe CPU tests (2 skipped), 40 Triton CPU, 37 Metal CPU (3 skipped), and the full local Pallas interpreter module (269 passed, 44 skipped). These include 13 direct regressions, cross-scope templates, immutable FX arguments and 1,500 nested operators inside and beside a callback. Four of six initial semantic cases failed on main; the first expression-scope correction passed 344 CuTe, 33 Triton, 30 Metal and 269 Pallas, with the same skips. A device-denied SDK 4.8.1 compile of the corrected callback and a direct late load emitted identical complete SM100a ELF and instructions. ./lint.sh check on the three touched files, including Pyrefly, passed. No physical GPU lane was run in this standalone check. Integrated validation before the direct-ConfigSpec target lookup and shared test-loader changes: scripts/run_tests.py passed the CuTe lanes (26,206 CPU, 16,138 GPU on B200 3/5), the full Triton lanes (4,900 CPU, 3,395 GPU on B200 6), and the Pallas interpreter suite (269 passed, 44 skipped). CuTe used nightly Torch and CuTe DSL 4.8.1; Triton used CI Torch 2.14.1/Triton 3.8. The production compiler was identical in these runs. The Triton run includes a later test-only fix to isolate the fake SM103 target from real devices, also checked with the affected test module on CuTe and Triton. autoreview passed: claude, codex stack-info: PR: #4749, branch: choijon5/helion-b200/shared/1
choijon5
marked this pull request as draft
November 26, 2026 17:02
choijon5
force-pushed
the
choijon5/helion-b200/shared/1
branch
from
November 26, 2026 17:03
3d5fd78 to
8500749
Compare
choijon5
marked this pull request as ready for review
November 26, 2026 17:04
jansel
approved these changes
Nov 27, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked PRs:
[compiler] Preserve expression bindings when coalescing device variables
Coalescing an outer variable could change 2 * 3 to 7 * 3 in a closed
lambda, or turn an outer 7 into a local 2. The same name can appear as
both a bound and a free read in a single generated device expression.
Keep lambda arguments and comprehension targets local. Defaults and
the first iterable use their defining scope. For a real free-to-bound
collision, rename the comprehension target or give the lambda a getter
so it retains its keyword arguments and observes later outer assignments.
Plain code takes one iterative walk; closed callback shapes stay intact.
Helion templates may splice the same AST node twice. Detach affected
expression occurrences before changing outer names, preserve source
metadata and FX-owned argument lists, and process replacements without
recursing into either the scoped body or an unrelated deep expression.
This is an internal expression transform. The kernel's own variables
still coalesce; outlined named functions explicitly rewrite their own
formals before passing their body to this pass. Use the returned value
for a bare lambda, which may need a wrapper.
Testing: scripts/run_tests.py passed 351 focused CuTe CPU tests (2
skipped), 40 Triton CPU, 37 Metal CPU (3 skipped), and the full local
Pallas interpreter module (269 passed, 44 skipped). These include 13
direct regressions, cross-scope templates, immutable FX arguments and
1,500 nested operators inside and beside a callback. Four of six initial
semantic cases failed on main; the first expression-scope correction
passed 344 CuTe, 33 Triton, 30 Metal and 269 Pallas, with the same skips.
A device-denied SDK 4.8.1 compile of the corrected callback and a direct
late load emitted identical complete SM100a ELF and instructions.
./lint.sh check on the three touched files, including Pyrefly, passed.
No physical GPU lane was run in this standalone check.
Integrated validation before the direct-ConfigSpec target lookup and
shared test-loader changes: scripts/run_tests.py passed the CuTe lanes
(26,206 CPU, 16,138 GPU on B200 3/5), the full Triton lanes
(4,900 CPU, 3,395 GPU on B200 6), and the Pallas interpreter suite
(269 passed, 44 skipped). CuTe used nightly Torch and CuTe DSL 4.8.1;
Triton used CI Torch 2.14.1/Triton 3.8. The production compiler was
identical in these runs. The Triton run includes a later test-only
fix to isolate the fake SM103 target from real devices, also checked
with the affected test module on CuTe and Triton.
autoreview passed: claude, codex