Skip to content

fix: post-#6473 regressions (Trainer in a GPT-QModel process, late-import Accelerate dispatch, stale guards) - #6499

Draft
Qubitium wants to merge 1 commit into
mainfrom
wl-post-refactor-fixes
Draft

Qubitium wants to merge 1 commit into
mainfrom
wl-post-refactor-fixes

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Follow-up to #6473 / #6494 (tracking: #6471). It comes from re-auditing the accelerate removal for completeness and regressions.

Regressions fixed

  1. transformers.Trainer broke in any process that imports gptqmodel, even with Accelerate installed (TrainingArguments raised "requires accelerate"). This also broke the PEFT fine-tuning workflow in docs/peft.md.
    • Cause: _accelerate_isolation patched is_accelerate_available for all of Transformers.
    • Fix: a scoped import hook executes only transformers.trainer and transformers.training_args with the real flag.
    • Weight loading, placement, generate, load_adapter (integrations.peft) and the quantizers stay isolated. from_pretrained(device_map=...) still raises after the Trainer is imported (pinned by the test).
  2. Late-import Accelerate dispatch. A plain-Transformers script that does not import gptqmodel first gets past Transformers' device_map check, because Optimum imports gptqmodel only inside the GPTQ quantizer. Accelerate then dispatched the model, and the HF bridge mishandled Accelerate's hooks: it only understands weight_loader hooks, so disk-offloaded layers raised and CPU-offloaded Marlin layers were treated as resident.
    • Fix: hf_gptqmodel_post_init now refuses Accelerate-owned hooks with a clear message pointing to GPTQModel.load(placement=...). This applies "strict everywhere" regardless of import order.
  3. OSTQuant's lazy-checkpoint-shell guard still read owner.turtle_model, so it never fired. It now reads checkpoint_source.
  4. Three unchanged tests regressed (they pass on aff56aa1a):

Cleanup

  • utils/offload.py: remove the preexisting-hook take/restore plumbing; its setter was removed in Delete the dead hook-based offload machinery (#6471) #6494, so it was always a no-op.
  • weight_loader/plan.py: remove the unreferenced _split_dim_cache_key.
  • Docs, comments and strings that still described Accelerate dispatch or LazyTurtle names: weight-loader.md, peft.md, hf-interop.md §6, loader-quantized-redirect.md, fp8-save-offload.md, calibration-replay.md, tenstorrent.md, the isolation docstring, bridge comments in utils/model.py, the importer.py docstring, and the logger.py region label.
  • Kept on purpose: the max_memory remedy string in importer.py, because test_default_device_mixed_capability_4705.py asserts on it.
flowchart TD
    A[import gptqmodel] --> B[is_accelerate_available = False for Transformers]
    B --> C{module being imported}
    C -- transformers.trainer / training_args --> D[exec with real flag: Trainer gets Accelerator]
    C -- modeling_utils / generation / integrations.accelerate / peft / quantizers --> E[isolated: device_map raises, hooks = weight_loader]
    F[plain Transformers, gptqmodel imported late by Optimum] --> G[Accelerate dispatches]
    G --> H[hf_gptqmodel_post_init]
    H --> I[ValueError: use GPTQModel.load placement=]
Loading

Validation (targeted only)

  • Red/green: the new tests fail on main and pass here:
    • test_accelerate_isolation.py::test_transformers_trainer_still_trains_in_a_gptqmodel_process[gptqmodel_first|trainer_first]
    • test_hf_bridge_refuses_accelerate_dispatch.py
    • test_ostquant_config.py::test_ostquant_refuses_a_lazy_checkpoint_shell
  • A/B over 198 unchanged test files covering loading, offload, checkpoint, bridge, device and GGUF (CPU, per file, run on aff56aa1a, main and this branch):
    • main had 3 regressions against aff56aa1a;
    • this branch has 0 files worse than aff56aa1a.
  • Isolation, unpatched-Transformers and bridge tests: 15 passed. Offload, undo and bridge tests show the same failure set as main (environmental: no AVX512-BF16, no optimum).
  • The ruff gate passes.

Also measured (no change needed)

🤖 Generated with Claude Code

…mport Accelerate dispatch, stale guards

Regressions found by re-auditing the accelerate removal (#6471):

- Importing gptqmodel hid Accelerate from all of Transformers, so
  `TrainingArguments`/`Trainer` raised "requires accelerate" even with it
  installed (PEFT fine-tuning of GPT-QModel models broke). The isolation now
  executes only `transformers.trainer` / `transformers.training_args` with the
  real flag via a scoped import hook; loading, placement, generation and
  `load_adapter` stay isolated.
- A plain-Transformers load that imports gptqmodel late (Optimum imports it
  inside the GPTQ quantizer, after `device_map` was accepted) got dispatched by
  Accelerate and then half-initialized by the bridge, which only understands
  weight_loader hooks. `hf_gptqmodel_post_init` now refuses Accelerate hooks
  with a pointer to `GPTQModel.load(placement=...)` (strict everywhere).
- OSTQuant's lazy-shell guard still read `turtle_model`; it never fired.
- Three unchanged tests still used LazyTurtle's private interface or a
  deleted test file.

Cleanup: dead preexisting-hook plumbing in utils/offload.py (its setter went
in #6494), unused `_split_dim_cache_key`, and stale docs/comments that still
described Accelerate dispatch or LazyTurtle names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant