Repository navigation
fix: scope Accelerate isolation to GPT-QModel calls; restore HF/Optimum/PEFT compat - #6501
Merged
Merged
Conversation
…um/PEFT compat #6499 hid Accelerate from all of Transformers once gptqmodel was imported. Optimum and PEFT drive GPT-QModel kernels through plain Transformers with Accelerate placing the model, so that broke `device_map` loads of GPTQ/AWQ checkpoints (AWQ failed even without a device_map: its quantizer requires Accelerate) and refused Accelerate-dispatched models in the bridge. - Isolation is now a ContextVar scope entered by GPT-QModel's entry points (GPTQModel.load/from_pretrained/from_quantized/quantize_mlx, BaseQModel quantize/generate/save/serve). Inside: is_accelerate_available() is False, modeling_utils uses weight_loader helpers, generate builds weight_loader hooks. Outside: Transformers is upstream (real flag and Accelerate bindings). - add_hook_to_module dispatches by hook type (weight_loader hook -> ours, anything else -> Accelerate's). - A Transformers module first imported inside the scope executes unscoped, so its import-time Accelerate bindings match an ordinary import. - The HF bridge accepts Accelerate's hooks and weights maps again (`_hook_types`), replacing the #6499 refusal. - Dense loads with a `cpu>`/`disk>` placement: the materialization check no longer rejects the offload hooks' meta placeholders, and an offloaded block gets an input hook so kwargs consumed outside its leaves (Llama `position_embeddings`) reach the execution device. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
November 30, 2026 19:37
This was referenced Dec 1, 2026
Merged
Merged
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.
Follow-up to #6499 (tracking: #6471). Per maintainer decision: GPT-QModel's own paths stay Accelerate-free, while plain Transformers / Optimum / PEFT keep upstream Accelerate behavior, because Optimum and PEFT drive GPT-QModel kernels for GPTQ/AWQ training.
Problem (on current
main)PEFT LoRA training matrix (Llama-3.2-1B GPTQ + AWQ-Llama-3.2-1B-g128-gemm, 12 steps, save/reload adapter):
mainGPTQModel.load(backend=trainable)device_map="auto", gptqmodel imported firstdevice_map="auto", Optimum imports gptqmodel latedevice_map, gptqmodel imported firstEvery scenario trains: loss drops from 0.63/0.69 to 0.10–0.19, LoRA weights change and the base
qweightstays frozen. The 6-scenario AWQ results match the pre-#6473 tree.Change
_accelerate_isolationis now aContextVarscope entered by GPT-QModel's entry points:GPTQModel.load/from_pretrained/from_quantized/quantize_mlxandBaseQModel.quantize/generate/save/serve.is_accelerate_available() == False,modeling_utilsuses theweight_loaderhelpers, andgeneratebuildsweight_loaderhooks.add_hook_to_modulehands aweight_loaderhook to GPT-QModel and any other hook to Accelerate._hook_types), replacing fix: post-#6473 regressions (Trainer in a GPT-QModel process, late-import Accelerate dispatch, stale guards) #6499's refusal. Accelerate is never imported by this check.cpu>/disk>dense loads (found while tracing; broken onmainsince Remove accelerate: explicit WeightLoader for weight loading, placement and offload (#6471) #6473):position_embeddingsfailed with "Expected all tensors to be on the same device".weight-loader.md(new "Accelerate scope" section with a mermaid flow) andhf-interop.md§6. The fix: post-#6473 regressions (Trainer in a GPT-QModel process, late-import Accelerate dispatch, stale guards) #6499 strict-contract edits are reverted inpeft.md(the plain-Transformers flow is supported again) andtenstorrent.md.flowchart TD A[call into Transformers] --> B{inside a GPT-QModel entry point?} B -- yes --> C[is_accelerate_available False; weight_loader hooks; no device_map] B -- no --> D[upstream: real flag, Accelerate dispatch] D --> E[HF bridge accepts Accelerate or weight_loader hooks] F[add_hook_to_module] --> G{hook type} G -- weight_loader --> H[GPT-QModel] G -- other --> I[Accelerate]Validation (targeted)
accelerate.*from outside Accelerate during load, generate and save, with Accelerate installed. It found 0 calls for:cpu>accel:1layers (its output matches the single-GPU load);mainand pass here:test_accelerate_isolation.py(scope, hook-type dispatch, lazily imported module bindings, plain-HF GPTQdevice_mapload with gptqmodel imported first, Trainer);test_hf_bridge_accelerate_hooks.py::test_accelerate_offload_hook_is_recognized;test_offload_block_inputs.py(1 and 2 GPU).mainover the weight-loader, placement, dispatch, offload, isolation, HF bridge and loader suites: 418 passed on this branch, and the 4 failures are identical onmain. Those are the Marlin JIT build, which can't build in this environment, plus twotest_hf_bridge_cpu_offload_5022cases that also fail before Remove accelerate: explicit WeightLoader for weight loading, placement and offload (#6471) #6473.Note: Transformers imports Accelerate at startup again when it is installed, as upstream does. GPT-QModel itself still neither depends on nor calls it.
🤖 Generated with Claude Code