Skip to content

Delete the dead hook-based offload machinery (#6471) - #6494

Merged
Qubitium merged 1 commit into
mainfrom
wl-offload-cleanup
Nov 30, 2026
Merged

Qubitium merged 1 commit into
mainfrom
wl-offload-cleanup

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Follow-up to #6473, for #6471.

After #6473, offload_to_disk is file-backed and checkpoint resume loads artifacts with load_state_dict(assign=True). That leaves the hook-based offload machinery in utils/offload.py unreachable. This PR deletes it: 8 files, +232 / −640. utils/offload.py goes from 1,973 to about 1,500 lines.

What is removed (dead by call graph)

Computed from every name the rest of gptqmodel/ imports from utils/offload.py, following references inside the file:

  • _snapshot_preexisting_hooks
  • _prepare_offload_directory, _write_offload_index, _bundle_module_state_dict
  • _qzero_layout_for_module, _bundle_qzero_layout, _qzeros_format_buffer, _convert_bundle_qzeros
  • _LiveQzeroWeightsMap, _iter_offload_hooks, _install_live_qzero_restore
  • offload_to_safetensors_reference, attach_disk_offload_hook

What stays, and why

Kept Why
undo_offload_to_disk, restore_disk_offloaded_modules, materialize_disk_offloaded_module placement= with disk>accel:N targets still installs offload hooks at inference time
Writer offload-reference resolution and export preflight writer.py builds OffloadTensorRef itself, so these are live

Tests

Checked separately: saving into the source directory

Quantized Llama-3.2-1B, whose embed_tokens is source-backed (a view of the source model.safetensors), then save() into that same directory:

  • the save completes;
  • the live embedding is unchanged;
  • the reload generates correctly.

The writer's temp-file plus atomic-rename leaves the mapped inode intact, so there is no SIGBUS and no corruption on Linux.

Docs

The following are updated to describe file-backed resume and source-backed modules:

  • in-session-model-after-offload.md
  • gptq-qzero-runtime-layout.md
  • offload-run-directories.md
  • safetensors-reference-offload.md

🤖 Generated with Claude Code

After #6473 offload_to_disk is file-backed and resume loads artifacts with
load_state_dict(assign=True), so nothing in the library reaches these anymore
(call graph from every name the rest of gptqmodel/ imports):
_snapshot_preexisting_hooks, _prepare_offload_directory, _write_offload_index,
_bundle_module_state_dict, _qzero_layout_for_module, _bundle_qzero_layout,
_qzeros_format_buffer, _convert_bundle_qzeros, _LiveQzeroWeightsMap,
_iter_offload_hooks, _install_live_qzero_restore, offload_to_safetensors_reference,
attach_disk_offload_hook (utils/offload.py 1973 -> ~1500 lines).

Kept: undo_offload_to_disk / restore_disk_offloaded_modules /
materialize_disk_offloaded_module (placement disk> targets still install offload
hooks), and the writer's offload-reference resolution (writer.py builds
OffloadTensorRef itself).

Tests: offload_to_safetensors_reference moves to tests/offload_test_utils.py as a
fixture builder for the writer's reference-resolution and export-preflight tests;
the four tests of that helper's own validation are dropped; #4777 now drives the
real resume path (artifact load_state_dict(assign=True) + non-persistent scratch)
instead of attach_disk_offload_hook. Docs describe the file-backed resume and
source-backed modules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread tests/offload_test_utils.py Resolved
@Qubitium
Qubitium marked this pull request as ready for review November 30, 2026 11:09
@Qubitium
Qubitium merged commit e4314ff into main Nov 30, 2026
6 checks passed
@Qubitium
Qubitium deleted the wl-offload-cleanup branch November 30, 2026 11:09
Qubitium added a commit that referenced this pull request Nov 30, 2026
DEVICE.to_device_map() and p2p.accelerator_devices_from_device_map() have
no callers since GPT-QModel stopped consuming device maps (#6471). Also
document the intentional pass in the offload test fixture (code-quality
review on #6494).

Co-authored-by: Claude Opus 5.5 <[email protected]>
Qubitium added a commit that referenced this pull request Nov 30, 2026
…mport Accelerate dispatch, stale guards (#6499)

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 <[email protected]>
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