[Bug][Megatron] megatron sft + lora 训练 MoE 模型,target_modules 含 linear_fc1/linear_fc2 时报错 TERowParallelLinear is not supported
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- backend, machine-learning
Research direction
Start with the Megatron LoRA adapter setup in swift/megatron/utils/utils.py and the PEFT integration in swift/tuners/peft.py, where the traceback shows adapter injection reaches PEFT's module replacement. Check how TERowParallelLinear is handled for all-linear versus explicit target modules, then reproduce with the listed Megatron SFT command and linear_fc1/linear_fc2. Done means those explicit targets inject LoRA successfully for the reported MoE setup.
Written by the indexing model from the issue text.
Description
Checklist / 检查清单
- I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
910B2使用 Megatron-SWIFT 对 MoE 模型(Qwen/Qwen3-30B-A3B,请改成你的实际模型)做 LoRA 微调。参考文档中 Megatron 的参数映射(linear_proj 对应 o_proj,linear_fc1 对应 gate_proj,up_proj,linear_fc2 对应 down_proj),将 target_modules 设置为:--target_modules linear_qkv linear_proj linear_fc1 linear_fc2
在注入 LoRA 时报错:> ValueError: Target module TERowParallelLinear() is not supported. Currently, only the following modules are supported: torch.nn.Linear, torch.nn.Embedding, ...
完整报错
[rank0]: Traceback (most recent call last):
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/cli/_megatron/sft.py", line 7, in
[rank0]: megatron_sft_main()
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/pipelines/train/sft.py", line 93, in megatron_sft_main
[rank0]: return MegatronSft(args).main()
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/pipelines/base.py", line 52, in main
[rank0]: result = self.run()
[rank0]: ^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/pipelines/train/sft.py", line 66, in run
[rank0]: trainer = self.prepare_trainer()
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/pipelines/train/sft.py", line 34, in prepare_trainer
[rank0]: return MegatronTrainer(self.args, self.template)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/trainers/base.py", line 79, in init
[rank0]: self.prepare_model()
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/trainers/base.py", line 201, in prepare_model
[rank0]: self.peft_models = self._prepare_peft_model(self.unwrapped_models)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/trainers/base.py", line 208, in _prepare_peft_model
[rank0]: peft_models = [prepare_mcore_model(args, model) for model in models]
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/trainers/base.py", line 208, in
[rank0]: peft_models = [prepare_mcore_model(args, model) for model in models]
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/utils/utils.py", line 200, in prepare_mcore_model
[rank0]: model = prepare_adapter(args, model)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/megatron/utils/utils.py", line 153, in prepare_adapter
[rank0]: model = Swift.prepare_model(model, lora_config)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/tuners/base.py", line 720, in prepare_model
[rank0]: return get_peft_model(model, config, **kwargs)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/mapping_func.py", line 122, in get_peft_model
[rank0]: return MODEL_TYPE_TO_PEFT_MODEL_MAPPING[peft_config.task_type](
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/peft_model.py", line 2063, in init
[rank0]: super().init(model, peft_config, adapter_name, **kwargs)
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/peft_model.py", line 164, in init
[rank0]: self.base_model = cls(model, {adapter_name: peft_config}, adapter_name)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/tuners/peft.py", line 363, in new_init
[rank0]: self.init_origin(model, config, *args, **kwargs)
[rank0]: File "/home/jovyan/wzx/downloads/mcore-bridge-new/mcore-bridge-main/src/mcore_bridge/tuners/patcher.py", line 48, in new_init
[rank0]: origin_init(self, *args, **kwargs)
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/tuners/tuners_utils.py", line 318, in init
[rank0]: self.inject_adapter(self.model, adapter_name, low_cpu_mem_usage=low_cpu_mem_usage, state_dict=state_dict)
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/tuners/tuners_utils.py", line 917, in inject_adapter
[rank0]: self._create_and_replace(
[rank0]: File "/home/jovyan/huangwy/frameworks/latest/ms-swift/swift/tuners/peft.py", line 133, in _create_and_replace_hook
[rank0]: return self._create_and_replace_origin(peft_config, adapter_name, target, *args, **kwargs)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/tuners/lora/model.py", line 281, in _create_and_replace
[rank0]: new_module = self._create_new_module(lora_config, adapter_name, target, device_map=device_map, **kwargs)
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[rank0]: File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/peft/tuners/lora/model.py", line 436, in _create_new_module
[rank0]: raise ValueError(
[rank0]: ValueError: Target module TERowParallelLinear() is not supported. Currently, only the following modules are supported: torch.nn.Linear, torch.nn.Embedding, torch.nn.Conv1d, torch.nn.Conv2d, torch.nn.Conv3d, transformers.pytorch_utils.Conv1D, torch.nn.MultiheadAttention..
[ERROR] 2026-11-16-13:02:39 (PID:550818, Device:0, RankID:-1) ERR99999 UNKNOWN applicaiton exception
W1116 13:02:47.272000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550819 closing signal SIGTERM
W1116 13:02:47.276000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550820 closing signal SIGTERM
W1116 13:02:47.284000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550821 closing signal SIGTERM
W1116 13:02:47.293000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550822 closing signal SIGTERM
W1116 13:02:47.320000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550823 closing signal SIGTERM
W1116 13:02:47.347000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550824 closing signal SIGTERM
W1116 13:02:47.368000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:900] Sending process 550825 closing signal SIGTERM
E1116 13:02:55.733000 550643 site-packages/torch/distributed/elastic/multiprocessing/api.py:874] failed (exitcode: 1) local_rank: 0 (pid: 550818) of binary: /home/jovyan/.conda/envs/ms-swift-latest/bin/python3.11
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/torch/distributed/run.py", line 896, in
main()
File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/torch/distributed/elastic/multiprocessing/errors/init.py", line 355, in wrapper
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/torch/distributed/run.py", line 892, in main
run(args)
File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/torch/distributed/run.py", line 883, in run
elastic_launch(
File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 139, in call
return launch_agent(self._config, self._entrypoint, list(args))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/jovyan/.conda/envs/ms-swift-latest/lib/python3.11/site-packages/torch/distributed/launcher/api.py", line 270, in launch_agent
--target_modules设置为all-linear运行正常
How to Reproduce / 如何复现
ascend 910b2
gpytorch 1.15.2
mcore_bridge 1.7.0.dev0
megatron-core 0.16.1
ms_swift 4.6.0.dev0
peft 0.20.0
torch 2.7.1
torch_npu 2.7.1.post2
torchaudio 2.7.1
torchvision 0.22.1
NPROC_PER_NODE=8
megatron sft
--model
--model_type 'qwen3_moe'
--check_model false
--nccl_comm_warmup true
--template 'qwen3_nothinking'
--save_safetensors true
--merge_lora false
--dataset
--tuner_type lora
--lora_rank 32
--lora_alpha 64
--lora_dropout 0.05
--target_modules all-linear
--load_from_cache_file true
--expert_model_parallel_size 8
--moe_permute_fusion true
--moe_grouped_gemm true
--moe_shared_expert_overlap true
--moe_aux_loss_coeff 1e-2
--packing true
--micro_batch_size 1
--global_batch_size 56
--recompute_granularity full
--recompute_method uniform
--recompute_num_layers 1
--num_train_epochs 2
--finetune true
--lr 3e-5
--lr_warmup_fraction 0.1
--output_dir megatron_output/Qwen3-30B-A3B/double-task-mix/SFT
--save_strategy epoch
--max_length 25201
--dataloader_num_workers 4
--dataset_num_proc 128
--no_save_optim true
--no_save_rng true
--sequence_parallel true
--cross_entropy_loss_fusion true
--gradient_accumulation_fusion false
--cross_entropy_fusion_impl native
--attention_backend flash
Additional Information / 补充信息
No response
- Dominant language
- Python
- Stars
- 16.2k
- Forks
- 1.8k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 68
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelscope/ms-swift
-
get_multimodal_target_regex(..., exclude_router=True) does not exclude shared_expert_gatePossibly taken @KonnyakuMatcha claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10696 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss crashes with beta>0 and kl_in_reward=True (NoneType * Tensor)Possibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelscope/ms-swift#10690 ·
Maintainers usually reply within 1 day
-
[BUG] GRPO REAL loss divides by all groups instead of valid groups, silently scaling gradientsPossibly taken @newcloud123 claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
modelscope/ms-swift#10688 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 Half a day Newbie friendliness 62/100
modelscope/ms-swift#10621 ·
Maintainers usually reply within 1 day
-
[Bug] `get_seed` consumes a draw from the shared RandomState even when decision augmentation is disabled, changing the train/val split and dataset shufflePossibly taken @ryznren claimed this 38 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelscope/ms-swift#10466 · 1 comment ·
Maintainers usually reply within 1 day
All issues in modelscope/ms-swift
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day