Repository navigation
fix(weight_loader): dispatch a whole-model cpu>/disk> target as offload (#6581) - #6582
Merged
Merged
Conversation
With a single root rule _subtree_targets returns only {"": target}, so
dispatch visited the children without a target and gave every leaf a
resident AlignDevicesHook: placement="cpu>accel:0" moved all weights onto
the accelerator and "disk>accel:0" failed placing meta tensors. Hand the
root target to the top-level children so they take the offload branch.
Fixes #6581
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Qubitium
marked this pull request as ready for review
December 1, 2026 03:38
This was referenced Dec 1, 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 #6581
Problem
WeightLoader.dispatchnever offloaded a whole-modelcpu>/disk>target. With one root rule,_subtree_targetsreturns only{"": target};visitthen walks the children with no target and gives each tensor-owning leaf a residentAlignDevicesHook(execution_device). DenseGPTQModel.load(..., placement="cpu>accel:0")therefore loaded every weight onto the accelerator, andplacement="disk>accel:0"raisedValueError: weight is on the meta deviceduring load.Change
When the root has a target (only reached when it is offloaded; a resident root returns early), give it to each top-level child, the same way
visitalready forwards a container's target to its children. The children then take the existing offload branch.flowchart TD A["dispatch: targets = {'': cpu>/disk> accel:0}"] --> B{"root offloaded"} B --> C["root AlignDevicesHook(io_same_device)"] C --> D["visit(top-level children)"] D -. "before: no child target" .-> X["leaf AlignDevicesHook(resident)<br/>cpu>: weights moved to accel<br/>disk>: ValueError on meta"] D -- "after: child inherits root target" --> E["attach_align_device_hook(offload=True, weights_map)"] E --> F["weights stay on CPU / in offload_dir, onloaded per forward"] style X fill:#f8d7da,stroke:#b02a37Test plan
Hardware: AMD Radeon AI PRO R9700 (gfx1201), ROCm 7.16, torch 2.16 dev (the code path is device-independent).
New tests in
tests/test_weight_loader.py:test_whole_model_disk_offload_dispatch_runs_on_cpu(disk>cpu, CPU only)test_whole_model_cpu_offload_keeps_weights_off_the_accelerator(cpu>cuda:0; asserts no parameter on the accelerator, allocator delta below a quarter of the parameter bytes, the layer executed on the accelerator, output equal to the reference)origin/mainValueError: weight is on the meta device;assert (14848 - 0) < (8960 // 4))tests/test_weight_loader.pytest_weight_loader.py test_offload_block_inputs.py test_layerwise_device_placement.py test_cpu_offload_device_map_tied_head_4866.py test_cpu_offload_tied_both_copies_4943.py test_offload_disk_container_5145.py test_loader.pyReal model,
GPTQModel.load(model, placement=..., dtype=float16)then greedygenerateof 8 tokens:cpu>accel:0cuda:0, 2100.2 MiB allocated after load, peak 2180.6 MiBmeta(CPU store), 0 MiB after load, peak 206.5 MiB; same tokens ("Paris.\n\n2. B.")disk>accel:0ValueErrorduring loadcpu>accel:0accel:0uvx [email protected] checkon the touched files: clean.Not covered here: a tied-embedding checkpoint with
disk>on the embedding still fails withKeyError: 'lm_head.weight'(the offload index stores only the de-duplicated tied name). That is a separate bug, tracked on its own.🤖 Generated with Claude Code