Repository navigation
Conversation
[ghstack-poisoned]
| # TODO: don't use `received` | ||
| gathered_tokens = MoE.token_gather_buf[:received] | ||
| else: # "torch_all_to_all" | ||
| # Prepare input ans output splits |
There was a problem hiding this comment.
Typo: and
also, the point of this else branch is just to offer EP>8 support for now, right? and perhaps also benchmark between the two on EP=8
| return reordered_past | ||
|
|
||
| # Setup Symmetric Memory for MoE token shuffle. | ||
| # Supports inference currently. |
There was a problem hiding this comment.
doesn't support training you mean?
there was a comment on the first PR in the stack that points out a bug in backward formula for all2all. Otoh I thought training was supported.
There was a problem hiding this comment.
Yeah, I put a comment in the code:
For training, this is disabled for now. Reason is that autograd requires tensors not be modified a second time, this conflicts with our wish of sharing the symm mem across layers and/or PP microbatches.
Till we find a workaround, this is disabled for backward.
There was a problem hiding this comment.
We noticed this as well when debugging the backward pass / the OOM mentioned in #979.
One way we were able to get around both issues is by using the symmetric memories purely as buffers and passing them directly to on_device_all_to_all_v and calling e.g. token_gather_buffer.copy_(tensor) inside the OnDeviceAllToAllV.forward function and changing OnDeviceAllToAllV.backward accordingly.
But tbh I'm not sure this resulted in correct gradients...
There was a problem hiding this comment.
@EugenHotaj Yeah, we may need to go the way you said.
Adding `dist.all_to_all_single` as token shuffle method. This is made the default option for better support of backward pass. The alternative shuffle method --`on_device_all_to_all_v` -- will be enabled only when user calls `model.setup_symm_mem()` and is limited to inference only. [ghstack-poisoned]
Adding `dist.all_to_all_single` as token shuffle method. This is made the default option for better support of backward pass. The alternative shuffle method --`on_device_all_to_all_v` -- will be enabled only when user calls `model.setup_symm_mem()` and is limited to inference only. [ghstack-poisoned]
|
Noob q: do we need to allreduce the gradients for the non-MoE parameters or is this automatically handled somehow? |
|
Great great great question! |
|
Yep. |
| processed_tokens = torch.empty_like(gathered_tokens) | ||
|
|
||
| # This part processes the tokens routed to the local experts. | ||
| # TODO: can we use group GEMM here? |
There was a problem hiding this comment.
yes, will integrate my MG group GEMM here. (#967)
| returned_tokens = torch.empty_like(gathered_tokens) | ||
| returned_tokens[idxs] = gathered_tokens | ||
| output_tokens = torch.empty_like(returned_tokens) | ||
| output_tokens[idxs] = returned_tokens |
There was a problem hiding this comment.
approx, in here we can add an un-permute kernel to handle and speedup the returned token re-ordering.
lessw2020
left a comment
There was a problem hiding this comment.
lgtm.
Stamping to get this landed!
Reland #989 Adding dist.all_to_all_single as token shuffle method. This is made the default option for better support of backward pass. The alternative shuffle method --on_device_all_to_all_v -- will be enabled only when user calls model.setup_symm_mem() and is limited to inference only.
|
Closing via #1002 |
Reland pytorch#989 Adding dist.all_to_all_single as token shuffle method. This is made the default option for better support of backward pass. The alternative shuffle method --on_device_all_to_all_v -- will be enabled only when user calls model.setup_symm_mem() and is limited to inference only.
Reland pytorch#989 Adding dist.all_to_all_single as token shuffle method. This is made the default option for better support of backward pass. The alternative shuffle method --on_device_all_to_all_v -- will be enabled only when user calls model.setup_symm_mem() and is limited to inference only.
Stack from ghstack (oldest at bottom):
output_splits#941Adding
dist.all_to_all_singleas token shuffle method.This is made the default option for better support of backward pass.
The alternative shuffle method --
on_device_all_to_all_v-- will be enabled only when user callsmodel.setup_symm_mem()and is limited to inference only.