Skip to content

fix(loader): preserve concrete device sequences - #3577

Merged
Qubitium merged 2 commits into
mainfrom
audit/post3576-rco
Nov 8, 2026
Merged

Qubitium merged 2 commits into
mainfrom
audit/post3576-rco

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Preserve concrete device sequences through the default quantized loader path, and normalize integer ordinals through the shared selector in the quantization path. Reject a sequence that mixes concrete ordinals with abstract selectors instead of silently broadening it.

Regression

On a mocked four-GPU host, the old _explicit_requested_devices returned None for (0, 1), a single-device sequence, or a concrete-plus-bare mix (gptqmodel/models/loader.py:388-403 at base 6bf8b0b). The None fallback counted all visible GPUs (gptqmodel/models/loader.py:412-424). from_quantized also collapsed singleton and duplicate sequences to a scalar before placement (gptqmodel/models/loader.py:1515-1526 at base).

Request Before After
device=(0, 1) Quantization could use four GPUs; default load map used two Both select cuda:0, cuda:1
device=("cuda:1",) Both could use all four Both select only cuda:1
device=("cuda:1", "cuda") Both could use all four Raises ValueError for ambiguity
device=("cuda:1", "cuda:1") Quantization selected one; default load map could use four Both select only cuda:1

New flow

flowchart TD
    A["ModelLoader.from_quantized device argument"] --> B{"Explicit device_map?"}
    B -- Yes --> M["normalize_device_device_map from map"]
    B -- No --> C["_resolve_default_layerwise_device"]
    C --> D["_explicit_requested_devices"]
    D --> E["_selector_devices normalizes ordinals"]
    E --> F{"Concrete accelerator ordinals?"}
    F -- None --> G["normalize_device_device_map and auto_select_device"]
    G --> H["expand_selector_device_family"]
    F -- Mixed --> X["ValueError: ambiguous device sequence"]
    F -- All --> I["selector_device_family checks family and capabilities"]
    I --> J{"Compatible selected devices?"}
    J -- No --> Y["ValueError: unsupported device mix"]
    J -- Yes --> K["Keep ordered concrete tuple"]
    H --> L["_layerwise_device_count and _layerwise_device_strings"]
    K --> L
    M --> N["Explicit device_map placement"]
    classDef failure fill:#ffe8e8,stroke:#b30000,color:#111;
    class X,Y failure;
Loading

_explicit_requested_devices normalizes, deduplicates, and validates the original tuple/list at gptqmodel/models/loader.py:393-406. _resolve_default_layerwise_device keeps a concrete tuple before generic normalization can collapse it (gptqmodel/models/loader.py:453-460), and from_quantized calls that path at gptqmodel/models/loader.py:1529-1536. from_pretrained uses the same validated ordinals to create its compute_device_filter. The diagram and selection contract are in docs/multi_gpu_quantization.md, linked from the README.

Validation

  • python -m pytest -q -o log_cli=false tests/test_layerwise_device_placement.py tests/test_compute_device_filter.py tests/test_quant_module_device.py tests/test_loader.py — 27 passed, 1 warning.
  • uvx ruff check gptqmodel/models/loader.py tests/test_layerwise_device_placement.py — passed.
  • git diff --check — passed.

The tests use a mocked four-GPU topology to exercise ordinal order, singletons, duplicates, mixed-selector rejection, and different GPU compute capabilities.

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