Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug in switch_gate #199

Open
Heihaierr opened this issue Mar 7, 2024 · 6 comments
Open

A bug in switch_gate #199

Heihaierr opened this issue Mar 7, 2024 · 6 comments

Comments

@Heihaierr
Copy link
Contributor

Describe the bug
In fmoe/gates/switch_gate.py line 45:
capacity = math.ceil(cap_rate * inp.shape[0])

should be:
capacity = math.ceil(cap_rate * inp.shape[0] / self.num_expert) ?

@laekov
Copy link
Owner

laekov commented Mar 11, 2024

That is a good point. I think you are right. Can you please open a pull request on this? Thanks.

BTW, I am also wondering if the capacity calculation in GShardGate is wrong. @zms1999

@Peg-Wu
Copy link

Peg-Wu commented Apr 6, 2024

Hi, guys!
Thanks for your fantastic work.
I met a problem when I use class SwitchGate, can you take a look at it for me?

The following is my code:

import torch
from fmoe.gates import *

device = torch.device("cuda:0")

sg = SwitchGate(d_model=64, num_expert=5, world_size=2)
sg = sg.to(device)

input = torch.rand(128, 64) # (batch_size, d_model)
input = input.to(device)

idx, val = sg(input)
print(idx, idx.shape)
print(val, val.shape)

Parameter word_size can only set to 1, or it will occur the error "Segmentation fault (core dumped)".

@laekov
Copy link
Owner

laekov commented Apr 7, 2024

@Peg-Wu As you are not using torch distributed, world_size has to be 1.

@Peg-Wu
Copy link

Peg-Wu commented Apr 8, 2024

谢谢您的回复~

如果我想用DDP进行加速,
我应该怎样修改代码,
可以使用pytorch官方的DDP并行吗

@laekov
Copy link
Owner

laekov commented Apr 8, 2024

@Peg-Wu Refer to this test

@Peg-Wu
Copy link

Peg-Wu commented Apr 8, 2024

非常感谢!

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

No branches or pull requests

3 participants