This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new 11cba7d7 [FIX] Invalidate Torch addon cache when generator changes
(#915)
11cba7d7 is described below
commit 11cba7d743d1af966b5b25356275ab458802b6a6
Author: Lei Wang <[email protected]>
AuthorDate: Wed Nov 4 20:09:48 2026 +0800
[FIX] Invalidate Torch addon cache when generator changes (#915)
The JIT cache for the Torch C DLPack addon is keyed by the Torch build,
device, and C++ ABI, but does not include the packaged generator.
Updating `_build_optional_torch_c_dlpack.py` can therefore reuse a
previously compiled addon and leave changes to its C++ code or build
logic unapplied.
Include the first eight hex digits of the generator's SHA-256 in the
cached library name. A changed generator selects a new cache entry and
recompiles the addon; identical contents continue to reuse the cached
binary. This lets addon fixes take effect after an FFI upgrade without
manually clearing the cache.
The native Torch and externally installed addon paths keep their
existing behavior. Old cache files are retained, and the first JIT load
with the new naming scheme rebuilds the addon once.
---
python/tvm_ffi/_optional_torch_c_dlpack.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/python/tvm_ffi/_optional_torch_c_dlpack.py
b/python/tvm_ffi/_optional_torch_c_dlpack.py
index b50cc8bf..3a0a4c5b 100644
--- a/python/tvm_ffi/_optional_torch_c_dlpack.py
+++ b/python/tvm_ffi/_optional_torch_c_dlpack.py
@@ -145,13 +145,15 @@ def load_torch_c_dlpack_extension() -> Any: # noqa:
PLR0912, PLR0915
# addon -> crashes or wrong tensor data instead of a clean rebuild.
abi_id =
f"{torch.__version__}|cxx11abi={int(torch.compiled_with_cxx11_abi())}"
abi_tag = hashlib.sha256(abi_id.encode()).hexdigest()[:8]
- libname =
f"libtorch_c_dlpack_addon_torch{major}{minor}-{device}-{abi_tag}{suffix}"
+ build_script_path = Path(__file__).parent / "utils" /
"_build_optional_torch_c_dlpack.py"
+ # Rebuild when the generator changes, even if the Torch build is
unchanged.
+ source_tag =
hashlib.sha256(build_script_path.read_bytes()).hexdigest()[:8]
+ libname = (
+
f"libtorch_c_dlpack_addon_torch{major}{minor}-{device}-{abi_tag}-{source_tag}{suffix}"
+ )
lib_path = addon_output_dir / libname
if not lib_path.exists():
logger.debug("JIT-compiling torch-c-dlpack-ext to cache...")
- build_script_path = (
- Path(__file__).parent / "utils" /
"_build_optional_torch_c_dlpack.py"
- )
args = [
sys.executable,
str(build_script_path),