Skip to content

[BUG] ROCm: transformers from_pretrained(device_map="auto") of an AWQ-GEMM ckpt that resolves to all-CPU keeps AwqGEMMTritonLinear (SUPPORTS_CPU_OFFLOAD skips the #5262 reselect) -> 'Pointer argument cannot be accessed from Triton' at first forward #5579

Closed

Description

@Qubitium

Found on main @ 8c71625, AMD Radeon AI PRO R9700 (gfx1201), torch 2.16 dev ROCm 10.1, transformers 5.23.0. The same failure is present at c03416c, so this is not a regression.

What is wrong

On ROCm, AutoModelForCausalLM.from_pretrained(<AWQ-GEMM ckpt>, device_map="auto", max_memory=...) crashes in the first forward when the resolved map puts the whole model on CPU. Two examples: max_memory={"cpu": "30GiB"}, or a GPU budget too small for any layer such as {0: "400MiB", "cpu": "30GiB"}. AUTO keeps AwqGEMMTritonLinear, and the Triton launch receives CPU tensors:

gptqmodel/nn_modules/qlinear/gemm_awq_triton.py:326 forward -> :122 forward
gptqmodel/quantization/awq/modules/triton/gemm.py:414 awq_gemm_triton
ValueError: Pointer argument (at 376736992) cannot be accessed from Triton (cpu tensor?)

The same load on CUDA works. There the bridge's hf_gptqmodel_reselect_offloaded_kernels (gptqmodel/utils/hf_load.py:683) rebuilds all 112 modules with TorchAtenAwqLinear (INFO Transformers/Optimum: rebuilding 112 CPU/disk-offloaded module(s)...). On ROCm the AUTO pick is AwqGEMMTritonLinear, which declares SUPPORTS_CPU_OFFLOAD = True (gemm_awq_triton.py:202, "the Triton kernel runs after Accelerate materializes the layer on the execution device"). The reselect filter at hf_load.py:721-726 therefore skips every module. That assumption holds only when there is a GPU execution device. When the map resolves to CPU only, transformers dispatches the model on CPU with no AlignDevicesHook, so nothing moves the layer to the GPU. tritonv2.TritonV2Linear declares the same flag.

Native GPTQModel.load(..., device_map="auto", max_memory={"cpu": "30GiB"}) on the same card picks TorchAtenAwqLinear and works. Only the HF bridge path is affected. Mixed placements ({0: "700MiB", "cpu": ...}, {0: "600MiB", "cpu": "200MiB", "disk": ...}) work on ROCm, because those layers get an AlignDevicesHook with execution device 0.

Repro (one ROCm GPU visible; with or without a prior import gptqmodel)

import torch, gptqmodel
from transformers import AutoModelForCausalLM, AutoTokenizer
P = "AWQ-Llama-3.2-1B-g128-gemm"
tok = AutoTokenizer.from_pretrained(P); ids = tok("The capital of France is", return_tensors="pt")
for kw in ({"device_map": "cpu"}, {"device_map": "auto", "max_memory": {"cpu": "30GiB"}}):
    m = AutoModelForCausalLM.from_pretrained(P, dtype=torch.float16, **kw)
    print(kw, {type(x).__name__ for x in m.modules() if "Awq" in type(x).__name__})
    print(tok.decode(m.generate(**ids, max_new_tokens=8, do_sample=False)[0]))

Output on ROCm:

{'device_map': 'cpu'}                                     ['TorchCpuAvx512AwqLinear']  ' Paris.\nThe capital of France is Paris'
{'device_map': 'auto', 'max_memory': {'cpu': '30GiB'}}    ['AwqGEMMTritonLinear']      ValueError: Pointer argument ... cannot be accessed from Triton (cpu tensor?)

On CUDA (RTX 4090), the second load gives ['TorchAtenAwqLinear'] ' Paris.\nThe capital of France is Paris'.

Suggested fix: SUPPORTS_CPU_OFFLOAD means "works when Accelerate offloads to a GPU execution device". In hf_gptqmodel_reselect_offloaded_kernels, when the resolved map has no GPU entry (every placement is cpu/disk), or when a module's placement is CPU with no GPU execution device, rebuild every module whose kernel does not list DEVICE.CPU in SUPPORTS_DEVICES, not only those without SUPPORTS_CPU_OFFLOAD. The #5262/#5395 CUDA paths only work because Marlin lacks the flag.

Which test should have caught it: tests/test_hf_bridge_thirdparty_offload_5262.py and test_hf_bridge_cpu_offload_5022.py cover only CUDA AUTO picks (Marlin) and only spills that keep a GPU execution device. Add a case with a CPU-only max_memory, and run the file on ROCm, where AUTO picks the Triton kernels.

Severity: low-medium. On ROCm, a plain transformers load with a max_memory that leaves no room on the GPU crashes at the first forward instead of running on CPU. Native load and CUDA are fine.

🤖 Generated with Claude Code

Activity

  1. added
    unsafe
    scanned
    on Nov 20, 2026
  2. added
    safe
    and removed
    unsafe
    on Nov 20, 2026
  3. Qubitium commented on Nov 20, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-fb5145b84190 finished this issue.

    Pull request: #5657

    ROCm HF-bridge reselect: make SUPPORTS_CPU_OFFLOAD skip only the offload path, not the CPU kernel reselect; CPU-testable with a fake device map

  4. Qubitium commented on Nov 20, 2026

    @Qubitium
    CollaboratorAuthor

    Fixed by #5657 (merged as 5cd9bb8). The reselect filter now honours SUPPORTS_CPU_OFFLOAD only when the resolved map has a non-CPU execution device; with an all-CPU/disk map it rebuilds every kernel that does not declare DEVICE.CPU/DEVICE.ALL, so the ROCm AUTO pick (AwqGEMMTritonLinear) is replaced before the first forward. Verified on CPU: 8 new filter tests pass (4 fail pre-fix); the two HF-bridge suites keep their pre-existing Marlin CUDA_HOME failures only. The gfx1201 end-to-end load was not re-measured here (no ROCm device).

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

    safescanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions