Repository navigation
fix(device): fall back to CPU for keyword maps without a usable accelerator - #6212
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6165.
On a host with a CUDA-built torch wheel but no usable GPU,
torch.accelerator.current_accelerator()still reportscudabecause it describes the build, not the runtime.normalize_device_device_maptherefore resolveddevice_map="auto"/"balanced"/"sequential"toDEVICE.CUDA, AUTO selectedTritonV2Linear, and the native loader raised: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
_current_accelerator()ingptqmodel/utils/importer.py: it returns the build accelerator only whentorch.accelerator.device_count() >= 1; otherwise it returnsNone.normalize_device_device_mapnow uses that helper for accelerate keyword maps, so a host with no usable device resolves the keyword toDEVICE.CPU.device="cuda",device_map={"": "cuda:0"}and integer ordinals still target CUDA and keep failing loudly when no device exists.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):
Red (only the
gptqmodel/utils/importer.pyfix reverted, new tests kept):The six failures assert
DEVICE.CUDA is DEVICE.CPUfor 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):
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 -rsSkips 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):GPTQModel.load(path, device_map="auto")->RuntimeError: No devices detected for accelerator family 'cuda'.GPTQModel.load(path, device_map="auto")->TorchCpuAvx512Linearoncpu.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!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
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:
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.