| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
This feature is still experimental. The next steps are:
We welcome help testing and validating this on large-scale models. |
Sorry, something went wrong.
|
@tohtana I wish I could be of help, but I haven't written code on this level; if you could clarify on what you mean by a preset for gpt-oss, or if there are other first-issues kind of work I could help with, I would gladly look into it |
Sorry, something went wrong.
|
Hi @jiosephlee, |
Sorry, something went wrong.
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
Hi @tohtana, I noticed this PR is in draft now. |
Sorry, something went wrong.
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com> (cherry picked from commit cc45af3)
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
Hi @nathon-lee,
I've been using Mixtral for verification but haven't checked other models enough. If you can try and share the feedback, it would be super helpful. Reducing the number of layers would be fine. |
Sorry, something went wrong.
|
ok, @tohtana
|
Sorry, something went wrong.
|
Hi @tohtana, @PKUWZP and I is testing Moonlight-16B-A6B model finetuning which is a muon pretrained model. When working on this model, we found some changes to AutoEP is necessary to make AutoEP work with noaux_ac MoE (which is used by DeepSeek and Moonlight) model and with models using Muon optimizers. The changes is in following branch, is it possible to merge this branch into your PR? Thanks! https://github.com/deepspeedai/DeepSpeed/tree/gma/autoep-muon-fixes |
Sorry, something went wrong.
Here is the model that requires this change to work with AutoEP, https://huggingface.co/delock/Moonlight-16B-A3B-finetune-fixed |
Sorry, something went wrong.
|
Hi @delock, Thank you for sharing the patch! It definitely fixes an issue with DeepSeek / Moonlight.
Can you update our patch? On the Muon side, I also found that it removes @compiler.compile() and replaces one batched Newton-Schulz call with a Python loop over experts. Current Muon already supports batched matrices. Can we use it? |
Sorry, something went wrong.
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
Hi @tohtana, I ran some tests on the new AutoEP presets and wanted to share my findings. 1. Qwen preset works as expected 2. There are still some issues testing other models:
(Note: I also intentionally loaded the Qwen model but applied the llama4 preset. AutoEP correctly threw the "no MoE layers detected" error, which verifies that the regex parser isolation works correctly.) |
Sorry, something went wrong.
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Two fixes addressing masahiro's review feedback on PR #7938: 1. Auto-fill AutoEPConfig from HF model config (auto_ep_config.py, auto_ep.py): add fill_autoep_config_from_hf() which maps HF field names to AutoEP internal names on AutoEP.__init__: - n_group -> num_expert_groups - topk_group -> num_limited_groups - routed_scaling_factor -> route_scale User-supplied values always take precedence. Without this, Moonlight (DeepSeek-V3) training used route_scale=1.0 instead of 2.446, producing systematically wrong MoE output magnitudes. 2. Restore batched Newton-Schulz in muon_update (original_muon.py): replace the per-expert Python loop with a single batched call to zeropower_via_newtonschulz5, which already supports ndim>=2 inputs. This restores GPU parallelism across all E experts per step. Signed-off-by: Ma, Guokai <guokai.ma@gmail.com>
|
Hi @tohtana , another question, I'm testing freeze most of the parameters (including expert parameters) except expert router parameters. During the process I found that the freezed expert are not freezed any more and I got an OOM during training. Should AutoEP sync requires_grad flags after create the new EP tensors? |
Sorry, something went wrong.
Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
Great catch, @delock! I appreciate your help with testing AutoEP. |
Sorry, something went wrong.
refactor(autoep-zero3): drop files already covered by deepspeedai#7938
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
@tohtana LGTM. This is really awesome.
|
Sorry, something went wrong.
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com>
|
@sfc-gh-truwase Thank you for reviewing!
Updated the doc to clarify the we now have two different features for MoE. I also added a link to the AutoEP doc.
That will be follow-up work. |
Sorry, something went wrong.
|
@tohtana Thanks for the PR, I am actually wondering if you have tested the AutoEP code over multi-node GPU clusters and explored any issues in communication overheads? |
Sorry, something went wrong.
This PR adds AutoEP (Automatic Expert Parallelism) to DeepSpeed training for HuggingFace MoE models. AutoEP detects MoE blocks during `deepspeed.initialize()`, builds the required EP/EDP process groups, and replaces supported MoE blocks with an EP-enabled execution path, so expert parallelism can be enabled with DeepSpeed config only and without model code changes. Current scope in this PR is the base AutoEP feature: - ZeRO stages 0, 1, and 2 support - checkpoint save/load support - universal checkpoint conversion support ZeRO-3 extensions are intentionally left as follow-up work (deepspeedai#7928 should be merged for this work) Supported presets in this PR: - Mixtral - Qwen3-MoE - DeepSeek-V2 - DeepSeek-V3 For end-to-end benchmarking and testing, an AutoEP example is available in DeepSpeedExamples: - <https://github.com/tohtana/DeepSpeedExamples/tree/tohtana/add_auto_ep/training/expert_parallel> ## Attribution This implementation substantially builds on TorchTitan's MoE / expert-parallel implementation, and we want to explicitly acknowledge that prior work. The TorchTitan-derived pieces in this PR are primarily: - `deepspeed/moe/ep_router.py`: adapted from TorchTitan's `TokenChoiceTopKRouter` - `deepspeed/moe/ep_experts.py`: adapted from TorchTitan's `GroupedExperts` and grouped-GEMM expert execution path - `deepspeed/moe/ep_kernels.py`: adapted from TorchTitan's `TokenReorderer`, `generate_permute_indices`, Triton fill-indices kernel, and token-group alignment / padding helpers - `deepspeed/module_inject/auto_ep_layer.py`: adapts the same router -> reorder -> dispatch -> local expert compute -> combine structure used in TorchTitan's MoE / EP flow Relevant TorchTitan sources: - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe/moe.py> - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe/kernels.py> - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe/utils.py> - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/distributed/expert_parallel.py> The DeepSpeed-specific work in this PR is the AutoEP integration layer around those building blocks: - HuggingFace MoE detection and structural validation - model-family presets and custom-config path - weight repacking from HF expert layouts into grouped expert tensors - DeepSpeed runtime group setup and module replacement - DeepSpeed checkpoint save/load and universal checkpoint support - DeepSpeed docs and tests ## Design The implementation is split into a few layers: - `deepspeed/module_inject/auto_ep_config.py` - user config parsing - built-in model presets - validation for EP topology and per-model constraints - `deepspeed/module_inject/auto_ep.py` - scans the model for MoE blocks - validates the detected structure - builds a `MoELayerSpec` for each supported MoE layer - replaces the original HF block with `AutoEPMoELayer` - `deepspeed/module_inject/auto_ep_layer.py` - the drop-in execution wrapper for a detected MoE block - implements router execution, token reorder, EP dispatch/combine, local expert compute, and shared-expert merge - `deepspeed/moe/ep_router.py`, `deepspeed/moe/ep_experts.py`, `deepspeed/moe/ep_kernels.py` - reusable MoE runtime pieces for routing, grouped expert compute, token permutation, and aligned grouped-GEMM execution - `deepspeed/moe/ep_repack.py` - converts HF expert weights into the grouped expert layout expected by the runtime - `deepspeed/runtime/engine.py` and checkpoint conversion code - wires AutoEP into `deepspeed.initialize()` - handles checkpoint save/load metadata and universal checkpoint integration At runtime, the execution path is: 1. detect and replace supported HF MoE blocks during initialization 2. route tokens with the EP router 3. reorder tokens by expert assignment 4. perform all-to-all dispatch across the EP group when `autoep_size > 1` 5. run local grouped expert compute 6. all-to-all combine and restore the original token order 7. merge shared experts if the model has them ## Adding new model support There are two supported ways to extend AutoEP to a new MoE model family. 1. Add a preset in `PRESET_MODELS`. This is the preferred path for a model family we want to support out of the box. A preset defines: - MoE layer pattern - router child name - experts child name - expert weight names / layout - `num_experts` and `top_k` config attributes - routing defaults - optional shared-expert structure 2. Use the custom config path. For models that are not yet built into DeepSpeed, AutoEP can be driven from config with: - `moe_layer_pattern` - `router_pattern` - `expert_pattern` - `expert_w1`, `expert_w2`, `expert_w3` - `num_experts_attr` - `top_k_attr` - optional shared-expert fields Once detection can produce a valid `MoELayerSpec`, the replacement, execution, and checkpoint paths are shared. --------- Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com> Signed-off-by: Ma, Guokai <guokai.ma@gmail.com> Signed-off-by: Guokai Ma <guokai.ma@intel.com> Co-authored-by: Ma, Guokai <guokai.ma@gmail.com> Co-authored-by: Guokai Ma <guokai.ma@intel.com> Signed-off-by: nathon-lee <leejianwoo@gmail.com>
This PR adds AutoEP (Automatic Expert Parallelism) to DeepSpeed training for HuggingFace MoE models. AutoEP detects MoE blocks during `deepspeed.initialize()`, builds the required EP/EDP process groups, and replaces supported MoE blocks with an EP-enabled execution path, so expert parallelism can be enabled with DeepSpeed config only and without model code changes. Current scope in this PR is the base AutoEP feature: - ZeRO stages 0, 1, and 2 support - checkpoint save/load support - universal checkpoint conversion support ZeRO-3 extensions are intentionally left as follow-up work (deepspeedai#7928 should be merged for this work) Supported presets in this PR: - Mixtral - Qwen3-MoE - DeepSeek-V2 - DeepSeek-V3 For end-to-end benchmarking and testing, an AutoEP example is available in DeepSpeedExamples: - <https://github.com/tohtana/DeepSpeedExamples/tree/tohtana/add_auto_ep/training/expert_parallel> ## Attribution This implementation substantially builds on TorchTitan's MoE / expert-parallel implementation, and we want to explicitly acknowledge that prior work. The TorchTitan-derived pieces in this PR are primarily: - `deepspeed/moe/ep_router.py`: adapted from TorchTitan's `TokenChoiceTopKRouter` - `deepspeed/moe/ep_experts.py`: adapted from TorchTitan's `GroupedExperts` and grouped-GEMM expert execution path - `deepspeed/moe/ep_kernels.py`: adapted from TorchTitan's `TokenReorderer`, `generate_permute_indices`, Triton fill-indices kernel, and token-group alignment / padding helpers - `deepspeed/module_inject/auto_ep_layer.py`: adapts the same router -> reorder -> dispatch -> local expert compute -> combine structure used in TorchTitan's MoE / EP flow Relevant TorchTitan sources: - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe/moe.py> - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe/kernels.py> - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/models/common/moe/utils.py> - <https://github.com/pytorch/torchtitan/blob/main/torchtitan/distributed/expert_parallel.py> The DeepSpeed-specific work in this PR is the AutoEP integration layer around those building blocks: - HuggingFace MoE detection and structural validation - model-family presets and custom-config path - weight repacking from HF expert layouts into grouped expert tensors - DeepSpeed runtime group setup and module replacement - DeepSpeed checkpoint save/load and universal checkpoint support - DeepSpeed docs and tests ## Design The implementation is split into a few layers: - `deepspeed/module_inject/auto_ep_config.py` - user config parsing - built-in model presets - validation for EP topology and per-model constraints - `deepspeed/module_inject/auto_ep.py` - scans the model for MoE blocks - validates the detected structure - builds a `MoELayerSpec` for each supported MoE layer - replaces the original HF block with `AutoEPMoELayer` - `deepspeed/module_inject/auto_ep_layer.py` - the drop-in execution wrapper for a detected MoE block - implements router execution, token reorder, EP dispatch/combine, local expert compute, and shared-expert merge - `deepspeed/moe/ep_router.py`, `deepspeed/moe/ep_experts.py`, `deepspeed/moe/ep_kernels.py` - reusable MoE runtime pieces for routing, grouped expert compute, token permutation, and aligned grouped-GEMM execution - `deepspeed/moe/ep_repack.py` - converts HF expert weights into the grouped expert layout expected by the runtime - `deepspeed/runtime/engine.py` and checkpoint conversion code - wires AutoEP into `deepspeed.initialize()` - handles checkpoint save/load metadata and universal checkpoint integration At runtime, the execution path is: 1. detect and replace supported HF MoE blocks during initialization 2. route tokens with the EP router 3. reorder tokens by expert assignment 4. perform all-to-all dispatch across the EP group when `autoep_size > 1` 5. run local grouped expert compute 6. all-to-all combine and restore the original token order 7. merge shared experts if the model has them ## Adding new model support There are two supported ways to extend AutoEP to a new MoE model family. 1. Add a preset in `PRESET_MODELS`. This is the preferred path for a model family we want to support out of the box. A preset defines: - MoE layer pattern - router child name - experts child name - expert weight names / layout - `num_experts` and `top_k` config attributes - routing defaults - optional shared-expert structure 2. Use the custom config path. For models that are not yet built into DeepSpeed, AutoEP can be driven from config with: - `moe_layer_pattern` - `router_pattern` - `expert_pattern` - `expert_w1`, `expert_w2`, `expert_w3` - `num_experts_attr` - `top_k_attr` - optional shared-expert fields Once detection can produce a valid `MoELayerSpec`, the replacement, execution, and checkpoint paths are shared. --------- Signed-off-by: Masahiro Tanaka <mtanaka@anyscale.com> Signed-off-by: Ma, Guokai <guokai.ma@gmail.com> Signed-off-by: Guokai Ma <guokai.ma@intel.com> Co-authored-by: Ma, Guokai <guokai.ma@gmail.com> Co-authored-by: Guokai Ma <guokai.ma@intel.com>
| Back | FazBrowse Home | New Git URL |
This PR adds AutoEP (Automatic Expert Parallelism) to DeepSpeed training for HuggingFace MoE models.
AutoEP detects MoE blocks during deepspeed.initialize(), builds the required EP/EDP process groups, and replaces supported MoE blocks with an EP-enabled execution path, so expert parallelism can be enabled with DeepSpeed config only and without model code changes.
Current scope in this PR is the base AutoEP feature:
ZeRO-3 extensions are intentionally left as follow-up work (#7928 should be merged for this work)
Supported presets in this PR:
For end-to-end benchmarking and testing, an AutoEP example is available in DeepSpeedExamples:
Attribution
This implementation substantially builds on TorchTitan's MoE / expert-parallel implementation, and we want to explicitly acknowledge that prior work.
The TorchTitan-derived pieces in this PR are primarily:
Relevant TorchTitan sources:
The DeepSpeed-specific work in this PR is the AutoEP integration layer around those building blocks:
Design
The implementation is split into a few layers:
deepspeed/module_inject/auto_ep_config.py
deepspeed/module_inject/auto_ep.py
deepspeed/module_inject/auto_ep_layer.py
deepspeed/moe/ep_router.py, deepspeed/moe/ep_experts.py, deepspeed/moe/ep_kernels.py
deepspeed/moe/ep_repack.py
deepspeed/runtime/engine.py and checkpoint conversion code
At runtime, the execution path is:
Adding new model support
There are two supported ways to extend AutoEP to a new MoE model family.
This is the preferred path for a model family we want to support out of the box. A preset defines:
For models that are not yet built into DeepSpeed, AutoEP can be driven from config with:
Once detection can produce a valid MoELayerSpec, the replacement, execution, and checkpoint paths are shared.