Skip to content

fix(loader): validate kernels against the max_memory devices, not every GPU (#4632) - #4637

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4632-max-memory-kernel-devices
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4632-max-memory-kernel-devices

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Root cause

max_memory is the authoritative placement list (#4082), but kernel selection ignored which devices it named:

  • _resolve_max_memory_device() returned None as soon as one non-CPU entry existed, so the loader fell through to _resolve_default_layerwise_device(device=None), which expands the CUDA family to every visible GPU;
  • _validate_selector_device_families then saw cuda:0=12.0, cuda:1=8.9 on a 5090 + 4090 host and refused the load — including budgets that only ever touch one card ({1: "20GiB"}, {0: "20GiB"}) and GPU+CPU offload budgets with BACKEND.TORCH.

Integer max_memory ordinals were also resolved against CPU when no device= was passed, so {1: "20GiB"} normalized to cpu:1 and looked accelerator-free.

Change (gptqmodel/models/loader.py)

  • _resolve_max_memory_device() now returns the tuple of concrete accelerator devices the budget names (deduplicated, in budget order) instead of None; CPU-only budgets still return DEVICE.CPU.
  • Integer keys resolve against the active accelerator family (_default_accelerator_family()) when no device= was given, and a clear error is raised if an ordinal is used on a host with no accelerator.
  • A device= that contradicts the budget is rejected: different family, or a concrete ordinal the budget does not fund. Matching requests are accepted.
  • The returned tuple flows through the existing explicit-sequence path, so _layerwise_device_count, _layerwise_device_strings and the placement builder use exactly those devices.

Tests

New tests/test_max_memory_kernel_devices_4632.py (8 tests) fakes a 2-GPU host with capabilities (12,0) / (8,9) and runs the real from_quantized chain (_resolve_max_memory_device → _resolve_default_layerwise_device → _validate_selector_device_families) for:

  • {1: ...}, {0: ...}, {"cuda:1": ...}, {0: ..., "cpu": ...} → resolve to exactly (cuda:N,) and no longer raise;
  • a budget naming both cards still rejects mixed capabilities (the guard is not weakened);
  • CPU-only budget → DEVICE.CPU; contradiction cases raise actionable errors.

On unmodified main 6 of the 8 fail with the reported cuda:0=12.0, cuda:1=8.9 error; with the fix all 8 pass.

tests/test_layerwise_device_placement.py::test_max_memory_with_an_accelerator_keeps_device_resolution asserted the old is None contract; it is updated to the new resolved-tuple contract (same intent: an accelerator budget keeps going down the device path).

tests/test_max_memory_kernel_devices_4632.py tests/test_layerwise_device_placement.py
tests/kernels/test_selection.py -> 163 passed, 73 skipped
tests/test_accelerator_memory_stats.py tests/test_qqq_kernel_memory_4387.py
tests/test_fp8_load_peak_4387.py tests/test_quantize_run_summary.py -> 86 passed, 4 skipped

Closes #4632.

…ry GPU

max_memory is the authoritative placement list (#4082), but kernel selection
expanded the CUDA family to every visible GPU. On a mixed-generation host
(RTX 5090 sm_120 + RTX 4090 sm_89) the capability check then rejected budgets
that never touched the other card: max_memory={1: '20GiB'} and even a
GPU+CPU offload budget with BACKEND.TORCH failed with cuda:0=12.0,
cuda:1=8.9.

Resolve max_memory to the concrete accelerator devices it names and hand that
tuple to the layer-wise/kernel path, so the capability check only sees GPUs
that will hold weights. Integer ordinals now resolve against the active
accelerator instead of CPU when no device was passed, and a device that
contradicts the budget is rejected with an actionable message.

Issue #4632.
@Qubitium
Qubitium merged commit 504769e into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4632-max-memory-kernel-devices branch November 17, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant