Skip to content

【Hackathon 10th Spring No.39】[CI] 功能模块 fused_moe_marlin_backend.py 单测补充#7750

Open
yu0809 wants to merge 1 commit intoPaddlePaddle:developfrom
yu0809:hackathon-10th-no39-marlin-tests
Open

【Hackathon 10th Spring No.39】[CI] 功能模块 fused_moe_marlin_backend.py 单测补充#7750
yu0809 wants to merge 1 commit intoPaddlePaddle:developfrom
yu0809:hackathon-10th-no39-marlin-tests

Conversation

@yu0809
Copy link
Copy Markdown

@yu0809 yu0809 commented May 8, 2026

Motivation

【Hackathon 10th Spring No.39】功能模块 fastdeploy/model_executor/layers/moe/fused_moe_marlin_backend.py 单测补充,覆盖 Marlin MoE backend 中无需真实 GPU kernel 即可稳定验证的 helper 和 dispatch 逻辑。

Modifications

新增 tests/model_executor/test_fused_moe_marlin_backend.py,通过最小模块 stub 加载目标文件,避免 CPU/macOS 本地环境依赖 Triton 或真实 Marlin kernel。

覆盖内容:

  • get_scale_perms 的 scale permutation 顺序
  • marlin_permute_scales 的 grouped / per-channel scale permutation
  • marlin_moe_permute_scales 的 per-expert scale permutation
  • gptq_marlin_moe_repack 对 Marlin repack op 的逐 expert dispatch,以及非法 size_k 校验
  • MarlinWeightOnlyMoEMethod.create_weights 注册的参数 shape / dtype
  • process_loaded_weights 的 quantization / packing 流程
  • applytopknoaux_tc 两条 top-k 路径,以及后续 GPU 预处理与 Marlin GEMM dispatch

Usage or Command

PPNLP_HOME=.cache/paddleformers .venv/bin/python -m pytest tests/model_executor/test_fused_moe_marlin_backend.py -q
git diff --check
python3 -m py_compile tests/model_executor/test_fused_moe_marlin_backend.py
PPNLP_HOME=.cache/paddleformers .venv/bin/python -m coverage run -m pytest tests/model_executor/test_fused_moe_marlin_backend.py -q
PPNLP_HOME=.cache/paddleformers .venv/bin/python -m coverage report fastdeploy/model_executor/layers/moe/fused_moe_marlin_backend.py tests/model_executor/test_fused_moe_marlin_backend.py

本地结果:

8 passed, 3 warnings in 0.55s

git diff --check: passed
python3 -m py_compile tests/model_executor/test_fused_moe_marlin_backend.py: passed

Name                                                               Stmts   Miss  Cover
--------------------------------------------------------------------------------------
fastdeploy/model_executor/layers/moe/fused_moe_marlin_backend.py     115      0   100%
tests/model_executor/test_fused_moe_marlin_backend.py                195      0   100%
--------------------------------------------------------------------------------------
TOTAL                                                                310      0   100%

Coverage CI 最终结果以仓库 CI 为准;本地目标文件覆盖率为 100%。

Accuracy Tests

无准确率影响。本 PR 只补充单元测试,不修改推理逻辑或模型输出。

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
    • 本地 venv 未安装 pre_commit 模块;已执行 git diff --checkpy_compile
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.
    • This PR targets develop.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 8, 2026

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label May 8, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 8, 2026

CLA assistant check
All committers have signed the CLA.

@yu0809 yu0809 changed the title [CI] Add marlin backend unit tests for Hackathon 10th No.39 【Hackathon 10th Spring No.39】[CI] 功能模块 fused_moe_marlin_backend.py 单测补充 May 8, 2026
@yu0809 yu0809 force-pushed the hackathon-10th-no39-marlin-tests branch from 2f19b94 to 270c7dc Compare May 8, 2026 07:31
PaddlePaddle-bot

This comment was marked as outdated.

@yu0809 yu0809 force-pushed the hackathon-10th-no39-marlin-tests branch from 270c7dc to 516ff93 Compare May 8, 2026 07:36
PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@yu0809 yu0809 force-pushed the hackathon-10th-no39-marlin-tests branch from 516ff93 to f5429df Compare May 8, 2026 07:58
@PaddlePaddle-bot
Copy link
Copy Markdown

PaddlePaddle-bot commented May 8, 2026

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-08 16:40:21

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

所有已执行任务均已通过。⚠️ 注意:7 个 Workflow 处于 action_required 状态,需人工审批后才会触发执行(含主测试流程)。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
2(0) 2 2 0 0 0 0

⚠️ 注意:以下 7 个 Workflow 处于 action_required 状态(等待审批后才会执行):Codestyle-Check、Approval、Check PR Template、CI_HPU、CI_XPU、ILUVATAR-CI、PR Build and Test。这些 Workflow 需人工审批触发。

注意:action_required workflows 不计入上表的任务统计。


2 任务状态汇总

2.1 Required任务 : 0/0 通过

必选任务阻塞合并,失败需优先处理。

当前无 required 任务(GitHub Branch Protection Rules 未配置,或 API 权限不足,所有任务均标记为可选)。

2.2 可选任务 — 2/2 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
其余 2 个可选任务通过 - - -

3 失败详情(仅 required)

无 required 失败任务。

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Paddle-CI-Agent | pr_review | 2026-05-08 16:05:27

📋 Review 摘要

PR 概述:为 Marlin MoE backend(fused_moe_marlin_backend.py)新增单元测试,通过 stub 模块加载策略在无 GPU/Triton 环境下完整覆盖 helper、dispatch 及 apply 逻辑。

变更范围tests/model_executor/test_fused_moe_marlin_backend.py

影响面 Tag[OP]

📝 PR 规范检查

描述结构通过(§D2 所有必填 section 均存在且内容充实)。

标题中 [CI] Tag 按 FastDeploy checklist 对应 .github/workflows/scripts/(CI 配置文件),而本 PR 新增的是 tests/model_executor/ 单元测试,被测模块位于 model_executor/layers/moe/,更符合 [OP] 语义。考虑到 Hackathon 任务编号中已将 CI 测试补充标记为 [CI],以下仅作参考:

标题建议(可直接复制):

  • 【Hackathon 10th Spring No.39】[OP] 功能模块 fused_moe_marlin_backend.py 单测补充

问题

级别 文件 概述
🟡 建议 tests/model_executor/test_fused_moe_marlin_backend.py:250 apply 系列测试中直接给模块属性赋 Mock,未使用 monkeypatch.setattr

总体评价

测试设计合理,stub 策略有效隔离了 GPU kernel 依赖,8 项用例本地全部通过且目标文件覆盖率达 100%。建议在 apply 系列测试中改用 monkeypatch.setattr 替换模块属性,以提升写法规范性与可维护性。

topk_ids = paddle.to_tensor([[0, 1], [1, 2], [2, 3]], dtype="int32")
topk_weights = paddle.ones([3, layer.top_k], dtype="float32")
hook = Mock()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 apply 系列测试中通过直接赋值给模块属性打 Mock:

marlin.tritonmoe_preprocess_func = Mock(...)
marlin.MoeWna16MarlinGemmApi = Mock(...)

当前结构下(每次测试均通过 _load_marlin_backend 重新加载模块),不会造成跨测试污染,但直接修改模块属性未经 monkeypatch 管理,后续若有人复用 marlin 对象可能产生意外副作用。

建议改为:

monkeypatch.setattr(marlin, "tritonmoe_preprocess_func", Mock(...))
monkeypatch.setattr(marlin, "MoeWna16MarlinGemmApi", Mock(...))

同样的写法也出现在 test_apply_uses_noaux_tc_score_path(约第 316、323 行)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants