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

NPU运行Qwen3-30B-A3B GRPO训练报错

Open yingzhao27 opened this issue 10 months ago • 15 comments

Describe the bug What the bug is, and how to reproduce, better with screenshots(描述bug以及复现过程,最好有截图) 运行moe模型的grpo训练,报错: INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK INFO: 127.0.0.1:41874 - "POST /update_named_param/ HTTP/1.1" 200 OK (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] WorkerProc hit an exception. (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] Traceback (most recent call last): (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/vllm/v1/executor/multiproc_executor.py", line 666, in worker_busy_loop (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] output = func(*args, **kwargs) (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/zy_exp/other/ms-swift-1219/swift/llm/infer/rollout.py", line 88, in update_named_param (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] self.model_runner.model.load_weights(weights=[(name, weight)]) (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/vllm/model_executor/models/qwen3_moe.py", line 689, in load_weights (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] return loader.load_weights(weights) (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/vllm/model_executor/models/utils.py", line 294, in load_weights (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] autoloaded_weights = set(self._load_module("", self.module, weights)) (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/vllm/model_executor/models/utils.py", line 252, in _load_module (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] yield from self._load_module(prefix, (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/vllm/model_executor/models/utils.py", line 225, in _load_module (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] loaded_params = module_load_weights(weights) (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/vllm/model_executor/models/qwen3_moe.py", line 526, in load_weights (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] param.weight_loader) (Worker_TP1 pid=111938) ERROR 01-07 17:21:12 [multiproc_executor.py:671] AttributeError: 'Parameter' object has no attribute 'weight_loader'

Your hardware and system info Write your system info like CUDA version/system/GPU/torch version here(在这里给出硬件信息和系统信息,如CUDA版本,系统,GPU型号和torch版本等) Ascend 910B3, torch/torch_npu=2.7.1, vllm/vllm_ascend=0.11.0

Additional context Add any other context about the problem here(在这里补充其他信息) (1)vllm server启动命令:ASCEND_RT_VISIBLE_DEVICES=2,3 swift rollout --model ./Qwen/Qwen3-30B-A3B --vllm_tensor_parallel_size 2 --vllm_max_model_len 16384 --vllm_enable_prefix_caching true (2)train启动命令:ASCEND_RT_VISIBLE_DEVICES=4,5,6,7 NPROC_PER_NODE=4 swift rlhf --rlhf_type grpo --model ./Qwen/Qwen3-30B-A3B --reward_funcs format --use_vllm true --vllm_mode server --vllm_server_host 127.0.0.1 --vllm_server_port 8000 --train_type lora --torch_dtype bfloat16 --dataset /yunpan/zy_exp/LW97.LT23054_llm_trainer/model_test/alpaca_long_long.json --split_dataset_ratio 0 --save_steps 200 --max_completion_length 8192 --max_length 8192 --num_train_epochs 1 --per_device_train_batch_size 1 --learning_rate 2e-5 --gradient_accumulation_steps 1 --logging_steps 1 --warmup_ratio 0.05 --dataloader_num_workers 4 --dataset_num_proc 4 --num_generations 2 --temperature 0.3 --deepspeed zero3_offload --log_completions true --num_iterations 1 --beta 0.001 --enable_flattened_weight_sync false --loss_type sapo --tau_pos 1.0 --tau_neg 1.05 --importance_sampling_level token --steps_per_generation 2 --move_model_batches 16

yingzhao27 avatar Jan 07 '26 09:01 yingzhao27

can you retry with following requirement?

pip install git+https://github.com/hjh0119/swift.git@patch-weight-load

hjh0119 avatar Jan 07 '26 10:01 hjh0119

can you retry with following requirement?

pip install git+https://github.com/hjh0119/swift.git@patch-weight-load

I userd it but it doesn't work. I am runing megatron grpo colocate mode.

vx120 avatar Jan 12 '26 04:01 vx120

can you retry with following requirement?

pip install git+https://github.com/hjh0119/swift.git@patch-weight-load

不报上面的错了 但是一直OOM。30b, 8卡64G的不应该oom吧 32b的模型都能跑

yingzhao27 avatar Jan 12 '26 06:01 yingzhao27

发下oom的报错栈

hjh0119 avatar Jan 12 '26 07:01 hjh0119

@vx120 please provide more details, including reproduce script and env infos

hjh0119 avatar Jan 12 '26 07:01 hjh0119

@vx120 please provide more details, including reproduce script and env infos

命令是 ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
NPROC_PER_NODE=8
megatron rlhf
--rlhf_type grpo
--model ./Qwen3-30B-A3B-Instruct-2507/Qwen3-30B-A3B-Instruct-2507_20250730_01
--model_type 'qwen3_moe'
--load_safetensors true
--save_safetensors true
--context_parallel_size 1
--sequence_parallel true
--tensor_model_parallel_size 2
--expert_model_parallel_size 4
--pipeline_model_parallel_size 1
--dataset './NuminaMath-TIR.jsonl'
--max_epochs 1
--global_batch_size 8
--micro_batch_size 1
--steps_per_generation 1
--num_generations 2
--reward_funcs accuracy format
--use_vllm true
--vllm_mode colocate
--vllm_gpu_memory_utilization 0.3
--vllm_tensor_parallel_size 4
--vllm_max_model_len 512
--max_length 512
--max_completion_length 512
--train_type lora
--lr 1e-6
--loss_type grpo
--sleep_level 2
--offload_model true
--offload_optimizer true
--optimizer_cpu_offload true
--use_precision_aware_optimizer
--log_interval 1
--num_workers 8
--dataset_num_proc 8
--no_save_optim
--no_save_rng
--attention_backend flash
--temperature 1.0
--padding_free true
--no_gradient_accumulation_fusion true
--no_masked_softmax_fusion true
--log_completions true \

依赖版本同样是Ascend 910B3, torch/torch_npu=2.7.1, vllm/vllm_ascend=0.11.0

报错内容如下 [rank7]: Traceback (most recent call last): [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/cli/_megatron/rlhf.py", line 7, in [rank7]: megatron_rlhf_main() [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/train/rlhf.py", line 78, in megatron_rlhf_main [rank7]: return MegatronRLHF(args).main() [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/llm/base.py", line 49, in main [rank7]: result = self.run() [rank7]: ^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/train/sft.py", line 77, in run [rank7]: self.trainer.train(train_dataset, val_dataset, data_collator) [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/grpo_trainer.py", line 72, in train [rank7]: super().train(train_dataset, val_dataset, data_collator) [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/base.py", line 1098, in train [rank7]: pretrain( [rank7]: File "/Megatron-LM/megatron/training/training.py", line 801, in pretrain [rank7]: iteration, num_floating_point_operations_so_far = train( [rank7]: ^^^^^^ [rank7]: File "/Megatron-LM/megatron/training/training.py", line 1993, in train [rank7]: train_step(forward_step_func, [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/base.py", line 564, in train_step [rank7]: new_data_iterator = self._replace_data_iterator(data_iterator, model) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/grpo_trainer.py", line 279, in _replace_data_iterator [rank7]: micro_batch_data = self._generate_and_score_completions(rollout_batch) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/grpo_trainer.py", line 304, in _generate_and_score_completions [rank7]: rollout_batch = self._generate_completions(rollout_batch) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/utils.py", line 168, in wrapper [rank7]: return func(self, *args, **kwargs) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/grpo_trainer.py", line 486, in _generate_completions [rank7]: self._move_model_to_vllm() [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/utils.py", line 168, in wrapper [rank7]: return func(self, *args, **kwargs) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/rollout_mixin.py", line 293, in _move_model_to_vllm [rank7]: self._export_and_load_weights() [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/swift/megatron/trainers/rollout_mixin.py", line 314, in _export_and_load_weights [rank7]: llm_model.load_weights(weight_iterator) [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/vllm/model_executor/models/qwen3_moe.py", line 689, in load_weights [rank7]: return loader.load_weights(weights) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/vllm/model_executor/models/utils.py", line 294, in load_weights [rank7]: autoloaded_weights = set(self._load_module("", self.module, weights)) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/vllm/model_executor/models/utils.py", line 252, in _load_module [rank7]: yield from self._load_module(prefix, [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/vllm/model_executor/models/utils.py", line 225, in _load_module [rank7]: loaded_params = module_load_weights(weights) [rank7]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [rank7]: File "/usr/local/python3.11.13/lib/python3.11/site-packages/vllm/model_executor/models/qwen3_moe.py", line 526, in load_weights [rank7]: param.weight_loader) [rank7]: ^^^^^^^^^^^^^^^^^^^ [rank7]: AttributeError: 'Parameter' object has no attribute 'weight_loader'

vx120 avatar Jan 12 '26 07:01 vx120

@vx120 plz retry with pip install git+https://github.com/hjh0119/swift.git@path-weight-load-clean

hjh0119 avatar Jan 12 '26 08:01 hjh0119

发下oom的报错栈

Train: 0%| | 0/6 [00:00<?, ?it/s][rank5]: Traceback (most recent call last): [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/cli/rlhf.py", line 7, in [rank5]: rlhf_main() [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/llm/train/rlhf.py", line 233, in rlhf_main [rank5]: return SwiftRLHF(args).main() [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/llm/base.py", line 49, in main [rank5]: result = self.run() [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/ray/base.py", line 170, in wrapper [rank5]: return func(self, *args, **kwargs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/llm/train/sft.py", line 210, in run [rank5]: return self.train(trainer) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/llm/train/sft.py", line 258, in train [rank5]: trainer.train(trainer.args.resume_from_checkpoint) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/mixin.py", line 880, in train [rank5]: res = super().train(*args, **kwargs) [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/transformers/trainer.py", line 2331, in train [rank5]: return inner_training_loop( [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/transformers/trainer.py", line 2680, in _inner_training_loop [rank5]: tr_loss_step = self.training_step(model, inputs, num_items_in_batch) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/grpo_trainer.py", line 1848, in training_step [rank5]: return super().training_step(model, inputs, num_items_in_batch) [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/transformers/trainer.py", line 4020, in training_step [rank5]: inputs = self._prepare_inputs(inputs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/utils.py", line 562, in wrapper [rank5]: return func(self, *args, **kwargs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/grpo_trainer.py", line 196, in _prepare_inputs [rank5]: generation_batch = self._generate_and_score_completions(generation_batch) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/utils.py", line 562, in wrapper [rank5]: return func(self, *args, **kwargs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/grpo_trainer.py", line 229, in _generate_and_score_completions [rank5]: inputs = self._generate_completions(inputs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/grpo_trainer.py", line 210, in _generate_completions [rank5]: results = self._fast_infer(inputs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/rollout_mixin.py", line 917, in _fast_infer [rank5]: self._move_model_to_vllm() [rank5]: self._move_model_to_vllm() [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/utils.py", line 562, in wrapper [rank5]: return func(self, *args, **kwargs) [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/rollout_mixin.py", line 381, in _move_model_to_vllm [rank5]: self._move_full_model_to_vllm() [rank5]: File "/yunpan/zy_exp/other/swift-patch/swift/trainers/rlhf_trainer/rollout_mixin.py", line 660, in _move_full_model_to_vllm [rank5]: with gather_if_zero3(parameters): [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/deepspeed/runtime/zero/partition_parameters.py", line 2336, in enter [rank5]: self.params[0].all_gather(param_list=self.params) [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/deepspeed/runtime/zero/partition_parameters.py", line 1218, in all_gather [rank5]: return self._all_gather(param_list, async_op=async_op, hierarchy=hierarchy) [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/deepspeed/utils/nvtx.py", line 20, in wrapped_fn [rank5]: ret_val = func(*args, **kwargs) [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/deepspeed/runtime/zero/partition_parameters.py", line 1623, in _all_gather [rank5]: self._allgather_params_coalesced(all_gather_nonquantize_list, hierarchy, quantize=False) [rank5]: File "/yunpan/miniconda3/envs/ms_swift/lib/python3.10/site-packages/deepspeed/runtime/zero/partition_parameters.py", line 1912, in _allgather_params_coalesced [rank5]: flat_tensor = torch.empty(tensor_size, dtype=param_list[0].ds_tensor.dtype, [rank5]: RuntimeError: NPU out of memory. Tried to allocate 20.00 MiB (NPU 5; 60.96 GiB total capacity; 52.78 GiB already allocated; 52.78 GiB current active; 668.00 KiB free; 60.20 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.

我的move_model_batches已经设置为2了

yingzhao27 avatar Jan 12 '26 08:01 yingzhao27

我的move_model_batches已经设置为2了

设大一点再试试

hjh0119 avatar Jan 12 '26 08:01 hjh0119

我的move_model_batches已经设置为2了

设大一点再试试

设置为16 32都是OOM

yingzhao27 avatar Jan 12 '26 09:01 yingzhao27

@hjh0119 请问这个问题和move_model_batches有关吗 还是什么其他原因导致的

yingzhao27 avatar Jan 13 '26 03:01 yingzhao27

oom发生在权重同步 zero3 gather 参数阶段,增大 move_model_batches 可以缓解

hjh0119 avatar Jan 13 '26 05:01 hjh0119

刚好我也遇到了这个问题,模型是qwen3vl-30B-A3B,打了修改的patch后,5个节点能正常训练,甚至都没改move_model_batches,可能跟训练参数有关系,而且训练速度巨慢。

JackeyGuo avatar Jan 13 '26 11:01 JackeyGuo

刚好我也遇到了这个问题,模型是qwen3vl-30B-A3B,打了修改的patch后,5个节点能正常训练,甚至都没改move_model_batches,可能跟训练参数有关系,而且训练速度巨慢。

@JackeyGuo 大佬 请问可以参考下你的训练超参吗 是5个节点还是5张卡啊

yingzhao27 avatar Jan 14 '26 02:01 yingzhao27

@yingzhao27 5个节点训练的,我是参考官方的训练脚本moe_colocate_full.sh,你也可以试试这套参数

JackeyGuo avatar Jan 19 '26 01:01 JackeyGuo