ms-swift icon indicating copy to clipboard operation
ms-swift copied to clipboard

Bug:megatron sft训练进行到eval和save的iter时退出

Open Sarahtorekryo opened this issue 1 year ago • 13 comments

Describe the bug 稳定复现:修改eval_interval和save_interval,退出的iter随之改变,报错Signal 11 (SIGSEGV) received by PID 即可以排除显存OOM的可能,eval_interval和save_interval设极大则训练正常进行

[Rank 7] (after 1 iterations) memory (MB) | allocated: 67419.740234375 | max allocated: 67419.74658203125 | reserved: 70648.0 | max reserved: 70648.0 [2025-08-28 15:00:37] iteration 5/ 2000 | consumed samples: 80 | elapsed time per iteration (ms): 11655.5 | memory(GiB): 87.97 | elapsed time: 1m 59s | remaining time: 13h 11m 31s | learning rate: 5.000000E-07 | global batch size: 16 | lm loss: 9.537131E-01 | load_balancing_loss: 1.905664E+00 | loss scale: 1.0 | grad norm: 5.919 | number of skipped iterations: 0 | number of nan iterations: 0 | [2025-08-28 15:01:26] iteration 10/ 2000 | consumed samples: 160 | elapsed time per iteration (ms): 9782.5 | memory(GiB): 93.61 | elapsed time: 2m 47s | remaining time: 9h 16m 59s | learning rate: 1.000000E-06 | global batch size: 16 | lm loss: 9.306264E-01 | load_balancing_loss: 1.885661E+00 | loss scale: 1.0 | grad norm: 5.538 | number of skipped iterations: 0 | number of nan iterations: 0 | dccd-pcde2-2131-xxx [6] NCCL INFO [Service thread] Connection closed by localRank 0 dccd-pcde2-2131-xxx [6] NCCL INFO [Service thread] Connection closed by localRank 7 dccd-pcde2-2131-xxx [6] NCCL INFO [Service thread] Connection closed by localRank 7 dccd-pcde2-2131-xxx [6] NCCL INFO [Service thread] Connection closed by localRank 1 W0828 15:01:26.518000 350839 torch/distributed/elastic/multiprocessing/api.py:900] Sending process 350881 closing signal SIGTERM W0828 15:01:26.521000 350839 torch/distributed/elastic/multiprocessing/api.py:900] Sending process 350882 closing signal SIGTERM

torch.distributed.elastic.multiprocessing.errors.ChildFailedError: =========================================================== /opt/tiger/ms-swift/swift/cli/_megatron/sft.py FAILED Failures: [1]: time : xxx host : xxx rank : 1 (local_rank: 1) exitcode : -11 (pid: 350877) error_file: <N/A> traceback : Signal 11 (SIGSEGV) received by PID 350877 [2]: time : xxx host : xxx rank : 2 (local_rank: 2) exitcode : -11 (pid: 350878) error_file: <N/A> traceback : Signal 11 (SIGSEGV) received by PID 350878

Your hardware and system info PyTorch version: 2.7.1 Python version: 3.11.2 Transformer Engine version: 2.6.0 CUDA version: 12.8 CUDNN version: 9.7.1 GPU: 8xNVIDIA B200

Additional context 翻到有其他swift sft类似bug,会是相同问题吗,盼优化~ sft训练过程中卡在保存ckpt前 #5293 Qwen3-emebdding训练中卡在eval不动 QwenLM/Qwen3-Embedding#108 微调模型时,eval会直接退出

脚本:

nproc_per_node=8 CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
MASTER_PORT=17005
NPROC_PER_NODE=$nproc_per_node
megatron sft
--load Qwen3-30B-A3B-Thinking-2507-mcore
--dataset train.json
--tensor_model_parallel_size 2
--pipeline_model_parallel_size 1
--expert_model_parallel_size 4
--moe_grouped_gemm true
--moe_shared_expert_overlap true
--moe_aux_loss_coeff 0.01
--micro_batch_size 1
--global_batch_size 16
--packing true
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 1
--train_iters 2000
--eval_iters 10
--finetune true
--cross_entropy_loss_fusion true
--lr 1e-5
--lr_warmup_iters 100
--min_lr 1e-6
--save megatron_output/Qwen3-30B-A3B-Thinking
--eval_interval 10000
--save_interval 10000
--max_length 5000
--num_workers 8
--dataset_num_proc 8
--no_save_optim true
--no_save_rng true
--sequence_parallel true
--use_flash_attn true
--overlap_grad_reduce true
--overlap_param_gather true `

Sarahtorekryo avatar Aug 28 '25 17:08 Sarahtorekryo

@Jintao-Huang @tastelikefeet 求助~

Sarahtorekryo avatar Aug 28 '25 18:08 Sarahtorekryo

https://github.com/NVIDIA/Megatron-LM/blob/core_r0.13.0/megatron/core/energy_monitor.py

发一下 pynvml的版本

Jintao-Huang avatar Aug 29 '25 07:08 Jintao-Huang

@Jintao-Huang 我有遇到同样的报错, pynvml版本是12.0.0 其他相关信息: ms-swift: 3.7.0 megatron-core: 0.13.0 transformer engine: 2.6.0.post1 torch: 2.7.1 cuda: 12.8 辛苦帮忙看下

Virgil-L avatar Sep 01 '25 10:09 Virgil-L

https://github.com/NVIDIA/Megatron-LM/blob/core_r0.13.0/megatron/core/energy_monitor.py

发一下 pynvml的版本

pynvml==11.5.3

Sarahtorekryo avatar Sep 01 '25 10:09 Sarahtorekryo

请问有解决方案或者规避手段了吗

zyq2ZYQ avatar Sep 17 '25 12:09 zyq2ZYQ

遇到了相同的错误。我试着区分了eval和save的iter,发现是在save时退出,请问有什么解决方法了么?

HaojieYuu avatar Sep 25 '25 09:09 HaojieYuu

https://github.com/NVIDIA/Megatron-LM/blob/core_r0.13.0/megatron/training/training.py#L1817-L1871

可以排查出是哪一行的报错嘛,我这里复现不了

虽然我怀疑是 这行

https://github.com/NVIDIA/Megatron-LM/blob/core_r0.13.0/megatron/training/training.py#L1833

Jintao-Huang avatar Sep 26 '25 02:09 Jintao-Huang

尝试了群里说的把energy_monitor.py的第62行改成return self._last_energy,就正常保存了

HaojieYuu avatar Sep 26 '25 03:09 HaojieYuu

尝试了群里说的把energy_monitor.py的第62行改成return self._last_energy,就正常保存了

https://github.com/NVIDIA/Megatron-LM/blob/core_r0.13.0/megatron/core/energy_monitor.py#L59-L64

Jintao-Huang avatar Sep 26 '25 03:09 Jintao-Huang

What should be the solution here? I have the same bug as in https://github.com/modelscope/ms-swift/issues/6342

mertunsall avatar Nov 03 '25 01:11 mertunsall

For me it seems to happen during eval, I set

    --eval_interval 205 \
    --save_interval 500 \

and it crashed during eval. But it's weird because if I set them very small values (10), then it doesn't crash and can evaluate normally.

mertunsall avatar Nov 03 '25 01:11 mertunsall

For me it seems to happen during eval, I set

    --eval_interval 205 \
    --save_interval 500 \

and it crashed during eval. But it's weird because if I set them very small values (10), then it doesn't crash and can evaluate normally.

change energy_monitor.py line 62-69 with try-except directly to "return self.__last_energy" https://github.com/NVIDIA/Megatron-LM/blob/core_r0.13.0/megatron/core/energy_monitor.py#L59-L64

sparkingarthur avatar Dec 11 '25 03:12 sparkingarthur

https://github.com/NVIDIA/Megatron-LM/issues/1880

Jintao-Huang avatar Dec 30 '25 15:12 Jintao-Huang