Skip to content

fix(looper): stage serial forward on the surviving filtered device - #3842

Merged
Qubitium merged 1 commit into
mainfrom
fix/3826-forward-single-device
Nov 13, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/3826-forward-single-device

Conversation

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator

TL;DR

ForwardExecutor.run() filtered the forward device pool but still handed the pre-filter cur_layer_device to the serial fallback. One-line behavior fix plus a regression test; 3 files, +95/-1.

1. The problem

select_forward_devices() expands a concrete device to its whole family. run() then applies compute_device_filter, and when exactly one device survives it dispatches to run_single(). The old code passed the original cur_layer_device, so a filter that excluded the base device had no effect on input staging, module rehome, or output placement.

flowchart TD
    A["ForwardExecutor.run"] --> B["select_forward_devices cur_layer_device"]
    B --> C["_filter_forward_devices"]
    C --> D{"Filtered device count"}
    D -- "1" --> E["run_single cur_layer_device"]
    E --> F["Stage inputs and rehome module on pre-filter cur_layer_device"]
    classDef failure fill:#ffe8e8,stroke:#b30000,color:#111;
    class F failure;
Loading
Mechanism Before (5853af0cf) After
Sole-survivor dispatch (gptqmodel/looper/forward_executor.py:232-248) Filtered list selected run_single, but cur_layer_device was forwarded unchanged run_single receives devices[0] from the filtered list
Input staging and module rehome (ForwardExecutor.run_single) Used the pre-filter base device Uses the surviving filtered device
Output placement (ForwardExecutor.run_single) Moved outputs to the pre-filter base device Moves outputs to the surviving filtered device
Empty filtered list (ForwardExecutor._filter_forward_devices) Returned the unfiltered pool Unchanged: returns the unfiltered pool

2. The new flow

flowchart TD
    A["ForwardExecutor.run"] --> B["select_forward_devices cur_layer_device"]
    B --> C["_filter_forward_devices"]
    C --> D{"Filtered device count"}
    D -- "0" --> E["Keep cur_layer_device"]
    D -- "1" --> F["single_device = devices[0]"]
    D -- "2+" --> G["run_parallel devices"]
    E --> H["run_single cur_layer_device"]
    F --> H
    H --> I["Stage inputs and rehome module on cur_layer_device"]
    classDef failure fill:#ffe8e8,stroke:#b30000,color:#111;
    class E failure;
Loading

3. Failure and ambiguity contract

Situation Before After
Filter keeps one device different from the base device Serial path used the excluded base device Serial path uses the surviving device
Filter keeps the base device Serial path used the base device Unchanged
Filter returns an empty list _filter_forward_devices keeps the unfiltered pool Unchanged
Filter keeps two or more devices run_parallel receives the filtered list Unchanged

4. Change inventory

Area File Purpose
Looper gptqmodel/looper/forward_executor.py Pass the sole surviving filtered device to run_single
Tests tests/test_compute_device_filter.py Pin serial-fallback target selection
Docs docs/multi_gpu_quantization.md Document forward device selection and the fallback contract

5. Tests

Test Invariant
tests/test_compute_device_filter.py::test_serial_fallback_stages_on_sole_surviving_filtered_device A filter that keeps only the non-base device is forwarded to run_single
Existing tests/test_compute_device_filter.py cases Quantization and parallel forward still honor the filter
Existing tests/module_tree/test_forward_executor_parallel.py cases Data-parallel result contract unchanged

6. Validation

  • Report reproduction: before observed=[('single', 'cuda:0')]; after observed=[('single', 'cuda:1')].
  • Real-device placement checks on both supported accelerator families, with the filter excluding the base device: parameter, input, module and output devices all land on the surviving device after the fix; all four were on the excluded base device before.
  • pytest tests/test_compute_device_filter.py tests/module_tree/test_forward_executor_parallel.py — 6 passed.
  • pytest tests/test_stage_modules.py — 49 passed.
  • pytest tests/test_calibration_data_device.py — 22 passed.
  • ruff check gptqmodel/looper/forward_executor.py tests/test_compute_device_filter.py — passed.
  • tests/test_weight_only_looper.py::test_weight_only_looper_respects_dense_and_moe_vram_strategy_devices fails on the unmodified base commit as well; unrelated to this change.

Fixes #3826.

ForwardExecutor.run applies compute_device_filter after select_forward_devices has expanded the base device to its family. When the filter leaves exactly one device, the serial fallback still received the pre-filter cur_layer_device, so inputs were staged and the module was rehomed on an excluded device.

Pass the sole surviving filtered device to run_single. Keep cur_layer_device when the filtered list is empty, matching _filter_forward_devices' existing fallback.

Fixes #3826.
@Qubitium
Qubitium merged commit b012d8a into main Nov 13, 2026
4 of 6 checks passed
@Qubitium
Qubitium deleted the fix/3826-forward-single-device branch November 13, 2026 08:51
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.

[BUG] Single-device forward fallback ignores the sole GPU retained by compute_device_filter

2 participants