[Relax][PyTorch] Bind symbolic scalar inputs in from_fx#19964
[Relax][PyTorch] Bind symbolic scalar inputs in from_fx#19964guan404ming wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request enables symbolic shape variables lifted by Dynamo as scalar graph inputs to be bound to matching shape variables, allowing operations like view that reference them to resolve correctly. A test case is added to verify this behavior. The feedback recommends explicitly importing tirx locally to prevent potential runtime errors from fragile transitive imports.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| sym_vars = { | ||
| v.name: v for shape, _ in input_info for v in shape if isinstance(v, tvm.tirx.Var) | ||
| } |
There was a problem hiding this comment.
Relying on transitive imports for submodules (like tvm.tirx) can be fragile and may lead to AttributeError if the import structure of other modules changes. It is safer and more robust to explicitly import tirx locally within the function.
from tvm import tirx
sym_vars = {
v.name: v for shape, _ in input_info for v in shape if isinstance(v, tirx.Var)
}cc2e639 to
abc639b
Compare
With torch.compile(dynamic=True), dynamo lifts SymInt scalars (e.g. a symbolic batch size) as scalar graph inputs. from_fx skipped these placeholders entirely, so any op referencing one directly, such as view(x.size(0), -1), failed with KeyError during translation. Bind such placeholders to the tir.Var of the same name already created for the input tensors' symbolic shapes, so references resolve the same way sym_size.int results do. Placeholders with no matching shape var are still skipped as before.
abc639b to
5347983
Compare
Why
torch.compile(backend=relax_dynamo(), dynamic=True)lifts SymInt scalars as scalar graph inputsfrom_fxskips these placeholders, so ops referencing one, e.g.view(x.size(0), -1), fail withKeyErrorHow
tir.Varfrom the input tensors' symbolic shapes; skip as before when none existstest_relax_dynamo_dynamic_sym_input_reference; fails withKeyErrorwithout the fix