This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch tvmscript-ast-only-transpiler
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 518fe576762decaa2082448717a194ca4898911d
Author: Tianqi Chen <[email protected]>
AuthorDate: Mon Sep 21 22:16:52 2026 +0000

    [TVMScript] Reuse annotated primitive declarations in Relax
---
 python/tvm/relax/script/builder/v2.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/python/tvm/relax/script/builder/v2.py 
b/python/tvm/relax/script/builder/v2.py
index dfc0f31846..a449e66afc 100644
--- a/python/tvm/relax/script/builder/v2.py
+++ b/python/tvm/relax/script/builder/v2.py
@@ -859,8 +859,12 @@ def bind_(
     # Shared dtype constructors return anonymous primitive Vars. Reuse the
     # signature's canonical symbol for declarations, while named aliases and
     # computed primitive expressions retain ordinary Relax binding semantics.
-    if ty is None and not frame_value and _ir.is_prim_var(value) and not 
value.name:
-        return _TypeVarFrame.current().resolve(name, value.ty, span=name_span)
+    if not frame_value and _ir.is_prim_var(value) and not value.name:
+        # A matching explicit annotation still denotes the same declaration.
+        # Mismatches follow the existing native binding validation below.
+        ty = None if ty is None else _type(ty)
+        if ty is None or _ffi.structural_equal(ty, value.ty):
+            return _TypeVarFrame.current().resolve(name, value.ty, 
span=name_span)
     if isinstance(value, _TypeVarDecl):
         return _TypeVarFrame.current().resolve(name, value.ty, span=name_span)
     if frame_value:

Reply via email to