Skip to content

fix(device): fall back to CPU for keyword maps without a usable accelerator - #6212

Merged
Qubitium merged 1 commit into
mainfrom
fix/6165-issue
Nov 29, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/6165-issue

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #6165.

On a host with a CUDA-built torch wheel but no usable GPU, torch.accelerator.current_accelerator() still reports cuda because it describes the build, not the runtime. normalize_device_device_map therefore resolved device_map="auto" / "balanced" / "sequential" to DEVICE.CUDA, AUTO selected TritonV2Linear, and the native loader raised:

RuntimeError: No devices detected for accelerator family `cuda`

The HF bridge handed Transformers the same CUDA-only kernel, so AutoModelForCausalLM.from_pretrained(..., device_map="auto") returned a CPU model whose first forward crashed in the Triton dequant path.

What Changed

No API change. No follow-up work is required for this issue.

Tests

New regression nodes (all CPU-only, faking a CUDA wheel with zero visible devices):

cd /root/openai-audit/issue-6165/tests
CUDA_VISIBLE_DEVICES="" \
PYTHONPATH=/root/openai-audit/issue-6165:/root/openai-audit/issue-6165/tests \
/root/venv/bin/python -m pytest \
  kernels/test_selection.py::test_keyword_device_map_falls_back_to_cpu_without_a_visible_device \
  kernels/test_selection.py::test_explicit_cuda_requests_still_target_cuda_without_a_visible_device \
  test_hf_bridge_mixed_capability_5084.py::test_keyword_map_without_a_visible_accelerator_selects_a_cpu_kernel \
  test_layerwise_device_placement.py::test_keyword_map_without_a_visible_accelerator_places_the_model_on_cpu \
  -q -rs

Red (only the gptqmodel/utils/importer.py fix reverted, new tests kept):

6 failed, 1 passed in 3.00s

The six failures assert DEVICE.CUDA is DEVICE.CPU for the four keyword spellings, the HF bridge, and the native layer-wise placement path. The one pass is the explicit-request control, proving explicit CUDA requests did not change.

Green (fix applied):

7 passed in 3.04s

Affected families:

CUDA_VISIBLE_DEVICES="" \
PYTHONPATH=/root/openai-audit/issue-6165:/root/openai-audit/issue-6165/tests \
/root/venv/bin/python -m pytest \
  kernels/test_selection.py \
  test_hf_bridge_mixed_capability_5084.py \
  test_layerwise_device_placement.py \
  test_quantize_device_sequence_4875.py \
  test_dense_load_explicit_device_5373.py \
  -q -rs
186 passed, 75 skipped in 3.77s

Skips are optional/hardware-only kernels (Marlin, Machete, Triton, MLX, TTNN, etc.), a two-visible-GPU quantize-sequence case, and two dense-load cases that require a visible CUDA accelerator. There were no failures.

Manual end-to-end on a tiny local GPTQ checkpoint with CUDA_VISIBLE_DEVICES="" (torch 2.15.0+cu132, transformers 5.23.0):

  • Before: GPTQModel.load(path, device_map="auto") -> RuntimeError: No devices detected for accelerator family 'cuda'.
  • After: GPTQModel.load(path, device_map="auto") -> TorchCpuAvx512Linear on cpu.
  • After: AutoModelForCausalLM.from_pretrained(path, device_map="auto") -> TorchCpuAvx512Linear, first forward finite.

Lint:

/root/venv/bin/ruff check \
  gptqmodel/utils/importer.py \
  tests/kernels/test_selection.py \
  test_hf_bridge_mixed_capability_5084.py \
  test_layerwise_device_placement.py
# All checks passed!
  • Unit tests have been executed and passed, or the reason they are not applicable is documented.
  • I added a new simple/fast unit test for this change, or documented why that is not applicable.

Measured Impact

Not applicable: correctness fix in device resolution. No VRAM, performance, or accuracy metric changes; GPU-host resolution is unchanged.

Model Support / Module Plan

Not applicable: no model, alias, definition, or module-plan change.

AWQ onboarding safety

Not applicable: no AWQ grouping/search/replay/fold change.

Logic Flow Documentation

  • This change does not alter a major logic flow, or the required diagrams and docs page are included below.

Justification: this is a local fallback guard inside the existing keyword-map branch. Only the accelerator-availability condition changes; the resolution order, explicit-request path, kernel selection and consumers are untouched.

Review Requirements

I or an AI agent (such as Codex or Claude) have:

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not applicable: no kernel implementation, dispatch declaration, packing, or fusion change. The fix only prevents a CUDA-only kernel from being selected when no CUDA device exists.

@Qubitium
Qubitium marked this pull request as ready for review November 29, 2026 01:32
@Qubitium
Qubitium merged commit 9b4072c into main Nov 29, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/6165-issue branch November 29, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant