Skip to content

[API compatibility]Fix trunc mode in divide op when input x is integer#74903

Merged
zhwesky2010 merged 2 commits into
PaddlePaddle:developfrom
zhanghonggeng:fix1
Aug 27, 2025
Merged

[API compatibility]Fix trunc mode in divide op when input x is integer#74903
zhwesky2010 merged 2 commits into
PaddlePaddle:developfrom
zhanghonggeng:fix1

Conversation

@zhanghonggeng
Copy link
Copy Markdown
Contributor

@zhanghonggeng zhanghonggeng commented Aug 26, 2025

PR Category

User Experience

PR Types

New features

Description

当 rounding_mode 为 trunc 时,_C_ops.divide 在输入 x 和 y 均为 int 类型的情况下,会将类型提升为 float32,实际 trunc 应保持 int 类型,其输出结果也应维持 int 类型。

注:

  1. 目前 paddle 不支持整数类型提升,例如int32->int64。

pcard-67164

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Aug 26, 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.

@zhanghonggeng zhanghonggeng force-pushed the fix1 branch 2 times, most recently from 1f5e3e9 to 9a84701 Compare August 26, 2025 08:46
@zhanghonggeng zhanghonggeng changed the title [API compatibility]Fix trunc mode in divide op when inputs are integer [API compatibility]Fix trunc mode in divide op when input x integer Aug 26, 2025
@zhanghonggeng zhanghonggeng changed the title [API compatibility]Fix trunc mode in divide op when input x integer [API compatibility]Fix trunc mode in divide op when input x is integer Aug 26, 2025
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Aug 26, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@4d37570). Learn more about missing BASE report.

Files with missing lines Patch % Lines
python/paddle/tensor/math.py 77.77% 2 Missing ⚠️

❌ Your patch status has failed because the patch coverage (77.77%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #74903   +/-   ##
==========================================
  Coverage           ?   77.77%           
==========================================
  Files              ?        1           
  Lines              ?        9           
  Branches           ?        0           
==========================================
  Hits               ?        7           
  Misses             ?        2           
  Partials           ?        0           

☔ 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.

tmp = _C_ops.divide(x, y)
res = _C_ops.trunc(tmp, out=out)

if x.dtype in (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rounding_mode=None:int提升到float
rounding_mode=floor:int不提升,仍为int
rounding_mode=trunc:int不提升,仍为int

floor下会有这个问题吗

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

floor没有这个问题,NeedTypePromotion里边专门针对divide的int的输入做了转换,trunc这里复用了divide需要转换, floor_divide是单独的kernel实现。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rounding_mode=None:int提升到float rounding_mode=floor:int不提升,仍为int rounding_mode=trunc:int不提升,仍为int

floor下会有这个问题吗

所以这里相当于 误提升到了float,然后又降回int,做了两个不必要操作。

后面可以看下直接新增一个 trunc_divide kernel成本大不大,不大的话可以做下,性能会好不少。
不是很紧急先合入这一版了。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

好的好的~

tmp = _C_ops.divide(x, y)
res = _C_ops.trunc(tmp, out=out)

if x.dtype in (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rounding_mode=None:int提升到float rounding_mode=floor:int不提升,仍为int rounding_mode=trunc:int不提升,仍为int

floor下会有这个问题吗

所以这里相当于 误提升到了float,然后又降回int,做了两个不必要操作。

后面可以看下直接新增一个 trunc_divide kernel成本大不大,不大的话可以做下,性能会好不少。
不是很紧急先合入这一版了。

@zhwesky2010 zhwesky2010 merged commit 6377ab9 into PaddlePaddle:develop Aug 27, 2025
64 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants