deepspeedai / deepspeedai/DeepSpeed

World size must be larger than number of experts in MoE inference ?

Open
#4,562 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

As the comments depict, does DeepSpeed require that the device number must be larger than the number of experts, necessarily? According to the source code, it seems like that #experts could be larger than the world size, yet the if branch could never be reached.

# deepspeed/inference/engine.py
def _create_ep_parallel_group(self, moe_experts):
    # Call the init process
    self.ep_group = {}
    self.expert_mp_group = {}
    moe_experts = moe_experts if type(moe_experts) is list else [moe_experts]
    for e in moe_experts:
        self.ep_group.update({e: None})
        self.expert_mp_group.update({e: None})
    for moe_ep_size in self.ep_group.keys():
        # If dist.get_world_size() is smaller than moe_ep_size (say world_size = 2 and moe_ep_size = 8), num_ep_groups is 0
        num_ep_groups = dist.get_world_size() // moe_ep_size
        for i in range(num_ep_groups):
            ep_cnt = i * moe_ep_size
            # If dist.get_world_size() is smaller than moe_ep_size, this if branch is useless
            size = dist.get_world_size() if moe_ep_size > dist.get_world_size() else moe_ep_size
            ranks = list(range(ep_cnt, ep_cnt + size))
            _ep_group = dist.new_group(ranks)
            if dist.get_rank() in ranks:
                self.ep_group.update({moe_ep_size: _ep_group})

        if dist.get_world_size() > moe_ep_size:
            num_expert_mp_groups = dist.get_world_size() // num_ep_groups
            expert_mp_size = dist.get_world_size() // moe_ep_size
            for i in range(num_expert_mp_groups):
                expert_mp_comm_ranks = [i + nr * moe_ep_size for nr in range(expert_mp_size)]
                _expert_mp_group = dist.new_group(expert_mp_comm_ranks)
                if dist.get_rank() in expert_mp_comm_ranks:
                    self.expert_mp_group.update({moe_ep_size: _expert_mp_group})

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in deepspeed/inference/engine.py at _create_ep_parallel_group and trace how world size and the expert parallel size determine the groups. Verify the behavior when the world size is smaller than the number of experts, then establish whether the current branch and group construction support that configuration; done means the supported relationship and resulting behavior are clear.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.