Repository navigation
fix(nf12): reuse a preloaded partial operator namespace (#3886) - #3910
Merged
Merged
Conversation
load() only accepted a preloaded torch.ops.nf12 when it exposed the full current operator set, including the newer row-major ops. A legacy or standalone NF12 library that owns the namespace with a usable embedding operator was therefore rejected, and the loader tried to JIT or load a second library. Without build tools that raised _MissingBuildTools before embedding_repeat4 could take its documented single-copy fallback, and with another library already registered a second TORCH_LIBRARY load risks a registration error. Treat any registered NF12 operator as ownership of the namespace: reuse it, and let callers name the operators they actually need through require() / has_ops() / available_ops(). A missing specific operator now raises a clear RuntimeError naming it instead of a generic build failure. Fixes #3886
Record how a partially registered torch.ops.nf12 is reused instead of rebuilt, the single-copy fallback that stays reachable, and the require/has_ops/available_ops contract.
This was referenced Nov 14, 2026
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.
Fixes #3886
Root cause
gptqmodel_nf12._library.load()only accepted a preloadedtorch.ops.nf12when it exposed the complete current operator set, including the newerrowmajor_pack/rowmajor_embedding. A legacy or standalone NF12 library that owns the namespace with a usableembeddingoperator was therefore rejected, and the loader attempted a JIT build or a secondtorch.ops.load_library.Consequences: without build tools,
_MissingBuildToolswas raised beforeembedding_repeat4could take its documented single-copy fallback; with another library already registered, a secondTORCH_LIBRARYload risks a registration error. The issue's test reproduces the first case:Fix
Treat any registered NF12 operator as ownership of the namespace and reuse it. Callers name the operators they actually need:
has_ops(*names)— pure predicate.require(*names)— reuse the namespace if the named ops exist, otherwise load/build and raise aRuntimeErrornaming exactly the missing operators.available_ops(*names)— capability probe for a subset;available()keeps its existing meaning (the full current set is usable).embedding_repeat4keeps its fallback: a legacy namespace withembeddingbut noembedding_repeat4uses the single-copy lookup and repeats in Torch.Flow
flowchart TD A["api call, e.g. embedding_repeat4"] --> B["load()"] B --> C{"any nf12 op registered?"} C -- Yes --> D["reuse the namespace, no build"] C -- No --> E{"complete current operator set?"} E -- Yes --> D E -- No --> F["JIT build or packaged library"] F --> G["torch.ops.load_library"] D --> H["caller uses the operators it needs"] G --> H H --> I{"required op present?"} I -- Yes --> OK["run"] I -- No --> R["RuntimeError naming the missing operator"] style R fill:#fee,stroke:#c00 style D fill:#dfd,stroke:#060embedding/decode_MissingBuildToolsRuntimeErrornaming itReference page:
docs/auto-nf12-dtype-cast.md#preloaded-operator-namespaces(existing page, linked fromREADME.md).Validation
pytest tests/test_gptqmodel_nf12_api.py -qpytest tests/test_gptqmodel_nf12_api.py tests/test_auto_dtype_cast.py -qon RTX 4090pytest "tests/test_gptqmodel_nf12_api.py::test_repeat4_uses_single_copy_from_preloaded_legacy_namespace" -qwithPATH=/usr/bin:/bin CUDA_HOME=/nonexistent, source stashed_MissingBuildTools(the issue repro)New tests also cover partial-namespace reuse without a build (
library_pathpatched to fail if called) andrequire()reporting only the missing operator.