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

qwen3.5-35B-A3B微调 保存权重时报错 NCCL Error 1: unhandled cuda error

Open ooochen-30 opened this issue 8 months ago • 7 comments

Checklist / 检查清单

  • [x] I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。

Bug Description / Bug 描述

save_steps/eval_steps=5 正常 save_steps/eval_steps=10 iter=10/20都正常 save_steps/eval_steps=20 iter=20 保存权重时报错如下(20->200一样)

2026-01-09 17:40:31.169301 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/base.py", line 223, in save
2026-01-09 17:40:31.169303 master-0 >> [rank7]: async_request = self.async_save(sharded_state_dict, checkpoint_dir)
2026-01-09 17:40:31.169305 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-01-09 17:40:31.169306 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/torch.py", line 764, in async_save
2026-01-09 17:40:31.169307 master-0 >> [rank7]: ) = save_state_dict_async_plan(
2026-01-09 17:40:31.169309 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-01-09 17:40:31.16931 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/state_dict_saver.py", line 141, in save_state_dict_async_plan
2026-01-09 17:40:31.169312 master-0 >> [rank7]: all_local_plans = dist_wrapper.gather_object(local_plan)
2026-01-09 17:40:31.169313 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-01-09 17:40:31.169315 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/checkpoint/utils.py", line 135, in gather_object
2026-01-09 17:40:31.169318 master-0 >> [rank7]: dist.gather_object(
2026-01-09 17:40:31.169319 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper
2026-01-09 17:40:31.169321 master-0 >> [rank7]: return func(*args, **kwargs)
2026-01-09 17:40:31.169322 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^
2026-01-09 17:40:31.169324 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 3301, in gather_object
2026-01-09 17:40:31.169325 master-0 >> [rank7]: gather(
2026-01-09 17:40:31.169327 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper
2026-01-09 17:40:31.169328 master-0 >> [rank7]: return func(*args, **kwargs)
2026-01-09 17:40:31.16933 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^
2026-01-09 17:40:31.169331 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 4201, in gather
2026-01-09 17:40:31.169333 master-0 >> [rank7]: work = group.gather(output_tensors, input_tensors, opts)
2026-01-09 17:40:31.169334 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2026-01-09 17:40:31.169336 master-0 >> [rank7]: RuntimeError: NCCL Error 1: unhandled cuda error (run with NCCL_DEBUG=INFO for details)
2026-01-09 17:41:12.871213 master-0 >> [rank7]:[W109 17:41:12.150540851 ProcessGroupNCCL.cpp:1538] Warning: WARNING: destroy_process_group() was not called before program exit, which can leak resources. For more info, please see https://pytorch.org/docs/stable/distributed.html#shutdown (function operator())
2026-01-09 17:41:22.907089 master-0 >> W0109 17:41:22.906000 74 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 139 closing signal SIGTERM

按照https://github.com/modelscope/ms-swift/issues/5594 改动megatron/core/energy_monitor.py如下没有效果

    # def _get_energy(self) -> int:
    #     """Get current energy consumption from NVML."""
    #     try:
    #         return nvmlDeviceGetTotalEnergyConsumption(self._handle)
    #     except NVMLError:
    #         return self._last_energy  # return *something* if it errors
    def _get_energy(self) -> int:
        return self._last_energy  # return *something* if it errors

@Jintao-Huang

How to Reproduce / 如何复现

环境是官方提供的镜像modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.9.1-py311-torch2.8.0-vllm0.11.0-modelscope1.32.0-swift3.11.3 并升级或安装下面的库 pip install transformers=5.2.0 pip install peft -U pip install ms-swift==4.0.0 pip install flash-linear-attention==0.4.1 pip install casual-conv1d # https://github.com/Dao-AILab/causal-conv1d/releases/tag/v1.6.0 以及flash-attn-v3

设备是8卡H100 微调脚本如下


export SWIFT_PATCH_CONV3D=False

EXP_NAME="xxx"

export PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True'
export NPROC_PER_NODE=8 
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 
megatron sft \
    --model /workspace/models/pretrained/Qwen3.5-35B-A3B \
    --dataset "/workspace/swift_channel.jsonl" \
    --load_from_cache_file true \
    --add_non_thinking_prefix true \
    --split_dataset_ratio 0.02 \
    --train_type lora \
    --lora_rank 16 \
    --lora_alpha 32 \
    --target_modules all-linear \
    --expert_model_parallel_size 4 \
    --moe_permute_fusion true \
    --moe_grouped_gemm true \
    --moe_shared_expert_overlap true \
    --moe_aux_loss_coeff 5e-4 \
    --micro_batch_size 1 \
    --global_batch_size 128 \
    --recompute_granularity full \
    --recompute_method uniform \
    --recompute_num_layers 1 \
    --num_train_epochs 3 \
    --finetune true \
    --freeze_llm false \
    --freeze_vit true \
    --freeze_aligner true \
    --cross_entropy_loss_fusion true \
    --lr 5e-5 \
    --lr_warmup_fraction 0.05 \
    --min_lr 1e-5 \
    --wandb_project moe-train \
    --wandb_exp_name "${EXP_NAME}" \
    --output_dir "megatron_output/${EXP_NAME}" \
    --eval_steps 20 \
    --save_steps 20 \
    --logging_steps 5 \
    --max_length 32000 \
    --dataloader_num_workers 8 \
    --dataset_num_proc 8 \
    --no_save_optim true \
    --no_save_rng true \
    --tensor_model_parallel_size 2 \
    --sequence_parallel true \
    --attention_backend flash \
    --padding_free false \
    --use_rslora \
    --enable_channel_loss \

数据为纯文本数据 其他可能相关的库版本 megatron-core 0.15.0 pynvml 13.0.1

Additional Information / 补充信息

No response

ooochen-30 avatar Mar 06 '26 09:03 ooochen-30

    def _get_energy(self) -> int:
        print('='*30)
        print('_get_energy')
        print('='*30)
        return self._last_energy  # return *something* if it errors

I deleted the /root/.cache/modelscope/ directory and modified megatron/core/energy_monitor.py by adding print statements for debugging. However, based on the error logs, it appears that the execution never reached this modified code.

[rank0]:     return func(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 3301, in gather_object
[rank0]:     gather(
[rank0]:   File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper
[rank0]:     return func(*args, **kwargs)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^
[rank0]:   File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 4201, in gather
[rank0]:     work = group.gather(output_tensors, input_tensors, opts)
[rank0]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: RuntimeError: NCCL Error 1: unhandled cuda error (run with NCCL_DEBUG=INFO for details)
[rank0]:[W306 17:49:11.396078039 ProcessGroupNCCL.cpp:1538] Warning: WARNING: destroy_process_group() was not called before program exit, which can leak resources. For more info, please see https://pytorch.org/docs/stable/distributed.html#shutdown (function operator())
W0306 17:49:20.478000 660976 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 661042 closing signal SIGTERM
W0306 17:49:20.481000 660976 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 661043 closing signal SIGTERM

ooochen-30 avatar Mar 06 '26 10:03 ooochen-30

Checklist / 检查清单

  • [x] I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。

Bug Description / Bug 描述

save_steps/eval_steps=5 正常 save_steps/eval_steps=10 iter=10/20都正常 save_steps/eval_steps=20 iter=20 保存权重时报错如下(20->200一样)

2026-01-09 17:40:31.169301 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/base.py", line 223, in save 2026-01-09 17:40:31.169303 master-0 >> [rank7]: async_request = self.async_save(sharded_state_dict, checkpoint_dir) 2026-01-09 17:40:31.169305 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169306 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/torch.py", line 764, in async_save 2026-01-09 17:40:31.169307 master-0 >> [rank7]: ) = save_state_dict_async_plan( 2026-01-09 17:40:31.169309 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.16931 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/state_dict_saver.py", line 141, in save_state_dict_async_plan 2026-01-09 17:40:31.169312 master-0 >> [rank7]: all_local_plans = dist_wrapper.gather_object(local_plan) 2026-01-09 17:40:31.169313 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169315 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/checkpoint/utils.py", line 135, in gather_object 2026-01-09 17:40:31.169318 master-0 >> [rank7]: dist.gather_object( 2026-01-09 17:40:31.169319 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper 2026-01-09 17:40:31.169321 master-0 >> [rank7]: return func(*args, **kwargs) 2026-01-09 17:40:31.169322 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169324 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 3301, in gather_object 2026-01-09 17:40:31.169325 master-0 >> [rank7]: gather( 2026-01-09 17:40:31.169327 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper 2026-01-09 17:40:31.169328 master-0 >> [rank7]: return func(*args, **kwargs) 2026-01-09 17:40:31.16933 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169331 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 4201, in gather 2026-01-09 17:40:31.169333 master-0 >> [rank7]: work = group.gather(output_tensors, input_tensors, opts) 2026-01-09 17:40:31.169334 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169336 master-0 >> [rank7]: RuntimeError: NCCL Error 1: unhandled cuda error (run with NCCL_DEBUG=INFO for details) 2026-01-09 17:41:12.871213 master-0 >> [rank7]:[W109 17:41:12.150540851 ProcessGroupNCCL.cpp:1538] Warning: WARNING: destroy_process_group() was not called before program exit, which can leak resources. For more info, please see https://pytorch.org/docs/stable/distributed.html#shutdown (function operator()) 2026-01-09 17:41:22.907089 master-0 >> W0109 17:41:22.906000 74 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 139 closing signal SIGTERM 按照#5594 改动megatron/core/energy_monitor.py如下没有效果

# def _get_energy(self) -> int:
#     """Get current energy consumption from NVML."""
#     try:
#         return nvmlDeviceGetTotalEnergyConsumption(self._handle)
#     except NVMLError:
#         return self._last_energy  # return *something* if it errors
def _get_energy(self) -> int:
    return self._last_energy  # return *something* if it errors

@Jintao-Huang

How to Reproduce / 如何复现

环境是官方提供的镜像modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.9.1-py311-torch2.8.0-vllm0.11.0-modelscope1.32.0-swift3.11.3 并升级或安装下面的库 pip install transformers=5.2.0 pip install peft -U pip install ms-swift==4.0.0 pip install flash-linear-attention==0.4.1 pip install casual-conv1d # https://github.com/Dao-AILab/causal-conv1d/releases/tag/v1.6.0 以及flash-attn-v3

设备是8卡H100 微调脚本如下

export SWIFT_PATCH_CONV3D=False

EXP_NAME="xxx"

export PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' export NPROC_PER_NODE=8 export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 megatron sft
--model /workspace/models/pretrained/Qwen3.5-35B-A3B
--dataset "/workspace/swift_channel.jsonl"
--load_from_cache_file true
--add_non_thinking_prefix true
--split_dataset_ratio 0.02
--train_type lora
--lora_rank 16
--lora_alpha 32
--target_modules all-linear
--expert_model_parallel_size 4
--moe_permute_fusion true
--moe_grouped_gemm true
--moe_shared_expert_overlap true
--moe_aux_loss_coeff 5e-4
--micro_batch_size 1
--global_batch_size 128
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 1
--num_train_epochs 3
--finetune true
--freeze_llm false
--freeze_vit true
--freeze_aligner true
--cross_entropy_loss_fusion true
--lr 5e-5
--lr_warmup_fraction 0.05
--min_lr 1e-5
--wandb_project moe-train
--wandb_exp_name "${EXP_NAME}"
--output_dir "megatron_output/${EXP_NAME}"
--eval_steps 20
--save_steps 20
--logging_steps 5
--max_length 32000
--dataloader_num_workers 8
--dataset_num_proc 8
--no_save_optim true
--no_save_rng true
--tensor_model_parallel_size 2
--sequence_parallel true
--attention_backend flash
--padding_free false
--use_rslora
--enable_channel_loss
数据为纯文本数据 其他可能相关的库版本 megatron-core 0.15.0 pynvml 13.0.1

Additional Information / 补充信息

No response

I have same problem?Do you solve it?

ga546 avatar Mar 08 '26 07:03 ga546

我也遇到这个相同的问题,也是保存的时候gather爆显存

[rank0]: File "/usr/local/lib64/python3.11/site-packages/torch/distributed/checkpoint/utils.py", line 135, in gather_object [rank0]: dist.gather_object( [rank0]: File "/usr/local/lib64/python3.11/site-packages/torch/distributed/c10d_logger.py", line 83, in wrapper [rank0]: return func(*args, **kwargs) [rank0]: ^^^^^^^^^^^^^^^^^^^^^ [rank0]: File "/usr/local/lib64/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 3384, in gather_object [rank0]: gather( [rank0]: File "/usr/local/lib64/python3.11/site-packages/torch/distributed/c10d_logger.py", line 83, in wrapper [rank0]: return func(*args, **kwargs) [rank0]: ^^^^^^^^^^^^^^^^^^^^^ [rank0]: File "/usr/local/lib64/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 4340, in gather [rank0]: work = group.gather(output_tensors, input_tensors, opts)

保存的时候,我发现会gather到rank0 ,此时会爆内从,然后报nccl错误。这个有什么经验吗~~

Oukaishen avatar Mar 23 '26 07:03 Oukaishen

请问一下,解决了吗

fj1024 avatar Mar 26 '26 06:03 fj1024

Checklist / 检查清单

  • [x] I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。

Bug Description / Bug 描述

save_steps/eval_steps=5 正常 save_steps/eval_steps=10 iter=10/20都正常 save_steps/eval_steps=20 iter=20 保存权重时报错如下(20->200一样) 2026-01-09 17:40:31.169301 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/base.py", line 223, in save 2026-01-09 17:40:31.169303 master-0 >> [rank7]: async_request = self.async_save(sharded_state_dict, checkpoint_dir) 2026-01-09 17:40:31.169305 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169306 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/torch.py", line 764, in async_save 2026-01-09 17:40:31.169307 master-0 >> [rank7]: ) = save_state_dict_async_plan( 2026-01-09 17:40:31.169309 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.16931 master-0 >> [rank7]: File "/root/.cache/modelscope/_github/Megatron-LM/megatron/core/dist_checkpointing/strategies/state_dict_saver.py", line 141, in save_state_dict_async_plan 2026-01-09 17:40:31.169312 master-0 >> [rank7]: all_local_plans = dist_wrapper.gather_object(local_plan) 2026-01-09 17:40:31.169313 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169315 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/checkpoint/utils.py", line 135, in gather_object 2026-01-09 17:40:31.169318 master-0 >> [rank7]: dist.gather_object( 2026-01-09 17:40:31.169319 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper 2026-01-09 17:40:31.169321 master-0 >> [rank7]: return func(*args, **kwargs) 2026-01-09 17:40:31.169322 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169324 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 3301, in gather_object 2026-01-09 17:40:31.169325 master-0 >> [rank7]: gather( 2026-01-09 17:40:31.169327 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/c10d_logger.py", line 81, in wrapper 2026-01-09 17:40:31.169328 master-0 >> [rank7]: return func(*args, **kwargs) 2026-01-09 17:40:31.16933 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169331 master-0 >> [rank7]: File "/usr/local/lib/python3.11/site-packages/torch/distributed/distributed_c10d.py", line 4201, in gather 2026-01-09 17:40:31.169333 master-0 >> [rank7]: work = group.gather(output_tensors, input_tensors, opts) 2026-01-09 17:40:31.169334 master-0 >> [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2026-01-09 17:40:31.169336 master-0 >> [rank7]: RuntimeError: NCCL Error 1: unhandled cuda error (run with NCCL_DEBUG=INFO for details) 2026-01-09 17:41:12.871213 master-0 >> [rank7]:[W109 17:41:12.150540851 ProcessGroupNCCL.cpp:1538] Warning: WARNING: destroy_process_group() was not called before program exit, which can leak resources. For more info, please see https://pytorch.org/docs/stable/distributed.html#shutdown (function operator()) 2026-01-09 17:41:22.907089 master-0 >> W0109 17:41:22.906000 74 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 139 closing signal SIGTERM 按照#5594 改动megatron/core/energy_monitor.py如下没有效果

# def _get_energy(self) -> int:
#     """Get current energy consumption from NVML."""
#     try:
#         return nvmlDeviceGetTotalEnergyConsumption(self._handle)
#     except NVMLError:
#         return self._last_energy  # return *something* if it errors
def _get_energy(self) -> int:
    return self._last_energy  # return *something* if it errors

@Jintao-Huang

How to Reproduce / 如何复现

环境是官方提供的镜像modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.9.1-py311-torch2.8.0-vllm0.11.0-modelscope1.32.0-swift3.11.3 并升级或安装下面的库 pip install transformers=5.2.0 pip install peft -U pip install ms-swift==4.0.0 pip install flash-linear-attention==0.4.1 pip install casual-conv1d # https://github.com/Dao-AILab/causal-conv1d/releases/tag/v1.6.0 以及flash-attn-v3 设备是8卡H100 微调脚本如下 export SWIFT_PATCH_CONV3D=False EXP_NAME="xxx" export PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' export NPROC_PER_NODE=8 export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 megatron sft --model /workspace/models/pretrained/Qwen3.5-35B-A3B --dataset "/workspace/swift_channel.jsonl" --load_from_cache_file true --add_non_thinking_prefix true --split_dataset_ratio 0.02 --train_type lora --lora_rank 16 --lora_alpha 32 --target_modules all-linear --expert_model_parallel_size 4 --moe_permute_fusion true --moe_grouped_gemm true --moe_shared_expert_overlap true --moe_aux_loss_coeff 5e-4 --micro_batch_size 1 --global_batch_size 128 --recompute_granularity full --recompute_method uniform --recompute_num_layers 1 --num_train_epochs 3 --finetune true --freeze_llm false --freeze_vit true --freeze_aligner true --cross_entropy_loss_fusion true --lr 5e-5 --lr_warmup_fraction 0.05 --min_lr 1e-5 --wandb_project moe-train --wandb_exp_name "${EXP_NAME}" --output_dir "megatron_output/${EXP_NAME}" --eval_steps 20 --save_steps 20 --logging_steps 5 --max_length 32000 --dataloader_num_workers 8 --dataset_num_proc 8 --no_save_optim true --no_save_rng true --tensor_model_parallel_size 2 --sequence_parallel true --attention_backend flash --padding_free false --use_rslora --enable_channel_loss 数据为纯文本数据 其他可能相关的库版本 megatron-core 0.15.0 pynvml 13.0.1

Additional Information / 补充信息

No response

I have same problem?Do you solve it?

请问一下,解决了吗

fj1024 avatar Mar 26 '26 06:03 fj1024

try use main branch. It looks like an OOM issue.

Jintao-Huang avatar Mar 26 '26 07:03 Jintao-Huang

应该是OOM的问题,我试了好几个issue都没办法解决,在代码里加了下面这段,可以试一下

# ms-swift/swift/megatron/trainers/base.py
def save_checkpoint(self):
        args = self.args
        state = self.state
        args.consumed_train_samples = state.consumed_train_samples
        iteration = state.iteration
        output_dir = os.path.join(args.output_dir, f'checkpoint-{iteration}')
        os.makedirs(output_dir, exist_ok=True)
        args_path = os.path.join(os.path.dirname(output_dir), 'args.json')
        self.copy_path(args_path, os.path.join(output_dir, 'args.json'))
        save_peft_format = args.tuner_type == 'lora' and not args.merge_lora
        if args.save_safetensors and args.no_save_optim:
            model = []
        else:
            model = self.wrapped_models

        #=========这一段=========
        import gc
        import torch
        
        # 1. 强制进行 Python 垃圾回收
        gc.collect()  
        
        # 2. 强行清空 CUDA 缓存,将所有未使用的显存碎片重新拼合成大块连续显存
        if torch.cuda.is_available():
            torch.cuda.empty_cache()
            
        print(f"[Rank {torch.distributed.get_rank() if torch.distributed.is_initialized() else 0}] Cleaned CUDA cache before saving checkpoint {iteration}", flush=True)
        #=========这一段=========
        save_mcore_checkpoint(...)

ooochen-30 avatar Apr 01 '26 12:04 ooochen-30