Repository navigation
DSV3 generation script - #959
Conversation
[ghstack-poisoned]
…total received" cc yifuwang ngimel [ghstack-poisoned]
This PR contains three changes:
1. all-to-all-v kernel writes out `output_splits` instead of total received
(so that we can use the split info as `input_splits` in backward)
ghstack-source-id: 8e0dda4
Pull Request resolved: #941
2. Add backward for all_to_all_v
ghstack-source-id: 8e0dda4
Pull Request resolved: #943
3. [DeepSeek] Enable backward
Test
```
$ torchrun --standalone --nproc-per-node 4 run.py
...
logits: torch.Size([2, 128, 102400])
logits: torch.Size([2, 128, 102400])
loss=tensor(510.3908, device='cuda:2', grad_fn=<MeanBackward0>)
loss=tensor(506.3376, device='cuda:3', grad_fn=<MeanBackward0>)
Backward done
Backward done
Backward done
Backward done
```
cc yifuwang ngimel
[ghstack-poisoned]
This PR contains three changes:
1. all-to-all-v kernel writes out `output_splits` instead of total received
(so that we can use the split info as `input_splits` in backward)
ghstack-source-id: 8e0dda4
Pull Request resolved: #941
2. Add backward for all_to_all_v
ghstack-source-id: 8e0dda4
Pull Request resolved: #943
3. [DeepSeek] Enable backward
Test
```
$ torchrun --standalone --nproc-per-node 4 run.py
...
logits: torch.Size([2, 128, 102400])
logits: torch.Size([2, 128, 102400])
loss=tensor(510.3908, device='cuda:2', grad_fn=<MeanBackward0>)
loss=tensor(506.3376, device='cuda:3', grad_fn=<MeanBackward0>)
Backward done
Backward done
Backward done
Backward done
```
cc yifuwang ngimel
[ghstack-poisoned]
This PR contains three changes:
1. all-to-all-v kernel writes out `output_splits` instead of total received
(so that we can use the split info as `input_splits` in backward)
ghstack-source-id: 8e0dda4
Pull Request resolved: #941
2. Add backward for all_to_all_v
ghstack-source-id: 8e0dda4
Pull Request resolved: #943
3. [DeepSeek] Enable backward
Test
```
$ torchrun --standalone --nproc-per-node 4 run.py
...
logits: torch.Size([2, 128, 102400])
logits: torch.Size([2, 128, 102400])
loss=tensor(510.3908, device='cuda:2', grad_fn=<MeanBackward0>)
loss=tensor(506.3376, device='cuda:3', grad_fn=<MeanBackward0>)
Backward done
Backward done
Backward done
Backward done
```
cc yifuwang ngimel
[ghstack-poisoned]
[ghstack-poisoned]
This PR uses the `y[expert_idx == i] = expert(tokens[expert_idx == i])` to perform expert processing. It provides a simpler alternative to the previous big chunk of code for token grouping (so that tokens for the same expert reside together). [ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
This PR adds FSDP on the Expert modules. Since before this we are already doing a DP-to-EP shuffle between the Attention and the Experts, we applies HSDP on the Attention, with the replicate dimension being the same as the EP dimension. [ghstack-poisoned]
[ghstack-poisoned]
|
@kwen2501 this is how I've been doing generations rn, but as I mentioned the outputs don't look right (see description). I can also upload the training loop but maybe it's easier to focus on getting the forward pass / inference working first. |
|
@kwen2501 nvm looks like there were a couple of bugs on my side, but forward pass looks good on ep only!! However, something seems off when using pp, (but not sure if just another bug in my code somewhere): |
Oh nice! At least the most risky part is correct!
Got it. Have you compared different pipeline schedules? |
|
Edit: ah, you are already using |
|
@lessw2020 I wonder if you could have a look too? I did not spot anything unusual. |
|
@EugenHotaj I ran your script with PP=2, EP=2, this is result I got: This is the only change I made to your script, change |
|
@kwen2501 I'm using the |
|
Ah I see. Makes sense. I missed that, lol. Let me re-download. |
|
BTW does ep work with mbs > 1? I'm getting an issue when I try |
|
Yep, I can repro the issue you had. |
Oh I am afraid we'd need to bump the symm mem size: torchtitan/torchtitan/experiments/deepseek_v3/model_config.py Lines 143 to 144 in 54ef422 The |
nvm, this was just me messing up something on my end. Good news is, with ep only the loss at step 0 matches an identical run I have on NeMo 2.0 🙂 . This is only for DeepSeek-V2-Lite, going to try DSV3 as well. |
No, it is a real issue :) I am glad you "messed" it out.
Oh nice! Thanks a ton for verifying it! |
|
btw, would you like to name you file as |
|
Sure! Afk right now but I update in a few hours. Also, are there plans to optimize the memory / speed for the model? I took a look at |
|
Please feel free to PR! Appreciate it. |
|
@kwen2501 ok cleaned up a bit should be good to land with your stack |
Hi @EugenHotaj - thanks for the PR! I will run it tomorrow and review but looks nice at first glance. |
@lessw2020 thanks looking forward to it! We've been using a different framework for DSV3 finetuning but it's hard to use / modify so would love a pytorch-native solution. So happy to be a very early user and get this working. |
kwen2501
left a comment
There was a problem hiding this comment.
Looks great! Thank you very much for your contribution!
| rope_scaling: dict = field(default_factory=lambda: { | ||
| "beta_fast": 32, | ||
| "beta_slow": 1, | ||
| "factor": 40, | ||
| "mscale": 1.0, | ||
| "mscale_all_dim": 1.0, | ||
| "original_max_position_embeddings": 4096, | ||
| "type": "yarn" | ||
| }) |
There was a problem hiding this comment.
Thank you so much for filling in these settings!
I wonder if you'd be able to write a short comment on what these settings refer to or where they come from? Thank you!
There was a problem hiding this comment.
Oh this is just from the config.json files, e.g. for dsv3: https://huggingface.co/deepseek-ai/DeepSeek-V3/blob/main/config.json
I think the defaults in the python files on huggingface are not up to date
|
You can fix the lint issues with |
|
Hi @EugenHotaj I've landed the code changes up to |
|
@kwen2501 yes let me do that |
|
@kwen2501 should be up to date now |
Add generation script for dsv3. To run: ``` torchrun --standalone --nproc-per-node 4 generate.py ``` E.g. generations: ``` <|begin▁of▁sentence|>You are a helpful assistant. User: What is 2+2? Assistant: 2 + 2 equals 4.<|end▁of▁sentence|> ``` --------- Co-authored-by: Ke Wen <[email protected]>
Add generation script for dsv3. To run: ``` torchrun --standalone --nproc-per-node 4 generate.py ``` E.g. generations: ``` <|begin▁of▁sentence|>You are a helpful assistant. User: What is 2+2? Assistant: 2 + 2 equals 4.<|end▁of▁sentence|> ``` --------- Co-authored-by: Ke Wen <[email protected]>
Add generation script for dsv3. To run: ``` torchrun --standalone --nproc-per-node 4 generate.py ``` E.g. generations: ``` <|begin▁of▁sentence|>You are a helpful assistant. User: What is 2+2? Assistant: 2 + 2 equals 4.<|end▁of▁sentence|> ``` --------- Co-authored-by: Ke Wen <[email protected]>
Add generation script for dsv3.
To run:
E.g. generations: