Skip to content

[BUG] #4714 incomplete: with one GPU per capability (4090+5090) the default layer-wise device_map still spans every visible GPU; the mixed-capability guard is bypassed instead of placement staying in one group #4734

Closed

Description

@Qubitium

Found on main @ b225a43. CPU-mocked topology on a single RTX 4090: torch.cuda.device_count and get_device_capability are patched to describe a 4090 + 5090 host. Not yet run on real mixed hardware.

What is wrong

#4714 (fix for #4705) makes _resolve_default_layerwise_device keep the default placement inside the first device's compute-capability group (expand_selector_device_family(..., single_capability_group=True), gptqmodel/utils/importer.py). On the exact topology from #4705, one GPU per capability (4090 + 5090), that group has one device, and expand_selector_device_family returns it as a scalar (devices[0] if len(devices) == 1).

The layer-wise map builder then treats that scalar as a whole family. _layerwise_device_count (gptqmodel/models/loader.py:495-512) finds no explicit device list and returns torch.cuda.device_count(), which counts every visible GPU. build_layerwise_device_map (loader.py:~3303) then spreads the layers over cuda:0 and cuda:1.

Result:

The load in #4705 now succeeds because the guard is bypassed, not because placement stays in one group as the PR says. When the group has 2 or more devices the result is correct: a mocked [8.9, 12.0, 8.9] host maps to cuda:0 and cuda:2 only.

Repro (single GPU, capabilities mocked after import)

import torch
from gptqmodel import GPTQModel, BACKEND
import transformers.quantizers.auto
import gptqmodel.models.loader as L, gptqmodel.utils.model as UM

caps = {0: (8, 9), 1: (12, 0)}                      # 4090 at cuda:0, 5090 at cuda:1
torch.cuda.device_count = lambda: len(caps)
torch.cuda.get_device_capability = lambda d=None: caps[0 if d is None else (d if isinstance(d, int) else torch.device(d).index or 0)]

_r = L._resolve_default_layerwise_device
L._resolve_default_layerwise_device = lambda *a, **k: (print("default device ->", r := _r(*a, **k)), r)[1]
_o = UM.load_checkpoint_in_model_then_tie_weights
def spy(*a, **k):
    print("device_map values:", sorted({str(v) for v in k["device_map"].values()})); return _o(*a, **k)
L.load_checkpoint_in_model_then_tie_weights = spy

GPTQModel.load("ModelCloud/Llama-3.2-1B-Instruct-GPTQ-4bits-gp128", backend=BACKEND.AUTO)   # no device / device_map / max_memory

Output:

main @ b225a4383:
default device -> cuda:0
device_map values: ['cuda:0', 'cuda:1']           # layers placed on the excluded 12.0 GPU
(then "CUDA error: invalid device ordinal" here only because cuda:1 is mocked)

pre-fix @ 12c1273c2:
ValueError: Quantized kernel selection does not support a device map spanning different GPU compute capabilities: cuda:0=8.9, cuda:1=12.0.

main, explicit device="cuda:0":
device_map values: ['cuda:0']   -> loads, MarlinLinear, "The capital of France is Paris."

main, mocked [8.9, 12.0, 8.9]:
default device -> (cuda:0, cuda:2)
device_map values: ['cuda:0', 'cuda:2']           # correct when the group has >= 2 devices

Impact

On 4090 + 5090 with a GPTQ/Marlin checkpoint, the JIT builds for every visible arch, so this probably runs. The guard exists for the cases where it would not. With one GPU per generation, any kernel whose support depends on capability gets selected against one card and run on the other. Examples: Marlin (min_capability 8.0) chosen on an Ampere cuda:0 while layers land on a Turing cuda:1; the W4A FP8 kernels (MIN_COMPUTE_CAPABILITY = (8, 9)) chosen on a 4090 while layers land on an A100; w4a_nvfp4 (12.1) and similar. Placement also differs from what #4714 documents: a 1B model that fits on one card is split across both GPUs.

Suggested fix

Return the capability group as an explicit tuple even when it has one device, or have _resolve_default_layerwise_device return (device,) when the group was narrowed. _layerwise_device_count and build_layerwise_device_map then use the narrowed set. In general, validate the final device map's devices (accelerator_devices_from_device_map(device_map)) with _validate_selector_device_families, not only the selector target.

Test that should have caught it

tests/test_default_device_mixed_capability_4705.py only checks _selector_devices(_resolve_default_layerwise_device(None, AUTO)). Add an assertion on build_layerwise_device_map(...)'s values (or _layerwise_device_count) for the 2-GPU [(8, 9), (12, 0)] and [(12, 0), (8, 9)] topologies.

Severity

Medium. The fix silently disables a correctness guard on mixed-generation hosts and does not change placement in the topology it targets. A real crash or wrong-kernel run needs a kernel that some GPU in the map does not support.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-53ba17eb4d83 finished this issue.

    Pull request: #4744

    Completing #4714: default layer-wise map must stay in one capability group, not bypass the guard

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