grpo训练,megatron MoE + vLLM rollout server 模式权重同步 shape mismatch(疑似缺少 MoE 权重重分片)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- distributed-systems, machine-learning
Research direction
Start by tracing the server mode weight synchronization path from Megatron export_weights into vLLM, then compare it with the colocate path that performs Megatron to vLLM resharding. Reproduce with the reported TP=2, EP=8, ETP=1 setup and inspect the routed expert weight shapes; done means server mode synchronizes the MoE weights successfully across the reported layouts.
Written by the indexing model from the issue text.
Description
Checklist / 检查清单
- I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
环境
- ms-swift: 4.6.0(4.5.3 时同样可复现)
- vLLM: 0.32.0(源码安装,含 PR #53896,支持 qwen4_exp)
- megatron-core: 0.18.2
- mcore-bridge: 1.6.4
- peft: 0.20.0 / transformers: 5.16.1 / torch: 2.13.0+cu130
- 模型: Qwen3.8-Flash-Next(qwen4_exp,125B MoE + 51B ngram 表)
- 硬件: 训练侧 8×A800-80G,rollout 侧另 8×A800-80G(两台机器,--vllm_mode server)
How to Reproduce / 如何复现
训练侧(megatron rlhf --rlhf_type grpo):
--tuner_type lora --lora_rank 8
--target_modules in_proj out_proj linear_proj linear_qkv
--tensor_model_parallel_size 2 # 也试过 8
--expert_model_parallel_size 8
--expert_tensor_parallel_size 1 # ETP=1,MoE 中间维不切
--context_parallel_size 4 # 也试过 1
--pipeline_model_parallel_size 1
--use_vllm true --vllm_mode server
--vllm_server_host <rollout_ip> --vllm_server_port 8000
rollout 侧(swift rollout):
--vllm_tensor_parallel_size 8 # 也试过 2
--vllm_enable_expert_parallel true
--vllm_enable_lora false # 也试过 true
现象:无论怎么调 TP,权重同步都在 shape mismatch 之间来回跳
场景一:rollout TP=8,训练 TP=2(默认)
Worker failed: The size of tensor a (80) must match the size of tensor b (640) at non-singleton dimension 0 (routed_experts, intermediate 维)
640 = moe_intermediate_size,80 = 640/8(vLLM TP=8 切中间维),而训练侧 ETP=1 不切中间维、导出完整 640。
场景二:rollout TP=2(试图对齐训练 TP=2)
不报 shape 错了,但 rollout 8 卡被展开为 TP2 × DP4(EngineCore_DP1/DP2),dense 层整份复制,每卡显存冲到 77.55 GiB / 79.27 GiB,update_flattened_params OOM(torch.empty 3.26 GiB 失败)。
场景三:训练 TP 改成 8(与 rollout TP=8 一致)
intermediate 维(80/640)对上了,但立刻冒出新的 mismatch:
Worker failed: The size of tensor a (40) must match the size of tensor b (2560) at non-singleton dimension 0 (routed_experts.py:623 _load_w2, down_proj hidden 维)
根因判断
megatron 和 vLLM 对 MoE expert 权重的切分布局定义不一致:
megatron 训练:EP 切 experts + ETP=1 不切 intermediate + TP 切 dense hidden;
vLLM 推理:TP 切 intermediate(和 hidden)+ EP(EPLB)横跨 TP×DP 切 experts。
同一个 expert 权重,两边在多个维度(intermediate / hidden / experts)上的切法规则都不一样。所以 server 模式下 export_weights 把 megatron 布局的权重原样传给 vLLM,vLLM 按自己的布局 copy_,必然在一个维度上对不上。
colocate 模式是好的(官方 Qwen3.8-Flash-Next Best Practice 的 GRPO 就是 colocate + TP2/EP4/PP2 + vLLM TP8),因为同进程内 bridge 会做一次 megatron→vLLM 的权重重分片;而 server 模式这条重分片路径缺失,导致 shape mismatch。
期望 / 请求
server 模式下支持 megatron MoE 权重 → vLLM rollout 的权重重分片(对齐 megatron 的 TP/EP/ETP 布局 与 vLLM 的 TP/EP 布局),和 colocate 模式一致;
或给出「megatron MoE 训练 + vLLM rollout server(两台机器)」的官方正确配置姿势——到底 tensor_model_parallel_size / expert_model_parallel_size / expert_tensor_parallel_size / rollout 的 vllm_tensor_parallel_size / vllm_enable_expert_parallel 该怎么配,才能让权重 shape 对齐。
这个问题不是配置能绕过的(场景一/二/三已排除),疑似是 server 同步缺 MoE 重分片,望确认并支持。
Additional Information / 补充信息
No response
- Dominant language
- Python
- Stars
- 16.2k
- Forks
- 1.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 68
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelscope/ms-swift
-
get_multimodal_target_regex(..., exclude_router=True) does not exclude shared_expert_gatePossibly taken @KonnyakuMatcha claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10696 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss crashes with beta>0 and kl_in_reward=True (NoneType * Tensor)Possibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelscope/ms-swift#10690 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss divides by all groups instead of valid groups, silently scaling gradientsPossibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10688 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 Half a day Newbie friendliness 62/100
modelscope/ms-swift#10621 ·
Maintainers usually reply within 1 day
-
[Bug] `get_seed` consumes a draw from the shared RandomState even when decision augmentation is disabled, changing the train/val split and dataset shufflePossibly taken @ryznren claimed this 38 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelscope/ms-swift#10466 · 1 comment ·
Maintainers usually reply within 1 day
All issues in modelscope/ms-swift
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day