Qwen3.5-27B SFT report error found NaN in local grad norm for bucket #0 in backward pass before data-parallel communication collective'
Checklist / 检查清单
- [ ] I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
/root/swift-magatron-mindspeed/Megatron-LM/megatron/core/pipeline_parallel/schedules.py:189: UserWarning: The AccumulateGrad node's stream does not match the stream of the node that produced the incoming gradient. This may incur unnecessary synchronization and break CUDA graph capture if the AccumulateGrad node's stream is the default stream. This mismatch is caused by an AccumulateGrad node created prior to the current iteration being kept alive. This can happen if the autograd graph is still being kept alive by tensors such as the loss, or if you are using DDP, which will stash a reference to the node. To resolve the mismatch, delete all references to the autograd graph or ensure that DDP initialization is performed under the same stream as subsequent forwards. If the mismatch is intentional, you can use torch.autograd.graph.set_warn_on_accumulate_grad_stream_mismatch(False) to suppress this warning. (Triggered internally at /pytorch/torch/csrc/autograd/input_buffer.cpp:240.)
Variable._execution_engine.run_backward(
[INFO:swift] last_model_checkpoint: None
[rank14]: Traceback (most recent call last):
[rank14]: File "/root/ms-swift/swift/cli/_megatron/sft.py", line 7, in
How to Reproduce / 如何复现
#!/bin/bash set -eux
export HCCL_CONNECT_TIMEOUT=7200 export HCCL_EXEC_TIMEOUT=7200 export TORCH_DIST_INIT_TIMEOUT=7200 export TORCH_ELASTIC_RENDEZVOUS_TIMEOUT=7200 export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 export CELOSS_PARALLEL_SIZE=2048 export PYTORCH_NPU_ALLOC_CONF='expandable_segments:True' export PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True'
NPROC_PER_NODE=16
ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
megatron sft
--model /root/Qwen3.5-27B
--tuner_type full
--dataset /root/train_128_32k.jsonl
--add_non_thinking_prefix true
--tensor_model_parallel_size 4
--context_parallel_size 4
--pipeline_model_parallel_size 1
--sequence_parallel true
--use_distributed_optimizer true
--attention_backend flash
--packing true
--padding_free true
--max_length 36000
--no-moe-grouped-gemm
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 8
--torch_dtype bfloat16
--micro_batch_size 1
--global_batch_size 16
--lr 1e-5
--lr_warmup_fraction 0.05
--num_train_epochs 1
--dataset_num_proc 4
--dataloader_num_workers 16
--save_steps 2
--eval_steps 100
--save_total_limit 2
--save_safetensors true
--output_dir /root/swift_output/Qwen3.5-27B-NPU-ts
Installed package: torch2.10.0_npu.post2, torch2.10.0, ms-swift4.5.0dev0( 7.23 main branch), megatron v0.16.0, mindspeed r0.16.0, mcore-brige(main branch), FLA 0.5.2 main、triton-ascend 3.2.1、transformers 5.12.1
Additional Information / 补充信息
No response
有人可以看下嘛
--context_parallel_size 1 试试会不会报错
--context_parallel_size 1 试试会不会报错
会的,也尝试过
目前看是triton-ascend层级的问题,而且还比较偶现,不同机器似乎也存在差异,需要进一步定位,建议先卸载FLA正常训
目前看是triton-ascend层级的问题,而且还比较偶现,不同机器似乎也存在差异,需要进一步定位,建议先卸载FLA正常训
ok,那卸载fla后目前还有能启动Qwen3.5-27B支持context-parallel的训练组合嘛
目前看是triton-ascend层级的问题,而且还比较偶现,不同机器似乎也存在差异,需要进一步定位,建议先卸载FLA正常训
ok,那卸载fla后目前还有能启动Qwen3.5-27B支持context-parallel的训练组合嘛
目前发现加上这个参数可以先规避问题 --gradient_accumulation_fusion=False, 可以试下
目前看是triton-ascend层级的问题,而且还比较偶现,不同机器似乎也存在差异,需要进一步定位,建议先卸载FLA正常训
ok,那卸载fla后目前还有能启动Qwen3.5-27B支持context-parallel的训练组合嘛
目前发现加上这个参数可以先规避问题 --gradient_accumulation_fusion=False, 可以试下
好的我再尝试下
我在Qwen3.5-35BA3B 上SFT,USE_MCORE_GDN=1,也有这个问题。感觉是triton-ascend的问题。
[rank15]: RuntimeError: Rank 15, node n122-122-099, device 15, iteration -1: Unexpected result nan (message='found NaN in local grad norm for bucket #0 in backward pass before data-parallel communication collective')
#https://github.com/fla-org/flash-linear-attention/pull/1113 #https://github.com/modelscope/mcore-bridge/pull/162 目前看这两个修复PR合入后能够解决这个问题,总体上是两个问题,一个是triton-ascend层面的算子问题,一个是mcore-bridge这里的GDN的sp的实现问题
#fla-org/flash-linear-attention#1113 #modelscope/mcore-bridge#162 目前看这两个修复PR合入后能够解决这个问题,总体上是两个问题,一个是triton-ascend层面的算子问题,一个是mcore-bridge这里的GDN的sp的实现问题
拉这两个最新main分支安装嘛
#fla-org/flash-linear-attention#1113 #modelscope/mcore-bridge#162 目前看这两个修复PR合入后能够解决这个问题,总体上是两个问题,一个是triton-ascend层面的算子问题,一个是mcore-bridge这里的GDN的sp的实现问题
拉这两个最新main分支安装嘛
这两个都还没合入,需要自己手动apply一下
#fla-org/flash-linear-attention#1113 #modelscope/mcore-bridge#162 目前看这两个修复PR合入后能够解决这个问题,总体上是两个问题,一个是triton-ascend层面的算子问题,一个是mcore-bridge这里的GDN的sp的实现问题
拉这两个最新main分支安装嘛
这两个都还没合入,需要自己手动apply一下
okk感谢
#fla-org/flash-linear-attention#1113 #modelscope/mcore-bridge#162 目前看这两个修复PR合入后能够解决这个问题,总体上是两个问题,一个是triton-ascend层面的算子问题,一个是mcore-bridge这里的GDN的sp的实现问题
apply这两个pr还是报错,--gradient_accumulation_fusion=False 是必须的吗?
#fla-org/flash-linear-attention#1113 #modelscope/mcore-bridge#162 目前看这两个修复PR合入后能够解决这个问题,总体上是两个问题,一个是triton-ascend层面的算子问题,一个是mcore-bridge这里的GDN的sp的实现问题
apply这两个pr还是报错,--gradient_accumulation_fusion=False 是必须的吗?
不必须,但可以加上,注意清一下triton的缓存