get_multimodal_target_regex(..., exclude_router=True) does not exclude shared_expert_gate
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend, machine-learning
Research direction
Start in swift/utils/transformers_utils.py at get_multimodal_target_regex and compare its router exclusions with get_modules_to_not_convert around line 337. Check how the regex matches mlp.shared_expert_gate while retaining gate_proj and attention projections. Done means the shared expert gate is excluded when exclude_router=True; verify with a MoE model or a focused regex test.
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 描述
In swift/utils/transformers_utils.py, get_multimodal_target_regex(..., exclude_router=True) currently excludes only 'gate' (router_modules = ['gate']) for MoE models, but does not exclude 'shared_expert_gate'.
This is inconsistent with the rest of ms-swift and causes a Megatron-to-PEFT LoRA export mismatch:
get_modules_to_not_convert(swift/utils/transformers_utils.py:337) andquant_args.pyalready treat bothmlp.gateandmlp.shared_expert_gateas MoE gating/router layers.- In HF MoE VLMs (e.g.
Qwen4-35B-A3B,Qwen3.5-MoE),shared_expert_gateis a scalarnn.Linear(hidden_size, 1, bias=False)gating the shared expert, whereas Megatron CoreSharedExpertMLPstores it as a rawnn.Parameter(gate_weight) and never attaches LoRA to it. - When
swift/megatron/init.pyexports a Megatron LoRA checkpoint to PEFT format viaget_multimodal_target_regex(..., exclude_router='all-router' not in args.target_modules), leavingshared_expert_gatein the regex causesadapter_config.jsonto targetshared_expert_gateeven though no LoRA weights exist for it.
How to Reproduce / 如何复现
ms-swift:main(ece3bcc,4.7.0.dev0)
Steps:
- Call
get_multimodal_target_regex(model, freeze_llm=False, exclude_router=True)on a MoE model containingmlp.shared_expert_gate(such asQwen/Qwen4-35B-A3BorQwen3.5-MoE). - Observe
shared_expert_gateis still matched by the returnedtarget_modulesregex (whilegateis excluded).
Additional Information / 补充信息
Keeping gate_proj and attention projections matched while excluding both gate and shared_expert_gate aligns get_multimodal_target_regex with get_modules_to_not_convert and Megatron LoRA export.
- 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
-
[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
-
[Bug] `swift --help` raises KeyError instead of showing CLI helpPossibly taken @haahy claimed this 64 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelscope/ms-swift#10287 ·
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