Skip to content

[DeepSeek] all-to-all-v kernel writes out output_splits - #994

Merged
kwen2501 merged 7 commits into
mainfrom
gh/kwen2501/5/base
Mar 20, 2025
Merged

kwen2501 merged 7 commits into
mainfrom
gh/kwen2501/5/base

Conversation

@kwen2501

Copy link
Copy Markdown
Contributor

Reland of #941 since ghstack land <PR> does not work now.

Original PR description:
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 the second shuffle or backward)

  2. Add backward for all_to_all_v (WIP)

  3. Move parts of the model out of no_grad()

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

kwen2501 added 7 commits March 6, 2025 16:50
…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]
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]
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 20, 2025
@kwen2501
kwen2501 merged commit d15ad3f into main Mar 20, 2025
MaxiBoether pushed a commit to eth-easl/torchtitan-mixtera that referenced this pull request Apr 17, 2025
Reland of pytorch#941  since `ghstack land <PR>` does not work now.

Original PR description:
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 the second
shuffle or backward)

2. Add backward for all_to_all_v (WIP)
  
3. Move parts of the model out of `no_grad()`

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
```
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
Reland of pytorch#941  since `ghstack land <PR>` does not work now.

Original PR description:
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 the second
shuffle or backward)

2. Add backward for all_to_all_v (WIP)
  
3. Move parts of the model out of `no_grad()`

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
```
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
Reland of pytorch#941  since `ghstack land <PR>` does not work now.

Original PR description:
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 the second
shuffle or backward)

2. Add backward for all_to_all_v (WIP)
  
3. Move parts of the model out of `no_grad()`

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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants