Skip to content

fix(hf): rebuild CUDA-only kernels for a CPU-only resolved map (#5579) - #5657

Merged
Qubitium merged 1 commit into
mainfrom
fix/rocm-hf-cpu-only-reselect-5579
Nov 20, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/rocm-hf-cpu-only-reselect-5579

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

What

On ROCm, AutoModelForCausalLM.from_pretrained(<AWQ-GEMM ckpt>, device_map="auto", max_memory={"cpu": "30GiB"}) keeps AwqGEMMTritonLinear for every layer. The resolved map is all-CPU, so Transformers dispatches on CPU and nothing moves the layer to the GPU; the first forward then fails with ValueError: Pointer argument (...) cannot be accessed from Triton (cpu tensor?).

hf_gptqmodel_reselect_offloaded_kernels skipped those modules because AwqGEMMTritonLinear.SUPPORTS_CPU_OFFLOAD = True. That flag means "safe when Accelerate offloads the layer to a GPU execution device", which does not hold when the map has no GPU entry. CUDA happened to work only because Marlin lacks the flag.

Fix

  • _device_map_has_execution_device(map): true when any resolved entry is a GPU ordinal / non-CPU device (0, "cuda:0", torch.device("cuda", 0); "cpu", "disk", None are not).
  • _kernel_supports_cpu(kernel): DEVICE.CPU or DEVICE.ALL in SUPPORTS_DEVICES.
  • The reselect filter now honours SUPPORTS_CPU_OFFLOAD only when the map has an execution device. With a CPU-only map it rebuilds every CPU/disk-placed kernel that does not declare CPU support. Kernels that declare CPU are left alone; GPU-bearing maps behave exactly as before.

Tests

New tests/test_hf_bridge_cpu_only_reselect_5579.py (CPU-only, 8 nodes; 4 fail on clean main):

  • all-CPU ({"": "cpu"}, torch.device("cpu")) and disk-only maps rebuild a Triton-like kernel;
  • a map with a GPU entry ({"model.layers.0": 0, "model.layers.1": "cpu"}) keeps it;
  • CPU/ALL-device kernels are kept; a kernel without the declaration still rebuilds;
  • _device_map_has_execution_device unit cases.

Verification

  • tests/test_hf_bridge_cpu_only_reselect_5579.py -> 8 passed.
  • tests/test_hf_bridge_cpu_offload_5022.py -> 23 passed, 1 failed with CUDA_HOME unset (Marlin JIT); the same test fails identically on clean main in this environment.
  • tests/test_hf_bridge_thirdparty_offload_5262.py + tests/test_post_init_payload_5261.py -> 16 passed, 13 failed, all 13 the same pre-existing Marlin CUDA_HOME JIT error.
  • bash format/check.sh clean.

Not verified locally

No ROCm device here, so the gfx1201 end-to-end load is not re-measured. The unit tests pin the filter decision that caused the crash.

`SUPPORTS_CPU_OFFLOAD` means "safe when Accelerate runs the layer on a GPU
execution device", not "safe to execute on CPU". On ROCm,
`from_pretrained(device_map="auto")` with a `max_memory` that leaves the
model on CPU resolves to an all-CPU map; AUTO had picked
`AwqGEMMTritonLinear`, the reselect filter skipped every module because of
that flag, and the first forward handed CPU tensors to Triton:

  ValueError: Pointer argument (...) cannot be accessed from Triton (cpu tensor?)

Keep the flag's meaning but honour it only when the resolved map actually
has a non-CPU execution device. With no GPU entry, rebuild every
CPU/disk-placed kernel that does not declare DEVICE.CPU (or DEVICE.ALL) in
`SUPPORTS_DEVICES`; kernels that declare CPU support are left alone.
CUDA behaviour is unchanged (Marlin lacks the flag, Triton layers keep
their GPU execution device).

Adds tests/test_hf_bridge_cpu_only_reselect_5579.py (CPU-only, 8 nodes;
4 fail on clean main): CPU-only and disk-only maps rebuild a Triton-like
kernel, a GPU-bearing map keeps it, CPU/ALL-device kernels are kept, and
a kernel without the declaration still rebuilds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant