Skip to content

[BUG] HF bridge: from_pretrained(device_map="auto", max_memory=<one card>) always fails on mixed-capability hosts (4090+5090): keyword map is expanded to every visible GPU before max_memory is applied (#4632 fixed only GPTQModel.load) #5084

Closed

Description

@Qubitium

Found on main @ e75181d, RTX 4090 (sm_89) + RTX 5090 (sm_120) visible as cuda:0 / cuda:1, torch 2.15 + CUDA 13.2, transformers 5.22.

What is wrong

On a host with two GPU generations, the plain-Transformers load of a GPT-QModel checkpoint with device_map="auto" always fails, even when max_memory names only one card (or one card plus CPU). GPTQModel.load with the same max_memory has worked since #4632. The error message recommends "a max_memory budget that names one card", but that does not work on this path.

Cause:

  • Transformers calls the quantizer's preprocess_model(..., device_map="auto") before it resolves the map from max_memory (transformers/modeling_utils.py: preprocess_model comes first, then _get_device_map(model, device_map, max_memory, ...)). max_memory is never passed to the quantizer.
  • The GPT-QModel bridge (gptqmodel/utils/hf_load.py:352 hf_normalize_device_device_map(None, device_map), the GPTQ path, and hf_select_quant_linear{,_v2} for AWQ) sends the "auto" keyword to normalize_device_device_map → _accelerate_keyword_device (gptqmodel/utils/importer.py:1075-1080) → expand_selector_device_family(CUDA). That expands to every visible GPU and runs _validate_selector_device_families (importer.py:387) without single_capability_group.
  • So the selector validates GPUs that the budget excludes, the same way [BUG] load(max_memory=...) validates kernels against every visible GPU instead of the budget's devices: mixed-arch hosts (4090+5090) refuse even single-GPU or GPU+CPU budgets #4632 did for the native loader.

Explicit maps that name one card (device_map={"": 1}, device_map=1, "cuda") load fine through the same bridge. The failure is limited to the accelerate keyword path, which is the standard way to use max_memory and CPU offload with Transformers (#5022 just fixed CPU offload on this path, but only on uniform hosts).

Repro

import torch, gptqmodel
from transformers import AutoModelForCausalLM
from gptqmodel import GPTQModel
P = "Llama-3.2-1B-Instruct-GPTQ-4bits-gp128"   # any GPTQ (or AWQ GEMM) checkpoint
print([torch.cuda.get_device_capability(i) for i in range(torch.cuda.device_count())])
for mm in ({1: "20GiB"}, {1: "400MiB", "cpu": "20GiB"}, {0: "20GiB"}):
    try:
        m = GPTQModel.load(P, max_memory=mm); print("GPTQModel.load     OK  ", mm, sorted({str(p.device) for p in m.model.parameters()}))
    except Exception as e: print("GPTQModel.load     FAIL", mm, type(e).__name__, str(e)[:150])
    try:
        m = AutoModelForCausalLM.from_pretrained(P, dtype=torch.float16, device_map="auto", max_memory=mm); print("HF from_pretrained OK  ", mm)
    except Exception as e: print("HF from_pretrained FAIL", mm, type(e).__name__, str(e)[:150])

Output:

[(8, 9), (12, 0)]
GPTQModel.load     OK   {1: '20GiB'} ['cuda:1']
HF from_pretrained FAIL {1: '20GiB'} ValueError Quantized kernel selection does not support a device map spanning different GPU compute capabilities: cuda:0=8.9, cuda:1=12.0. Place the model on one
GPTQModel.load     OK   {1: '400MiB', 'cpu': '20GiB'} ['cpu', 'cuda:1']
HF from_pretrained FAIL {1: '400MiB', 'cpu': '20GiB'} ValueError Quantized kernel selection does not support a device map spanning different GPU compute capabilities: ...
GPTQModel.load     OK   {0: '20GiB'} ['cuda:0']
HF from_pretrained FAIL {0: '20GiB'} ValueError Quantized kernel selection does not support a device map spanning different GPU compute capabilities: ...

The AWQ GEMM checkpoint AWQ-Llama-3.2-1B-g128-gemm fails the same way with {1: "400MiB", "cpu": "20GiB"}. With device_map={"": 1} or device_map=1, both load and generate correctly through the bridge.

Suggested fix

The bridge cannot see max_memory at preprocess_model time, so it should not reject a keyword map up front. Options:

  • For an accelerate keyword map, expand with single_capability_group=True (or select a kernel that is valid on every visible capability) instead of raising. Then validate the capability groups of the resolved placement in _process_model_after_weight_loading / post_init_model, where model.hf_device_map is known. That keeps the refusal for a map that really spans sm_89 and sm_120, and lets single-card budgets load.
  • At a minimum, the error raised from the HF path should not recommend max_memory, because on this path it cannot help. Only CUDA_VISIBLE_DEVICES or an explicit dict map works.

Test that should have caught it

tests/test_hf_bridge_cpu_offload_5022.py covers keyword+max_memory only on a uniform device set. Add a node that monkeypatches mixed capabilities ((8,9),(12,0)) and drives hf_gptqmodel_prepare_model_for_load(device_map="auto") / hf_select_quant_linear_v2(device_map="auto"). Then an end-to-end from_pretrained(device_map="auto", max_memory={1: ...}) should not raise.

Severity

Medium. It is a hard failure of the standard Transformers multi-GPU/offload idiom on mixed-generation workstations. The workaround is to hide GPUs with CUDA_VISIBLE_DEVICES or to write an explicit map, which loses max_memory budgeting.

🤖 Generated with Claude Code

Activity

  1. ZX-ModelCloud commented on Nov 18, 2026

    @ZX-ModelCloud
    Collaborator

    Claimed. I'm working on this issue and will submit a fix PR. Please avoid duplicate work in the meantime.

  2. ZX-ModelCloud commented on Nov 18, 2026

    @ZX-ModelCloud
    Collaborator

    Agent claim released: agent-0ccb368adbb7 finished this issue.

    Pull request: #5123

    Reproducing the HF-bridge keyword device_map failure on a mixed-capability host, then fixing selection at preprocess time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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