Skip to content

fix: prevent duplicate logical experts on same GPU - #28

Open
yurekami wants to merge 1 commit into
deepseek-ai:mainfrom
yurekami:fix/duplicate-experts-on-same-gpu
Open

yurekami wants to merge 1 commit into
deepseek-ai:mainfrom
yurekami:fix/duplicate-experts-on-same-gpu

Conversation

@yurekami

@yurekami yurekami commented Jan 2, 2026

Copy link
Copy Markdown

Summary

This PR fixes a bug where the expert packing algorithm could place multiple physical replicas of the same logical expert on the same GPU, which defeats the purpose of expert replication for load balancing.

Problem

As reported in #22, when distributing 256 logical experts + 32 redundant experts across 32 GPUs, the algorithm could produce mappings like:

dup expert layer 0 rank 16, [200, 226, 236, 236, 12, 204, 156, 229, 184]

where expert 236 appears twice on the same GPU.

Root Cause

The balanced_packing function in Step 3 only considered load balancing when packing physical experts to GPUs. It did not check whether multiple physical experts mapping to the same logical expert would end up on the same GPU.

Solution

  • Add optional logical_ids parameter to balanced_packing function
  • When packing, prefer packs (GPUs) that don't already contain the same logical expert ID
  • Pass the phy2mlog mapping to balanced_packing in Step 3 of rebalance_experts_hierarchical

The fix is backward compatible - existing code without the logical_ids parameter continues to work.

Changes

Test Results

README example test passed!
Issue #22 regression test passed!
High replication scenario test passed!
Global load balancing test passed!
Single replica per expert test passed!

All tests passed!

Test Plan

  • All new tests pass
  • README example produces valid output
  • No duplicate logical experts on same GPU in stress tests
  • Backward compatibility maintained (no API changes for existing callers)

Fixes #22

🤖 Generated with Claude Code

When packing physical experts to GPUs, the `balanced_packing` function
previously only considered load balancing, which could result in multiple
physical replicas of the same logical expert being placed on the same GPU.
This is inefficient and defeats the purpose of expert replication.

Changes:
- Add optional `logical_ids` parameter to `balanced_packing` function
- When packing, prefer packs that don't already contain the same logical ID
- Pass `phy2mlog` (physical-to-logical mapping) to balanced_packing in Step 3
- Add comprehensive test suite with regression test for issue deepseek-ai#22

The fix maintains backward compatibility - existing code without the
logical_ids parameter continues to work as before.

Fixes deepseek-ai#22

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

eplb algorithm can generate phy2log with duplicate hot expert ids on same rank

1 participant