GLM5.1 MoE + PP 训练卡在 Train 0/100:batch_p2p_comm=True 但实际触发 unbatched P2P send/recv lazy NCCL communicator init
Checklist / 检查清单
- [x] I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
128 卡lora training
GLM 5.1 Megatron LoRA SFT hangs at first training step with Pipeline Parallel on 128 GPUs
Problem
Training GLM 5.1 (MoE, 78 layers, 256 experts) with Megatron LoRA SFT hangs at the first training step and never produces any loss output. The progress bar stays at Train: 0%| | 0/100. No NCCL timeout, no OOM, no Python traceback — just a silent hang.
This has been reproduced consistently across multiple configurations over 20+ attempts.
Environment
- ms-swift: 4.3.0.dev0
- megatron-core: 0.17.0
- mcore-bridge: 1.4.1 (+ GitHub main for rotary_interleaved fix)
- transformer-engine: 2.15.0
- PyTorch: 2.10.0, CUDA 13.1
- Hardware: 16 nodes × 8 H800 GPUs = 128 GPUs
- Model: ZhipuAI/GLM-5.1 (
glm_moe_dsa, 78 layers, 256 experts, DSA attention)
Configurations Tried
| PP | TP | EP | DP | global_batch_size | Result |
|---|---|---|---|---|---|
| 1 | 4 | 8 | 32 | 32 | OOM during LoRA adapter injection (single card ~95GB full) |
| 2 | 4 | 8 | 8 | 32 | OOM during LoRA adapter injection |
| 4 | 4 | 8 | 8 | 32 | Hang at first step (9+ hours, no timeout) |
| 8 | 4 | 8 | 4 | 32 | Hang at first step (testing) |
Hang Symptoms (PP=4 case, observed for 9+ hours)
- Model loads successfully (78 layers, 46.9B params, 192M trainable LoRA)
- Dataset processes successfully (52k samples, packing to 8192, size=1023)
- Progress bar appears:
Train: 0%| | 0/100 - The following warning appears, then no further progress:
[rankN]:[W ProcessGroupNCCL.cpp:4071] Warning: An unbatched P2P op (send/recv)
was called on this ProcessGroup with size 4. In lazy initialization mode, this
will result in a new 2-rank NCCL communicator to be created.
-
GPU metrics: Only 3/16 executors show GPU utilization (~50-60%), the other 13 are idle. All executors have memory allocated (45-65 GiB), meaning processes are alive but stuck.
-
No NCCL timeout even with
NCCL_TIMEOUT=1800+NCCL_ASYNC_ERROR_HANDLING=1set — after 9+ hours, no timeout error was triggered.
Key Observation
The model config shows batch_p2p_comm=True, batch_p2p_sync=True, but the warning says "An unbatched P2P op was called". This mismatch suggests some pipeline P2P operations bypass the batched path and trigger lazy NCCL communicator initialization, which appears to deadlock.
Relevant Config Snippet
megatron sft \
--model GLM-5.1 \
--tuner_type lora \
--lora_rank 8 \
--lora_alpha 32 \
--target_modules all-linear \
--tensor_model_parallel_size 4 \
--expert_model_parallel_size 8 \
--pipeline_model_parallel_size 4 \
--decoder_last_pipeline_num_layers 18 \
--moe_grouped_gemm true \
--moe_shared_expert_overlap true \
--sequence_parallel true \
--micro_batch_size 1 \
--global_batch_size 32 \
--packing true \
--recompute_granularity full \
--recompute_method uniform \
--recompute_num_layers 1 \
--finetune true \
--cross_entropy_loss_fusion true \
--optimizer_cpu_offload false \
--attention_backend flash
Debug Environment Variables
NCCL_DEBUG=WARN
TORCH_DISTRIBUTED_DEBUG=DETAIL
NCCL_TIMEOUT=1800
NCCL_ASYNC_ERROR_HANDLING=1
Questions
- Is GLM 5.1 (MoE + DSA) with
pipeline_model_parallel_size > 1supported? Are there known issues with pipeline parallel for MoE models? - The "unbatched P2P op" warning appears despite
batch_p2p_comm=Truein the model config — is this expected? Could this cause a deadlock during lazy NCCL communicator initialization? - Is there a recommended parallelism configuration for GLM 5.1 LoRA training on 128 GPUs?
Related Issues
- #6312 — Swift Megatron SFT training hangs after thousands of steps on 128 GPUs with MoE + CP + PP
- #6476 — Qwen3-235B megatron pipeline并行报错
- #9191 — GLM5 全参数 SFT OOM
How to Reproduce / 如何复现
NPROC_PER_NODE=${n_gpus_per_node}
NNODES=${nnodes}
NODE_RANK=${ARNOLD_ID}
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
megatron sft
--model ${MODEL_PATH}
--dataset ${DATASET_PATH}
--tuner_type lora
--lora_rank 8
--lora_alpha 32
--target_modules all-linear
--merge_lora false
--tensor_model_parallel_size 4
--expert_model_parallel_size 8
--pipeline_model_parallel_size 4
--decoder_last_pipeline_num_layers 18
--moe_grouped_gemm true
--moe_shared_expert_overlap true
--moe_aux_loss_coeff 0.01
--dsa_indexer_loss_coeff 0.01
--sequence_parallel true
--micro_batch_size 1
--global_batch_size 32
--packing true
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 1
--finetune true
--cross_entropy_loss_fusion true
--optimizer_cpu_offload false
--optimizer_offload_fraction 1
--lr 1e-4
--lr_warmup_fraction 0.05
--min_lr 1e-5
--train_iters 100
--max_length 8192
--save_steps 100
--logging_steps 1
--output_dir ${OUTPUT_DIR}
--dataloader_num_workers 4
--dataset_num_proc 8
--no_save_optim true
--no_save_rng true
--attention_backend flash
--agent_template glm5_1
Additional Information / 补充信息
No response
我看看
我看看
感谢
https://github.com/modelscope/ms-swift/blob/e18b2ee839848b2ce5c232d0b303bf247f38e4f8/swift/megatron/init.py#L216
这里注释掉,看看能跑嘛
还有py-spy dump pid xxx 看看卡在哪行代码了
[rankN]:[W ProcessGroupNCCL.cpp:4071] Warning: An unbatched P2P op (send/recv) was called on this ProcessGroup with size 4. In lazy initialization mode, this will result in a new 2-rank NCCL communicator to be created.
这个能debug出是 哪行代码 抛出来的嘛
[rankN]:[W ProcessGroupNCCL.cpp:4071] Warning: An unbatched P2P op (send/recv) was called on this ProcessGroup with size 4. In lazy initialization mode, this will result in a new 2-rank NCCL communicator to be created.
这个能debug出是 哪行代码 抛出来的嘛
看着 只有 MTP中有isend/irecv的 操作
[rankN]:[W ProcessGroupNCCL.cpp:4071] Warning: An unbatched P2P op (send/recv) was called on this ProcessGroup with size 4. In lazy initialization mode, this will result in a new 2-rank NCCL communicator to be created. 这个能debug出是 哪行代码 抛出来的嘛
看着 只有 MTP中有isend/irecv的 操作
ok 我先注释掉试试
[rankN]:[W ProcessGroupNCCL.cpp:4071] Warning: An unbatched P2P op (send/recv) was called on this ProcessGroup with size 4. In lazy initialization mode, this will result in a new 2-rank NCCL communicator to be created. 这个能debug出是 哪行代码 抛出来的嘛
看着 只有 MTP中有isend/irecv的 操作
ok 我先注释掉试试
还是hang住了,我已经注释掉了并且设置了 --mtp_num_layers 0
suggestion from claude code.
还是一样。warning 里仍然说 "lazy initialization mode",说明 TORCH_NCCL_USE_COMM_NONBLOCKING=0 没起作用——这个环境变量控制的可能不是这里的 lazy init。
所有软件层面的尝试都没效果。这个 hang 发生在 megatron-core 0.17.0 的 pipeline parallel 1F1B schedule 内部,warning 之后某些 rank 的 send/recv 配对不上。
- 注释 _patch__batched_p2p_ops → 还是 hang
- --mtp_num_layers 0 → 还是 hang
- TORCH_NCCL_USE_COMM_NONBLOCKING=0 → 还是 hang
- PP=4 和 PP=8 都 hang,PP=1/2 OOM
问他下一步怎么排查,或者他能不能给一个 GLM 5.1 + PP 的已验证可用配置。
可否辛苦给一个128or更多h800 gpus的GLM 5.1 + PP 的已验证可用配置。
感觉不是 unbatched P2P op 这个warning的原因。会不会是环境的问题。
感觉不是 unbatched P2P op 这个warning的原因。会不会是环境的问题。
感谢回复,我已经参考了https://github.com/modelscope/ms-swift/issues/8231 里的环境还是不行
ms-swift/swift/megatron/init.py
Line 216 in e18b2ee
_patch__batched_p2p_ops() 这里注释掉,看看能跑嘛
还有py-spy dump pid xxx 看看卡在哪行代码了 Thread 30560 (active): "MainThread"
irecv (torch/distributed/distributed_c10d.py:2536)
batch_isend_irecv (torch/distributed/distributed_c10d.py:2854)
_communicate_shapes (core/pipeline_parallel/p2p_communication.py:257)
_communicate (core/pipeline_parallel/p2p_communication.py:323)
send_forward_recv_backward (core/pipeline_parallel/p2p_communication.py:545)
wrapper (core/utils.py:2559)
forward_backward_pipelining_without_interleaving (core/pipeline_parallel/schedules.py:2324)
train_step (swift/megatron/trainers/base.py:890)
run_train_step (swift/megatron/trainers/base.py:642)
train (swift/megatron/trainers/base.py:702)
run (swift/megatron/pipelines/train/sft.py:72)
main (swift/pipelines/base.py:52)
megatron_sft_main (swift/megatron/pipelines/train/sft.py:97)
(swift/cli/_megatron/sft.py:7)
Thread 31077 (idle): "fr_python_dump_server"
wait_signal_to_dump (megavision_sdk_core/flight_recorder/fr_dumper.py:95)
run (threading.py:1010)
_bootstrap_inner (threading.py:1073)
_bootstrap (threading.py:1030)
Thread 32904 (idle): "Thread-1"
wait (threading.py:359)
wait (threading.py:655)
run (tqdm/_monitor.py:60)
_bootstrap_inner (threading.py:1073)
_bootstrap (threading.py:1030)
Thread 34514 (idle): "Thread-8"
wait (threading.py:359)
wait (threading.py:655)
run (tqdm/_monitor.py:60)
_bootstrap_inner (threading.py:1073)
_bootstrap (threading.py:1030)
Thread 38754 (idle): "InductorSubproc"
_recv_msg (torch/_inductor/compile_worker/subproc_pool.py:76)
_read_thread (torch/_inductor/compile_worker/subproc_pool.py:271)
run (threading.py:1010)
_bootstrap_inner (threading.py:1073)
_bootstrap (threading.py:1030)
Thread 38970 (idle)
Thread 38971 (idle)
Thread 38972 (idle)
Thread 38973 (idle)
Thread 38974 (idle)
Thread 38975 (idle)
Thread 38976 (idle)
Thread 38977 (idle)
Thought for 33s (ctrl+o to expand)
● 两个 rank 栈完全一致——都卡在同一个地方:
irecv batch_isend_irecv _communicate_shapes ← 死锁点 _communicate send_forward_recv_backward forward_backward_pipelining_without_interleaving (line 2324)
确认了根因:PP P2P 通信死锁,具体在 shape 交换阶段。
_communicate_shapes 是在发送实际 tensor 之前先交换 shape 元信息。两个不同 PP stage 的 rank 同时在 send_forward_recv_backward 里做 irecv,意味着双方都在等对方发 shape,但没人在发——经典的通信模式不匹配。
这说明 GLM 5.1 的不同 PP stage 产生了不同数量或结构的中间 tensor(可能因为 DSA attention 的 indexer 或者 dense/MoE 混合层),导致相邻 stage 的 send/recv 对不上。
你要不要试试 _communicate_shapes
self.pp_group都修改为None试试(参考_patch__batched_p2p_ops的修改,之前这个补丁也是在某些环境卡住的原因)。(我这里复现不了,感觉是一些奇怪的问题导致卡住)
以及你试试其他模型是否有卡住的问题
ops = []
if send_prev_shape_tensor is not None:
send_prev_op = torch.distributed.P2POp(
torch.distributed.isend, send_prev_shape_tensor, self.prev_rank, self.pp_group
)
ops.append(send_prev_op)
if recv_prev_shape_tensor is not None:
recv_prev_op = torch.distributed.P2POp(
torch.distributed.irecv, recv_prev_shape_tensor, self.prev_rank, self.pp_group
)
ops.append(recv_prev_op)
if send_next_shape_tensor is not None:
send_next_op = torch.distributed.P2POp(
torch.distributed.isend, send_next_shape_tensor, self.next_rank, self.pp_group
)
ops.append(send_next_op)
if recv_next_shape_tensor is not None:
recv_next_op = torch.distributed.P2POp(
torch.distributed.irecv, recv_next_shape_tensor, self.next_rank, self.pp_group
)
ops.append(recv_next_op)
https://github.com/modelscope/ms-swift/pull/9486 这里有个相关PR
https://github.com/modelscope/ms-swift/pull/9493
https://github.com/modelscope/mcore-bridge/pull/111
https://github.com/NVIDIA/Megatron-LM/issues/5100
设置为packing false,variable_seq_lengths依旧是开启的
https://github.com/modelscope/mcore-bridge/blob/5b27c58376e1057cf6d7a16bbec3b35ccc5bba9e/src/mcore_bridge/config/model_config.py#L234
ms-swift是做 batch内padding的,并且默认是 padding_free true的。按道理和packing没有区别才对。
遇到了相同的问题,Qwen 3.5 397B,128卡(TP=8,PP=8,EP=8,DP=2)训练正常;64卡(TP=8,PP=8,EP=8,DP=1)时死锁。后来debug发现把 moe_shared_expert_overlap设置为false 似乎正常了,但会影响一点速度
在 H20 DeepSeek v4 flash 训练遇到同样问题,把节点间通信从 RMDA 转到以太网消除了卡死现象:
export NCCL_NET=Socket
export NCCL_IB_DISABLE=1
export NCCL_SOCKET_IFNAME=eth0
This issue has been inactive for over 3 months and will be automatically closed in 7 days. If this issue is still relevant, please reply to this message.