Skip to content

Fix device mismatch in test_gate_up_partition_covers_the_whole_weight - #8308

Merged
tohtana merged 1 commit into
deepspeedai:masterfrom
alanhuangyoo:fix/gate-up-partition-device-mismatch
Aug 24, 2026
Merged

tohtana merged 1 commit into
deepspeedai:masterfrom
alanhuangyoo:fix/gate-up-partition-device-mismatch

Conversation

@alanhuangyoo

Copy link
Copy Markdown
Contributor

tests/unit/module_inject/test_fused_repartition.py::test_gate_up_partition_covers_the_whole_weight fails on any accelerator-backed machine:

assert torch.equal(torch.cat([gate, up], dim=0), full_weight)
E  RuntimeError: Expected all tensors to be on the same device, but got other
   is on cpu, different from other tensors on cuda:0

GateUpPack_LinearLayer._tp_partition() finishes with self.move(_partition), and move() resolves its target as

device = 'cpu' if self.__class__.keep_module_on_host else get_accelerator().current_device_name()

so each shard comes back on the accelerator. full_weight is never moved, and torch.equal() refuses the cross-device comparison. The sibling test test_gate_up_partition_ignores_later_grain_size_changes compares two post-partition tensors, so both operands share a device and it passes — this is the only case in the file that mixes a partitioned tensor with the original.

This compares against full_weight on the shards' device instead. It is a no-op on CPU-only runs, which is why the test passes there.

Before, on master (8x H20, CUDA):

tests/unit/module_inject/  ->  36 passed, 1 failed

After:

tests/unit/module_inject/test_fused_repartition.py  ->  5 passed
tests/unit/module_inject/                           ->  37 passed

pre-commit run --files tests/unit/module_inject/test_fused_repartition.py is clean.

The test was added in #8185 four days ago. It is not covered by the live CI: modal-torch-latest runs tests/unit/v1/ only, and the self-hosted GPU workflows that would run unit/ have not produced a run in a long time (nv-a6000 last ran 2025-08-01, nv-nightly 2026-01-15, nv-torch-latest-v100 and nv-inference have no runs listed).

Env: torch 2.13.0+cu130, H20 (sm90), single node.

GateUpPack_LinearLayer._tp_partition() ends with self.move(), which
relocates the shard to get_accelerator().current_device_name(). The test
then compares the reassembled shards against full_weight, which stays on
CPU, so torch.equal() raises on any accelerator-backed machine:

  RuntimeError: Expected all tensors to be on the same device, but got
  other is on cpu, different from other tensors on cuda:0

Compare against full_weight on the shards' device. No-op on CPU-only runs.

Signed-off-by: alanhuangyoo <[email protected]>

@tohtana tohtana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the catch, @alanhuangyoo! Looks good to me.

@tohtana
tohtana enabled auto-merge August 24, 2026 16:53
@tohtana
tohtana added this pull request to the merge queue Aug 24, 2026
Merged via the queue into deepspeedai:master with commit 84fd92a Aug 24, 2026
13 of 15 checks passed
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants