CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[CINN] Refine sym infer for FloorDivide #69167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CINN] Refine sym infer for FloorDivide #69167
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
[&](const symbol::DimExpr &x, const symbol::DimExpr &y) { | ||
if (x.isa<int64_t>() && y.isa<int64_t>()) { | ||
int64_t m = x.dyn_cast<int64_t>(); | ||
int64_t n = y.dyn_cast<int64_t>(); | ||
if (n == 0) { | ||
PADDLE_THROW(common::errors::InvalidArgument( | ||
"Division by zero is undefined.")); | ||
} | ||
int64_t quotient = m / n; | ||
int64_t remainder = m % n; | ||
if ((remainder != 0) && ((m < 0) != (n < 0))) { | ||
quotient -= 1; | ||
} | ||
return symbol::DimExpr{quotient}; | ||
} else { | ||
return symbol::DimExpr{infer_context->GetNextSymName()}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dim 的运算都整数运算,这里是不是可以直接 return x/y;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
floor_divide 是往 -inf 靠齐的,c++的divide / 是往 0 靠齐的,负数会不一样
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddle 的 floor_divide 也是朝 0 方向舍入到最接近的整数值。另外Dim一般不会出现负值,在infermeta 中会出现-1表示动态维度,Shape Dialect里一般没有负值
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最新的 develop 是往 -inf 舍入的,这个是 Data 区数据,可能会负的叭
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实,这个接口在3.0版本修改了;按理说不会出现负值,如果出现了int64的负值我们直接报错吧,否者用普通除法处理
Description 中可以添加上修复 SIR_32 子图测试的描述 |
已提交 PaddleTest 仓库修改~ PaddlePaddle/PaddleTest#2981 |
辛苦国勇提交PR将Camp中的任务认领并标记为完成 👍https://github.com/PFCCLab/Camp/blob/main/Docs/Hackathon_7th/CINN_Symbolic_infer/PaddleTest_bug_fix.md |
PADDLE_THROW(common::errors::InvalidArgument( | ||
"Currently, negative data is not considered, but received x=%d", | ||
x.dyn_cast<int64_t>())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该不用THROW吧,不设置data就行了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data出现负数应该是不合法的吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
照理说这里如果isa int64_t,里面的值就不可能<0,不然应该是个Negative,data出现负数不一定不合法,而且加合法性验证的话应该是在构造data的时候检查而不是在这里的逻辑就直接抛异常
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是在 full(full_int_array) op 推导的时候,如果是负数的话,需要转为 Negative DimExpr,但是 full 负数除了给 reshape 提供 -1 ,好像也没什么场景?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是不是在 full(full_int_array) op 推导的时候,如果是负数的话,需要转为 Negative DimExpr,但是 full 负数除了给 reshape 提供 -1 ,好像也没什么场景?
在一些有axis tensor 输入的算子里,还可能会出现负的下标索引,也需要通过full来处理,所以不能改full
经讨论之后建议直接 return x/y,退化为整数除法处理。 |
paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/element_wise_binary.cc
Outdated
Show resolved
Hide resolved
paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/element_wise_binary.cc
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR Category
CINN
PR Types
Others
Description
Note
FloorDivide 计算退化为整数除法 x/ y 处理,floorDevide 算子是向 -inf 舍入的,C++ 是向 0 舍入的,这里可能会有舍入误差。