Skip to content

[Relax] Return values a match_cast reads from a CUDA graph capture - #20485

Merged
tlopex merged 1 commit into
apache:mainfrom
akaashrp:fix/cuda-graph-match-cast-output
Sep 30, 2026
Merged

tlopex merged 1 commit into
apache:mainfrom
akaashrp:fix/cuda-graph-match-cast-output

Conversation

@akaashrp

Copy link
Copy Markdown
Contributor

RewriteCUDAGraph adds a lifted value to the capture function's outputs when a binding outside the region uses it. The planner does that for var, call, tuple and tuple_get_item bindings but never overrode the match_cast visitor, so a match_cast over a lifted value kept reading a var that no longer exists in the original function. Compiling Phi-3.5-vision for CUDA in MLC LLM hits this in the image embedding, where a static reshape is captured and then match_cast to the symbolic crop grid, and VM codegen fails with Var lv383 is not defined.

  1. Add a MatchCastNode visitor to the planner that marks the value as an output of the region that lifted it
  2. Add a test with a captured reshape followed by a match_cast and a launch that depends on it

RewriteCUDAGraph lifts static bindings into a capture function and adds
a lifted value to the function's outputs when a later binding outside the
region uses it. That bookkeeping ran for var, call, tuple and
tuple_get_item bindings but not for match_cast, which the planner left
to the base visitor. A match_cast over a lifted value therefore stayed in
the original function with its input undefined, and VM codegen failed
with "Var lv383 is not defined" when compiling Phi-3.5-vision's image
embedding for CUDA in MLC LLM.

Mark the value as a region output in a MatchCast visitor and add a test.
@tlopex
tlopex merged commit 2393db6 into apache:main Sep 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants