Skip to content

fix(exl3): give routed-expert Hessians a concrete owner device (#5093) - #5144

Merged
Qubitium merged 2 commits into
mainfrom
fix/exl3-moe-dp-hessian-owner-5093
Nov 18, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/exl3-moe-dp-hessian-owner-5093

Conversation

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5093.

EXL3 pinned each routed expert's shared Hessian accumulator to an "owner"
device, but with the default config the owner list came from the bare
qcfg.device family (exllamav3_processor.py:147-162), which
as_torch_device keeps index-less on purpose. GPTQ.process_batch
(gptq.py:1356-1361) then moved every partial to torch.device("cuda") --
the calling worker's current GPU -- while keying it under "cuda". With
auto_forward_data_parallel=True the cuda:1 worker added its partial to the
cuda:0 tensor and layer 0 failed with Expected all tensors to be on the same device. Dense models never reach this path, which is why they were fine.

The owner list now resolves to concrete ordinals, so every worker accumulates
into the same device-keyed entry.

What Changed

  • routed_expert_owner_devices now prefers the configured
    moe_vram_strategy_devices, then the looper's resolved MoE pool
    (ModuleLooper._moe_quant_devices, after compute_device_filter), and
    finally expands a bare qcfg.device family to the runtime's visible
    ordinals. Indexed and CPU entries are preserved.
  • ModuleLooper binds that pool to processors that own per-device capture
    state via EXL3Processor.bind_moe_quant_devices, so capture stays on the
    devices the run is allowed to use.
  • GPTQ.set_hessian_accumulator_device rejects an index-less accelerator
    device. A thread-relative device can never name a shared accumulator key;
    failing at preprocess names the module instead of crashing in layer 0.
  • The serial forward (auto_forward_data_parallel=False) now also spreads
    experts round-robin instead of accumulating everything on the forward
    thread's current device. The reduced sum is unchanged.
  • docs/multi_gpu_quantization.md documents the ownership flow.

No API change: the public config surface is unchanged.

Tests

python -m pytest tests/test_exl3_moe_dp_hessian_owner_5093.py tests/test_exl3_rocm_moe_devices_4667.py -q -ra
# 11 passed

python -m pytest tests/test_exl3_*.py tests/test_shared_input_hessian_dedup.py tests/test_shared_input_hessian_dedup_methods.py tests/test_quantize_config_offload_tempdir.py -q -ra
# 383 passed

bash format/check.sh
# ruff 0.14.2, All checks passed!

The two-device tests skip when fewer than two CUDA devices are visible; the
runs above had two and skipped nothing.

Red evidence, same test file on a worktree at the pre-fix revision:

tests/test_exl3_moe_dp_hessian_owner_5093.py::test_bare_device_family_expands_to_visible_ordinals FAILED
    assert [device(type='cuda')] == [device(type='cuda', index=0), device(type='cuda', index=1)]
tests/test_exl3_moe_dp_hessian_owner_5093.py::test_indexless_accumulator_device_is_rejected FAILED
    Failed: DID NOT RAISE ValueError
tests/test_exl3_rocm_moe_devices_4667.py::test_bare_family_expands_to_every_visible_ordinal FAILED
tests/test_exl3_moe_dp_hessian_owner_5093.py::test_default_data_parallel_owns_routed_hessians_on_concrete_devices FAILED
    RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1!

Green behavior on two CUDA devices with the default
auto_forward_data_parallel=True: quantization completes, owners are
cuda:0 and cuda:1, all 24 routed projections captured 128 tokens, and the
layer-0 Hessian (whose inputs come from the dense embeddings) matches the
serial capture with a normalized error <= 4.3e-8. Single-device and serial
controls also complete.

Model Support / Module Plan

Not applicable: no new model, alias, definition or module-plan change.

AWQ onboarding safety

Not applicable: no AWQ grouping, search, replay or fold change.

Logic Flow Documentation

This change alters owner resolution, a device boundary, and tensor lifecycle,
so the diagrams and the mechanism page are included.

flowchart TD
    A["EXL3Processor.preprocess<br/>routed expert identity"] --> B{"moe_vram_strategy_devices configured"}
    B -- "yes" --> C["as_torch_device per entry"]
    B -- "no" --> D{"looper MoE pool bound"}
    D -- "yes" --> E["ModuleLooper._moe_quant_devices<br/>after compute_device_filter"]
    D -- "no" --> F["qcfg.device through as_torch_device"]
    C --> G["_expand_family_owner_devices<br/>cuda becomes cuda:0 .. cuda:N-1"]
    E --> G
    F --> G
    G --> H["resolve_hessian_owner_device<br/>expert_index modulo len devices"]
    H --> I["GPTQ.set_hessian_accumulator_device"]
    I --> J["process_batch moves the batch to the owner<br/>and keys the partial under that device"]
    I -. "index-less accelerator" .-> X["ValueError: concrete ordinal required"]
    style X fill:#f8d7da,stroke:#c82333
Loading
Mechanism Before After
Owner list [as_torch_device(qcfg.device)], index-less (exllamav3_processor.py:147-162) Configured pool, else looper pool, else family expanded to visible ordinals
Worker 2 Moves the batch to "cuda" (its GPU) but keys it under "cuda" (gptq.py:1356-1361) Moves to the expert's concrete owner and keys it there
Accumulation existing.add_(xtx) mixes cuda:0 with cuda:1 (gptq.py:889) add_ runs on one device
Index-less accelerator Accepted; failure surfaces in layer 0 ValueError at preprocess naming the module
Serial forward Every expert owned by the forward thread's device Experts spread over the pool; same sum

The same diagram and the before/after table are in
docs/multi_gpu_quantization.md#routed-expert-hessian-ownership-exl3, which is
linked from the README's multi-GPU entry.

Review Requirements

  • Reviewed this PR.
  • Checked that the code matches existing project structure, APIs, and conventions.
  • Avoided unnecessary monkeypatching and used the project's normal extension points where possible.
  • Minimized and compacted the impacted code surface.
  • Considered and eliminated potential regressions.

Kernel Accuracy Requirements

Not a kernel change. The capture split is validated against the serial
capture: the layer-0 Hessian (inputs from the dense embeddings, so independent
of quantization) has a normalized error <= 4.3e-8, and every routed projection
records the same per-module sample count.

Notes

  • The two-device integration test compares only layer 0. Later layers replay
    the already-quantized layer 0, and data-parallel quantization is not
    bit-identical to the serial path (documented in
    docs/multi_gpu_quantization.md), so their inputs legitimately differ.
  • The ValueError guard is defense in depth: the resolver no longer produces
    an index-less accelerator owner, but a future caller that bypasses it fails
    early with the module name.

EXL3 pins each routed expert's shared Hessian accumulator to an "owner"
device. With the default config the owner list came from the bare
`qcfg.device` family, and `as_torch_device` keeps families index-less on
purpose. `GPTQ.process_batch` then moved every partial to `"cuda"` -- the
calling worker's current GPU -- while keying it under `"cuda"`, so with
`auto_forward_data_parallel=True` the cuda:1 worker added its partial to
the cuda:0 tensor and layer 0 failed with "Expected all tensors to be on
the same device".

Resolve ownership to concrete ordinals:

- `routed_expert_owner_devices` prefers the configured
  `moe_vram_strategy_devices`, then the looper's resolved MoE pool
  (`_moe_quant_devices`, after `compute_device_filter`), then expands a
  bare `qcfg.device` family to the runtime's visible ordinals.
- `ModuleLooper` binds that pool to processors that own per-device capture
  state, so capture stays on the devices the run may use.
- `GPTQ.set_hessian_accumulator_device` rejects an index-less accelerator
  device, since it can never name a shared accumulator key.

The serial forward now also spreads experts round-robin instead of
accumulating everything on the forward thread's current device.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants