You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/07/14 08:02:09 UTC
[PR] [IR][Relax][TIRx] Consolidate canonical Var unification cleanup [tvm]
tqchen opened a new pull request, #20004:
URL: https://github.com/apache/tvm/pull/20004
This PR consolidates canonical Var unification into two reviewed foundation commits followed by focused append-only corrections.
### Design
- Use one canonical `Var` identity across IR, Relax, and TIRx, with a checked typed primitive view rather than competing object identities.
- Preserve the narrow Relax semantic boundaries required by that identity: dependent-type traversal, conservative shape-only canonicalization, and marker-free primitive binding syntax.
- Use the public Python `.name` contract consistently while retaining the internal C++ `name_hint` field.
- Make VM shape lowering use-driven: binding definition roots do not create demand, `slot_map_` is the rewrite/capture oracle, and exact signed-int64 compound use roots are captured without restoring a def-side classifier.
### Commit structure
1. `87fca83a2a7e9bc19e78178274308fd1db5f929d` — use one canonical Var identity across IR, Relax, and TIRx.
2. `539ce1809b112f26835c8e2eb19cbadd952bc12e` — preserve the minimal Relax semantic boundaries required by that identity.
The remaining commits are focused corrections for typed primitive containers, dependent substitution, conservative canonicalization, parser/printer behavior, canonical Python naming, and use-driven VM shape demand.
### Validation
- Shape lowering plus lazy parameter transformation: 30/30 passed.
- All 30 changed Python test files: 845 passed, 134 skipped, 7 xfailed.
- CTest: 122/122 passed.
- Complete Python suite: 8,873 passed, 6,863 skipped, 56 xfailed, 5 xpassed, and 147 established environment/upstream failures. An exact pre-correction `c1679641` source/library rerun reproduced the identical 147-node set with no final-only failure.
- Independent shape probes preserved every unchanged-demand serialization, expected scalar-demand deltas, scheduling order, dead-root exclusion, and type/DataflowVar/MatchCast/If boundaries. Direct `return n + 1` now lowers and builds successfully.
- Exact history, changed-range naming, compiler build, diff, and touched-line formatting audits pass.
No new shape or review-only test case was added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [IR][Relax][TIRx] Consolidate canonical Var unification cleanup [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on code in PR #20004:
URL: https://github.com/apache/tvm/pull/20004#discussion_r3577334433
##########
python/tvm/relax/script/parser/parser.py:
##########
@@ -168,30 +213,25 @@ def is_recursive(node: doc.FunctionDef) -> bool:
def collect_symbolic_var_from_prelude(
- self: Parser, node: doc.FunctionDef, symbolic_vars: dict[str, tirx.Var]
-) -> dict[str, tirx.Var]:
+ self: Parser, node: doc.FunctionDef, symbolic_vars: dict[str, tvm.ir.Var]
+) -> dict[str, tvm.ir.Var]:
prelude_vars = {}
for stmt in node.body:
- if isinstance(stmt, doc.Assign) and all(
- isinstance(target, doc.Name) and target.id in symbolic_vars for target in stmt.targets
- ):
- values = self.eval_expr(stmt.value)
-
- try:
- iter(values)
- except TypeError:
- values = [values]
-
- assert len(stmt.targets) == len(values)
- for target, value in zip(stmt.targets, values):
- name = target.id
- prelude_vars[name] = value
+ if isinstance(stmt, doc.Assign) and len(stmt.targets) == 1:
+ declarations = collect_symbolic_var_declaration_nodes(stmt.targets[0], stmt.value)
+ for name, value_node in declarations.items():
+ if name not in symbolic_vars:
+ continue
+ declared_var = self.eval_expr(value_node)
+ if tvm.ir.is_prim_var(declared_var) and declared_var.ty == symbolic_vars[name].ty:
Review Comment:
Thanks for flagging this. I verified the behavior directly: this Python expression is not pointer equality. `tvm.ir.Type.__eq__` calls `tvm_ffi.structural_equal`, and `PrimType.__eq__` delegates to it for non-string operands. As a stronger check, I constructed two `int64` Var types on separate OS threads, bypassing the thread-local PrimType cache: `lhs.ty.same_as(rhs.ty)` was `False`, while `lhs.ty == rhs.ty` and `structural_equal(lhs.ty, rhs.ty)` were both `True`; `int64 == int32` was `False`. Both runtime operands were `tvm.ir.PrimType`. Therefore the existing comparison already has the intended structural semantics; replacing it with an explicit `structural_equal` call would be behavior-equivalent, so I kept the parser unchanged. At exact updated head `b79d07391687`, the focused parser/type/ExprFunctor gate passes 25/25.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [IR][Relax][TIRx] Unify Var identity [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #20004:
URL: https://github.com/apache/tvm/pull/20004
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [IR][Relax][TIRx] Consolidate canonical Var unification cleanup [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #20004:
URL: https://github.com/apache/tvm/pull/20004#discussion_r3577104361
##########
python/tvm/relax/script/parser/parser.py:
##########
@@ -168,30 +213,25 @@ def is_recursive(node: doc.FunctionDef) -> bool:
def collect_symbolic_var_from_prelude(
- self: Parser, node: doc.FunctionDef, symbolic_vars: dict[str, tirx.Var]
-) -> dict[str, tirx.Var]:
+ self: Parser, node: doc.FunctionDef, symbolic_vars: dict[str, tvm.ir.Var]
+) -> dict[str, tvm.ir.Var]:
prelude_vars = {}
for stmt in node.body:
- if isinstance(stmt, doc.Assign) and all(
- isinstance(target, doc.Name) and target.id in symbolic_vars for target in stmt.targets
- ):
- values = self.eval_expr(stmt.value)
-
- try:
- iter(values)
- except TypeError:
- values = [values]
-
- assert len(stmt.targets) == len(values)
- for target, value in zip(stmt.targets, values):
- name = target.id
- prelude_vars[name] = value
+ if isinstance(stmt, doc.Assign) and len(stmt.targets) == 1:
+ declarations = collect_symbolic_var_declaration_nodes(stmt.targets[0], stmt.value)
+ for name, value_node in declarations.items():
+ if name not in symbolic_vars:
+ continue
+ declared_var = self.eval_expr(value_node)
+ if tvm.ir.is_prim_var(declared_var) and declared_var.ty == symbolic_vars[name].ty:
Review Comment:

Comparing `tvm.ir.Type` instances using `==` checks for pointer/reference equality rather than structural equality. Since `declared_var.ty` and `symbolic_vars[name].ty` are constructed independently, they will be different instances of `PrimType` (even if they both represent `int64`), causing this check to always evaluate to `False`. Use `tvm_ffi.structural_equal` to perform a proper structural comparison.
```suggestion
if tvm.ir.is_prim_var(declared_var) and tvm_ffi.structural_equal(declared_var.ty, symbolic_vars[name].ty):
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org