Skip to content

Conversation

@YuhanXu
Copy link
Contributor

@YuhanXu YuhanXu commented Jul 29, 2025

PR Category

CINN

PR Types

New features

Description

DeepSeek子网涉及到的一些Simplify优化:
SelectOp -> Min Max
BoundSimplify优化:支持 (ax + b)/a, a > b --> x, (ax + b)% a, a > b --> b,
“Power+Log”优化成“Bit操作+ldexpf"

明确CINN中UpperBound能否取到,修正UpperBound的传递关系,使其计算更准确
Var [LowerBound, UpperBound)左闭右开,
For loop_var [LowerBound, UpperBound)左闭右开,
CasInterval [LowerBound, UpperBound]左闭右闭,
SymbolicExprAnalyzer [LowerBound, UpperBound]左闭右闭

Pcard-90680

@paddle-bot
Copy link

paddle-bot bot commented Jul 29, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@YuhanXu YuhanXu force-pushed the simplify_related_optim branch 12 times, most recently from f603b19 to cff0dd2 Compare August 5, 2025 12:14

using ir::ExprMutator<>::Visit;

// 递归优化 Compare 操作数
Copy link
Contributor

Choose a reason for hiding this comment

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

注释用 English

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
};

struct SimplifySelect2MinMaxMutator : public ir::ExprMutator<> {
Copy link
Contributor

Choose a reason for hiding this comment

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

加一些化简示例

Copy link
Contributor Author

Choose a reason for hiding this comment

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

新增用例在这里
test/cpp/pir/cinn/ir_simplify_select_test.cc

Copy link
Contributor

Choose a reason for hiding this comment

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

可以在代码前加点注释写示例,方便阅读,大部分开发者想不到去看单测

Copy link
Contributor Author

Choose a reason for hiding this comment

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

注释都加上啦

}
};

struct SimplifyPowerCeilLog2BitOpLdexpfMutator : public ir::ExprMutator<> {
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

新增用例在这里
test/cpp/pir/cinn/ir_simplify_test.cc

Comment on lines +546 to +571
// 2. Match target pattern: pow(base, ceil(log2(x)))
if (op->name == "pow" && new_args.size() == 2) {
const Expr& base = new_args[0];
const Expr& exponent = new_args[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

这类pow, log的计算是下标运算还是算子逻辑运算?

Copy link
Contributor Author

@YuhanXu YuhanXu Aug 6, 2025

Choose a reason for hiding this comment

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

是算子逻辑运算,新增用例在这里
test/cpp/pir/cinn/ir_simplify_test.cc
实际场景里的输入ir是这样的
image
select-->min/max,power+log2 -->ldexpf+bitOp化简以后长这样
image

@YuhanXu YuhanXu force-pushed the simplify_related_optim branch 4 times, most recently from 5bf17f4 to 882e5c4 Compare August 6, 2025 03:41
@YuhanXu
Copy link
Contributor Author

YuhanXu commented Aug 6, 2025

/re-run all-failed

liuruyan
liuruyan previously approved these changes Aug 7, 2025
Copy link
Contributor

@liuruyan liuruyan left a comment

Choose a reason for hiding this comment

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

  1. 由于历史包袱,Var Bound和CAS Bound区间定义暂时不统一,日后人力时间允许的话,需要统一定义
  2. 一些Comment可以下个PR补齐
  3. 需要关注下例行监控模型情况,是否存在新增报错、编译超时问题
Comment on lines 681 to 683
const ir::IndexExpr &expr, const common::SymbolicExprAnalyzer &ana) {
// Handle cases like `(a * C1 + b) / C2` and `(a * C1 + b) % C2`
// where `C1` and `C2` are constants
Copy link
Contributor

Choose a reason for hiding this comment

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

这个注释描述不清晰,应描述c1、b、c2大小及倍数关系,并且添加相应辅助理解的case,可参考simplify_util.h
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 707 to 709
if (rhs.is_constant() && rhs.as_int64() == denom_val) {
// Extract terms divisible by denominator
multiple_terms.push_back(term.operand(0)); // Extract multiplicand part
Copy link
Contributor

Choose a reason for hiding this comment

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

是否应该可以化简满足倍数关系?

Suggested change
if (rhs.is_constant() && rhs.as_int64() == denom_val) {
// Extract terms divisible by denominator
multiple_terms.push_back(term.operand(0)); // Extract multiplicand part
if (rhs.is_constant() && rhs.as_int64() % denom_val == 0) {
// Extract terms divisible by denominator
multiple_terms.push_back(term.operand(0) * (rhs.as_int64() / denom_va)); // Extract multiplicand part
Copy link
Contributor Author

Choose a reason for hiding this comment

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

可以满足

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@YuhanXu
Copy link
Contributor Author

YuhanXu commented Aug 8, 2025

/re-run all-failed

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

@zyfncg zyfncg merged commit af17fc9 into PaddlePaddle:develop Aug 11, 2025
71 of 75 checks passed
Enigmatisms pushed a commit to Enigmatisms/Paddle that referenced this pull request Aug 11, 2025
maxiaolong001 pushed a commit to maxiaolong001/Paddle that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants