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

tqchen pushed a commit to branch fix-tvm-ffi-bump-relax-slots
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/fix-tvm-ffi-bump-relax-slots 
by this push:
     new 3f4383f325 [IR] Use conditional moves for function attributes
3f4383f325 is described below

commit 3f4383f325eb11fe8db400b7e0fa4432ad5102cd
Author: tqchen <[email protected]>
AuthorDate: Fri Jul 17 11:46:12 2026 +0000

    [IR] Use conditional moves for function attributes
---
 3rdparty/tvm-ffi          |  2 +-
 python/tvm/ir/function.py | 15 ++++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/3rdparty/tvm-ffi b/3rdparty/tvm-ffi
index 21e30c3b1d..195b618955 160000
--- a/3rdparty/tvm-ffi
+++ b/3rdparty/tvm-ffi
@@ -1 +1 @@
-Subproject commit 21e30c3b1d4421f95fd69a6ba3fd0285c7b69e9c
+Subproject commit 195b6189557a6b380a2eb005b996eeb32fe243a7
diff --git a/python/tvm/ir/function.py b/python/tvm/ir/function.py
index abf7d37372..1041c52cfa 100644
--- a/python/tvm/ir/function.py
+++ b/python/tvm/ir/function.py
@@ -62,19 +62,20 @@ class BaseFunc(Expr):
         func : BaseFunc
             A new copy of the function
         """
-        # Pass an lvalue so that the RValueRef argument takes its own strong
-        # reference.  tvm-ffi ties a C++ object to one canonical Python 
wrapper,
-        # so BaseFuncCopy(self) may return self; moving that wrapper would also
-        # invalidate the caller's original function.
-        res = self
+        # Make a logical copy for copy-on-write.  tvm-ffi may return the same
+        # canonical Python wrapper, so move only when it has no other Python
+        # references; otherwise the RValueRef parameter takes an lvalue copy.
+        res = _ffi_api.BaseFuncCopy(self)
 
         if isinstance(attr_key_or_dict, dict):
             for key, val in attr_key_or_dict.items():
-                res = _ffi_api.BaseFuncWithAttr(res, key, 
tvm.runtime.convert(val))
+                res = _ffi_api.BaseFuncWithAttr(
+                    res._move_if_unique(), key, tvm.runtime.convert(val)
+                )
             return res
 
         return _ffi_api.BaseFuncWithAttr(
-            res, attr_key_or_dict, tvm.runtime.convert(attr_value)
+            res._move_if_unique(), attr_key_or_dict, 
tvm.runtime.convert(attr_value)
         )
 
     def with_attrs(self, attr_map: DictAttrs | dict[str, Object]) -> 
"BaseFunc":

Reply via email to