FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix device mismatch in test_gate_up_partition_covers_the_whole_weight by alanhuangyoo · Pull Request #8308 · deepspeedai/DeepSpeed · GitHub

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

Fix device mismatch in test_gate_up_partition_covers_the_whole_weight#8308
tohtana merged 1 commit into
deepspeedai:masterfrom
alanhuangyoo:fix/gate-up-partition-device-mismatch

Conversation

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 <alanhuangyoo@gmail.com>

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

tohtana enabled auto-merge August 24, 2026 16:53
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
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL