Reuse ABI-compatible JIT extension caches across Python/torch envs - #3043
Merged
Conversation
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Collaborator
Author
|
Review follow-up (H100-only test environment):
Validation:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JIT extension cache fingerprints hash the exact Python version (
python=3.12.9) and exact torch wheel version unconditionally, so every Python or torch env change forces a full recompile — even though allTorchOpsJitExtensionbinaries are loaded viatorch.ops.load_library(is_python_module=False) and most have no CPython ABI dependence. This PR makes fingerprints reflect actual ABI requirements so compiled extensions are reused wherever the binary is genuinely compatible.What Changed
gptqmodel/utils/cpp.py:TorchOpsJitExtensiongainspython_abi_dependent/torch_stable_abi_targetparams. Python-ABI detection (defaultNone= auto-detect by scanning sources + recursively resolved local includes) is deliberately conservative:Python.h/pybind11/*/torch/extension.h/torch/python.hincludes and anyPy[A-Z]*/py::/PYBIND11_*usage flag the extension as python-dependent; audited torch.ops-only loaders (pack_block, floatx, awq, qqq, exllamav2 gptq+awq, exllamav3, machete, marlin fp16+bf16, paroquant, hadamard) set explicitpython_abi_dependent=False(only unused registration macros / incidental includes, no runtime Python usage in compiled TUs).torch_stable_abi_target=(major, minor). When set, the class injects-DTORCH_TARGET_VERSIONinto both host cflags and NVCC flags (so the two floors can't drift), fingerprints astorch_abi=stable-{major}.{minor}, validates the scanned sources (onlytorch/csrc/stable//torch/headeronly/torch headers are stable;ATen/,c10/,caffe2/and othertorch/headers raise aRuntimeErrornaming the offending include), and enforces the runtime floor itself:load()refuses to reuse a cached binary or compile when the running torch is below the target. Sources that auto-detect as stable but have no explicit target stay keyed to the current torch build.extra_include_pathsentry; unresolvable angle includes are treated as system headers and skipped._torch_cpu_cache_version()): only+cpu,+cuNNN,+rocmX.Y,+xpuare stripped; source/vendor local identifiers (e.g.+gitabc1234) are preserved so different libtorch builds never collide in the cache.torch_stable_abi_target_define(major, minor)→-DTORCH_TARGET_VERSION=0x020A000000000000(libtorch encoding: major<<56 | minor<<48).gptqmodel/utils/swordfish.py: swordfish (written against the torch stable ABI) is pinned viatorch_stable_abi_target=(2, 10). 2.10 is the audited floor:torch_get_current_cuda_blas_handle(used bylibtorch_stable/torch_utils.h) is gated atTORCH_VERSION_2_10_0intorch/csrc/stable/c/shim.h; no swordfish API needs 2.11+._swordfish_static_runtime_error()also gates torch < 2.10 with an explicit error so expected incompatibility never enters JIT compilation.+cpu/+cu12x/+rocm*/+xpuwheels of the same torch version; python-agnostic extensions share caches across Python versions (including free-threaded); swordfish shares caches across torch versions >= 2.10 and refuses cached-binary reuse below the floor.Tests
New tests in
tests/test_torch_ops_jit_extension.pycover: python-agnostic fingerprint stability across Python versions, SOABI keying (incl. free-threaded fallback), conservative python-ABI marker detection, wheel-switch normalization (+cpu↔+cu128/+rocm6.2/+xpureuse;+gitabc1234preserved), stable-target fingerprinting + define injection into both flag sets, explicit-stable-target rejection of non-stable headers, runtime floor refusal on torch 2.9 with target 2.10 (no cache lookup), angle-bracket include resolution (ABI detection + fingerprint invalidation + system-include skip), swordfish torch<2.10 gate, and theTORCH_TARGET_VERSIONencoding.Review Requirements
Notes
TORCH_TARGET_VERSION=0x020A000000000000confirms the required declarations are visible at the 2.10 floor. A real build/load on torch >= 2.10 + Blackwell is recommended before relying on cross-torch swordfish reuse.Link to Devin session: https://app.devin.ai/sessions/b1d3f556711a4711b7b82bd732c66de5
Open in Devin Desktop: https://app.devin.ai/desktop/session/b1d3f556711a4711b7b82bd732c66de5?variant=devin
Requested by: @Qubitium