Repository navigation
fix(marlin): refresh CPU offload snapshot after post-init - #3452
Merged
Merged
Conversation
ZX-ModelCloud
marked this pull request as ready for review
October 27, 2026 13:06
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
…5046) Plain `transformers`/Optimum loading of a GPT-QModel GPTQ/RTN or AWQ-GEMM checkpoint with a map that offloads layers to CPU failed at load time, although `GPTQModel.load` serves the same maps since #4890: * GPTQ/RTN: `RuntimeError: CPU-offloaded Marlin requires a writable in-memory weights map.` * AWQ-GEMM: `ValueError: AWQ Marlin requires CUDA tensors, got 'meta'.` Two independent causes. 1. The bridge never told the selector about the offload. `from_quantized` derives `cpu_offload` from the map and passes it to `select_quant_linear`, so AUTO skips a kernel whose `post_init` needs CUDA. The HF entry points did not: `hf_select_quant_linear`, `hf_select_quant_linear_v2` (Transformers' GPTQ quantizer, Optimum's `GPTQQuantizer.convert_model`, and AWQ's `replace_with_awq_linear`) and the native bridge's `make_quant` all selected `MarlinLinear`/`AwqMarlinLinear` for an offloading map. The check now lives in `utils.importer.device_map_uses_cpu` (the native loader's `_device_map_uses_cpu` delegates to it) and `auto_cpu_offload`, which narrows it to AUTO so an explicit `backend="marlin"` stays the caller's choice. 2. `_post_init_cpu_offloaded_marlin` accepted only a plain `dict` or a `PrefixedDataset` over a `dict`. Transformers dispatches through Accelerate, which attaches `AlignDevicesHook(weights_map=PrefixedDataset(OffloadedWeightsLoader(...)))`, so the #3452 path could never run from a real `from_pretrained`. `_cpu_offload_writable_storage` unwraps the prefix and writes through the loader's in-memory `state_dict`, refusing only entries that live in its disk `index` (same message, now naming the disk-backed keys). `AwqMarlinLinear` shares the post-init: it repacks into the Marlin layout too, and before this it ran `post_init` on `meta`.
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.
Problem
Closes #1499.
With a mixed
device_map, Accelerate snapshots an offloaded GPTQ Marlin layer's weights before Marlin runspost_init(). Marlin then emptiesg_idxwhendesc_act=Falseand repacksqweightandscales. The first forward tries to restore the older snapshot into the new tensor shapes and raises a shape error.Fix
For a CPU-offloaded Marlin layer,
gptqmodel_post_init()now uses the layer's existing Accelerate hook to materialize its weights, runspost_init(), and replaces the hook's CPU snapshot with the resulting packed quantized tensors. The layer returns tometaafterward, so later forwards load the post-init layout. This works with a directAlignDevicesHookor one inside aSequentialHook. A layer whose weights are already resident still runspost_init()directly.Validation
mainon the firstpre_forward(): the savedqweightis[32, 128], while Marlin's post-init placeholder is[16, 256]. The same reproduction succeeds with this change.desc_actvalues and both hook forms. Two consecutive reloads match a separately initialized, never-offloaded Marlin layer tensor for tensor, and parameters return tometaafter each reload.