Skip to content

[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

Closed

Description

@Qubitium

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

import torch
from gptqmodel import GPTQModel
from gptqmodel.quantization.config import GPTQConfig, CalibrationConfig
g = 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 _ in range(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).

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-4e3a0639ecaf finished 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions