Prhub

#46341 [Bugfix] Fix Llama4ForCausalLM initialization test failure

原始 PR 作者 zhenwei-intel 合并时间 2026-06-22 16:40 文件变更 1 提交数 1 评论 0 代码增减 +7 / -1

执行摘要

修复 Llama4ForCausalLM 测试初始化失败

dummy_hf_overrides 只对 Llama4ForConditionalGeneration 设置了 num_experts_per_tok=1,导致 Llama4ForCausalLMEagleLlama4ForCausalLM 获得 num_experts_per_tok=2,这与 apply_router_weight_on_input=True 特性冲突(该特性仅支持 topk=1),造成测试初始化失败。

值得立即合入。变更逻辑简单明确,修复了测试基础设施中的 bug,确保了三个 Llama4 变体的测试一致性。

讨论亮点

无 review 评论。PR 由 reviewer DarkLight1337 直接批准,表明变更清晰无争议。

实现拆解

tests/models/utils.py 的 MoE 配置段中,将原先的简单条件判断 if model_arch == "Llama4ForConditionalGeneration" 扩展为检查一个元组 ("Llama4ForConditionalGeneration", "Llama4ForCausalLM", "EagleLlama4ForCausalLM"),使得这三个 Llama4 变体类型都会将 num_experts_per_tok 设为 1,从而与 apply_router_weight_on_input 约束一致。变更仅涉及该文件,无其他依赖。

文件 模块 状态 重要度
tests/models/utils.py 测试工具 modified 4.96

关键源码片段

tests/models/utils.py test-coverage

修复测试初始化中 MoE 参数配置的 bug,是所有变更的载体。

# tests/models/utils.py (partial)
    if model_arch_config.num_experts > 0:
        # 默认 num_experts_per_tok = 2,但 Llama4 系列需要 topk=1
        # 因为 apply_router_weight_on_input 只支持 topk=1
        num_experts_per_tok = 2
        if model_arch in (
            "Llama4ForConditionalGeneration",
            "Llama4ForCausalLM",
            "EagleLlama4ForCausalLM",
        ):
            num_experts_per_tok = 1
        update_dict.update(
            {
                "num_experts": num_experts,
                "num_experts_per_tok": num_experts_per_tok,
                # Kimi 使用 num_experts_per_token
                "num_experts_per_token": num_experts_per_tok,
                "num_local_experts": num_experts,
                # 否则不会有任何 expert 层
                "first_k_dense_replace": 0,
                # 避免 DeepSeek-V3 上的 OOM
                "n_routed_experts": num_experts,
            }
        )

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

低风险。变更仅在测试配置辅助函数中,调整了 MoE 参数设置的条件分支,不影响任何生产逻辑。风险点在于若未来新增 Llama4 变体但忘记更新此元组,可能导致类似问题,但该模式已有提示。

仅影响 tests/models/utils.py 中的测试初始化流程,确保 Llama4ForCausalLMEagleLlama4ForCausalLM 的单元测试能正确运行。对系统性能、安全、兼容性无影响。

仅测试文件 低风险

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论