Skip to content

[Cherry-Pick][Optimization] merge matmul and add(#6986) #7184

Open
BingooYang wants to merge 1 commit intoPaddlePaddle:release/2.5from
BingooYang:2.5/linear_opt
Open

[Cherry-Pick][Optimization] merge matmul and add(#6986) #7184
BingooYang wants to merge 1 commit intoPaddlePaddle:release/2.5from
BingooYang:2.5/linear_opt

Conversation

@BingooYang
Copy link
Copy Markdown
Contributor

Motivation

性能优化

Modifications

将UnquantizedLinearMethod中的matmul和add用linear替换。
带bias情况基本上有加速,不带bias情况小shape下性能有下降(主要是python层if等调度开销,linear内部实现也是matmul)。
810cbda4d14af8f770c231d04dbe1090

Usage or Command

Accuracy Tests

精度保持一致

Checklist

  • [ x ] Add at least a tag in the PR title.
    • Tag list: [[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]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • [ x ] Format your code, run pre-commit before commit.
  • [ x ] Add unit tests. Please write the reason in this PR if no unit tests.
  • [ x ] Provide accuracy results.
  • [ x ] 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.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 3, 2026

Thanks for your contribution!

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release/2.5@bccf388). Learn more about missing BASE report.

Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.5    #7184   +/-   ##
==============================================
  Coverage               ?   69.48%           
==============================================
  Files                  ?      390           
  Lines                  ?    54362           
  Branches               ?     8570           
==============================================
  Hits                   ?    37771           
  Misses                 ?    13862           
  Partials               ?     2729           
Flag Coverage Δ
GPU 69.48% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

@fastdeploy-bot fastdeploy-bot left a comment

Choose a reason for hiding this comment

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

🤖 AI Code Review | 2026-04-03 17:30 CST

📋 Review 摘要

PR 概述:将 UnquantizedLinearMethod.apply() 中的 matmul + add 替换为 paddle.nn.functional.linear,优化带 bias 场景的计算性能

变更范围model_executor/layers/linear.py(核心优化)、tests/e2e/utils/(测试 baseline 路径更新)

影响面 TagOP

问题

级别 文件 概述
🟡 建议 rollout_routing_replay_test_utils.py:160 baseline 路径硬编码日期 0403,建议语义化命名

总体评价

核心优化逻辑正确,新增的 bias 维度 assert 检查增强了代码健壮性。测试文件的 baseline 路径变更建议改用更语义化的版本命名方式。

if model_path:
baseline_path = os.path.join(model_path, f"R3_BaseLine_25_uint8/routing_replay_output_baseline_{model_name}")
baseline_path = os.path.join(
model_path, f"R3_BaseLine_dev_uint8_0403/routing_replay_output_baseline_{model_name}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 baseline 路径中硬编码了日期 0403

这种命名方式可能导致未来维护困难:

  1. 每次更新 baseline 都需要修改代码中的路径
  2. 日期含义不够清晰,dev_uint8_0403 中的 0403 指的是什么不明确

建议:

  1. 使用更语义化的版本命名,如 R3_BaseLine_v2.5_uint8
  2. 或者将 baseline 路径配置化,通过环境变量或配置文件管理

@EmmonsCurse EmmonsCurse changed the title [Optimization] merge matmul and add [Cherry-Pick][Optimization] merge matmul and add(#6986) Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants