[Cherry-Pick] [FDConfig] Unify num_experts_per_tok to moe_k in ModelConfig for MoE model compatibility(#7509)#7517
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-20 16:03 CST
📋 Review 摘要
PR 概述:将 MoE 模型 config 中的 num_experts_per_tok 统一映射为 moe_k,以支持 Qwen3VLMOE、DeepSeek V3 等模型的兼容性。
变更范围:fastdeploy/config.py — ModelConfig.override_name_from_config 方法
影响面 Tag:FDConfig
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | 多个模型文件 | 下游消费方仍直接使用 num_experts_per_tok,建议统一迁移为 moe_k |
总体评价
变更逻辑正确,与同方法内 moe_num_experts/moe_num_shared_experts 的映射模式一致。not hasattr(self, "moe_k") 的守卫条件也恰当(moe_k 不在 PRETRAINED_INIT_CONFIGURATION 中,因此用 hasattr 比 is None 更合理)。建议后续跟进将下游直接引用 num_experts_per_tok 的代码统一迁移到 moe_k,以保持代码风格一致性。
| # Because the ERNIE 4.5 config.json contains two sets of keys, adaptation is required. | ||
| self.moe_num_shared_experts = self.n_shared_experts | ||
|
|
||
| if hasattr(self, "num_experts_per_tok") and not hasattr(self, "moe_k"): |
There was a problem hiding this comment.
🟡 建议 映射逻辑本身正确,但目前有多个下游文件仍直接使用 fd_config.model_config.num_experts_per_tok 而非统一后的 moe_k:
fastdeploy/model_executor/models/deepseek_v3.py:173fastdeploy/model_executor/models/qwen3moe.py:68fastdeploy/model_executor/models/gpt_oss.py:119fastdeploy/model_executor/models/glm4_moe.py:178fastdeploy/model_executor/layers/moe/routing_indices_cache.py:170(对Glm4Moe的特殊分支)
由于映射代码只赋值 self.moe_k = self.num_experts_per_tok 而未删除原属性,这些引用不会报错,不阻塞合入。但建议在后续 PR 中将上述引用统一迁移为 moe_k,与 ernie4_5_moe.py 等已使用 moe_k 的模型保持一致,减少维护歧义。
Motivation
Unify num_experts_per_tok to moe_k in ModelConfig for MoE model compatibility. This enables R3 support for models like Qwen3VLMOE, DeepSeek V3, and other MoE models that use num_experts_per_tok instead of moe_k in their config.
Modifications
Usage or Command
N/A
Accuracy Tests
N/A
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.