Repository navigation
fix(loader): preserve concrete device sequences - #3577
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
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_devicesreturnedNonefor(0, 1), a single-device sequence, or a concrete-plus-bare mix (gptqmodel/models/loader.py:388-403at base6bf8b0b). TheNonefallback counted all visible GPUs (gptqmodel/models/loader.py:412-424).from_quantizedalso collapsed singleton and duplicate sequences to a scalar before placement (gptqmodel/models/loader.py:1515-1526at base).device=(0, 1)cuda:0,cuda:1device=("cuda:1",)cuda:1device=("cuda:1", "cuda")ValueErrorfor ambiguitydevice=("cuda:1", "cuda:1")cuda:1New 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;_explicit_requested_devicesnormalizes, deduplicates, and validates the original tuple/list atgptqmodel/models/loader.py:393-406._resolve_default_layerwise_devicekeeps a concrete tuple before generic normalization can collapse it (gptqmodel/models/loader.py:453-460), andfrom_quantizedcalls that path atgptqmodel/models/loader.py:1529-1536.from_pretraineduses the same validated ordinals to create itscompute_device_filter. The diagram and selection contract are indocs/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.