You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] PanGu-alpha GPTQ always crashes at the last layer on the real checkpoint: #4109's top-query replay hook uses ln_f (still meta under lazy load) and wqe (left on CPU) - NotImplementedError / device mismatch #5135
Found on main @ 7b8f127, RTX 4090, with the real pangu_alpha_2_6B checkpoint (all 32 layers). Also present at 3867c82af.
What is wrong
PanguAlphaQModel.prepare_layer_replay_kwargs (models/definitions/pangu_alpha.py:91-125, added by #4109 for #4093 item 5) replays the top-query block. It runs transformer.ln_f on the layer input and calls transformer.wqe(position_ids) for custom_query. It assumes both non-layer modules are resident on the layer's device. On a real quantize run neither is:
Default config (lazy load / offload_to_disk=True), and device="cpu":ln_f is still a meta placeholder when the last layer is replayed, so move_to(norm, device=...) at line 101 raises:
File ".../models/definitions/pangu_alpha.py", line 101, in prepare_layer_replay_kwargs
NotImplementedError: Cannot move a module that still contains meta tensors without offload hooks. Materialize it first before calling move_to().
offload_to_disk=False:ln_f is materialized, but wqe stays on CPU while position_ids.to(target_device) is on cuda:0:
File ".../models/definitions/pangu_alpha.py", line 121, in prepare_layer_replay_kwargs
RuntimeError: Expected all tensors to be on the same device, but got index is on cuda:0, different from other tensors on cpu (when checking argument in method wrapper_CUDA__index_select)
So GPTQ quantization of PanGu-α always crashes at the last layer (layer 31 of 32), after every other layer has been quantized. The crash happens in all three configurations above, with padded or unpadded calibration.
Repro
importtorchfromgptqmodelimportGPTQModelfromgptqmodel.quantization.configimportGPTQConfig, CalibrationConfigg=torch.Generator().manual_seed(0)
calib= [{"input_ids": torch.randint(10, 40000, (1, 128), generator=g),
"attention_mask": torch.ones(1, 128, dtype=torch.long)} for_inrange(16)]
m=GPTQModel.load("pangu_alpha_2_6B", quantize_config=GPTQConfig(bits=4, group_size=128),
trust_remote_code=True, dtype=torch.float16)
m.quantize(CalibrationConfig(dataset=calib, batch_size=1))
# ... MemDiag: layer=31 ... NotImplementedError: Cannot move a module that still contains meta tensors ...
(The same happens on a 2-layer truncation at layer 1, which is the quick way to reproduce.)
Why the tests pass
tests/test_pangu_alpha_replay.py drives the hook either with a hand-built nn.Module double or with a tiny 4-layer model from tests/tiny_remote_models.build_tiny_remote_model. That model is fully resident on CPU, so ln_f/wqe are never meta or on another device. No test runs the hook through a lazily loaded model or on a GPU.
Suggested fix
Materialize ln_f and wqe through the same path the looper uses for other non-layer modules (the turtle/offload materializer). Or compute custom_query and the ln_f output once during input capture, when HF's own forward already runs them on the right device, and store them in the last layer's replay kwargs. At minimum, move wqe to target_device before the lookup (or move position_ids to wqe's device and the result to target_device). Extend the end-to-end PanGu test to quantize with GPTQModel.load(...) on CUDA with the default offload, so the lazy shell is exercised.
Severity: high for PanGu-α. GPTQ quantization cannot complete on the real checkpoint (see also #5134: the layers before the crash are all RTN fallbacks).
PanGu last-layer replay now materializes/relocates ln_f and wqe through the offload helpers; 2-layer GPTQ completes in lazy, disk-offload and resident configs.
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-4e3a0639ecaffinished this issue.Pull request: #5169
PanGu last-layer replay now materializes/relocates ln_f and wqe through the offload helpers; 2-layer GPTQ completes in lazy, disk-offload and resident configs.
fix(pangu): materialize non-layer replay modules for the last layer (#…
tests: pin file-backed offload instead of meta + hook offload (#6471)
Remove accelerate: explicit WeightLoader for weight loading, placemen…