Skip to content
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

[AMP] Add python API for collecting operator stats. #52215

Merged
merged 8 commits into from
Mar 30, 2023

Conversation

Xreki
Copy link
Contributor

@Xreki Xreki commented Mar 28, 2023

PR types

Others

PR changes

APIs

Describe

工作内容1:添加动态图算子数据类型、调用次数统计的正式Python API,包括两组API:

  1. 一对enable/disable来开启、关闭算子统计功能:paddle.amp.debugging.enable/disable_operator_stats_collection
  2. 一个上下文切换API:paddle.amp.debugging.collect_operator_stats

使用示例和效果如下:

import paddle
conv = paddle.nn.Conv2D(3, 2, 3)
x = paddle.rand([10, 3, 32, 32])
paddle.amp.debugging.enable_operator_stats_collection()
# AMP list including conv2d, elementwise_add, reshape2, cast (transfer_dtype)
with paddle.amp.auto_cast(enable=True, level='O2'):
    out = conv(x)
# Print to the standard output.
paddle.amp.debugging.disable_operator_stats_collection()
# <------------------------------------------------------- op list -------------------------------------------------------->
# <--------------- Op Name ---------------- | -- FP16 Calls --- | -- BF16 Calls --- | --- FP32 Calls--- | -- Other Calls -->
#   conv2d                                  |  1                |  0                |  0                |  0
#   elementwise_add                         |  1                |  0                |  0                |  0
#   reshape2                                |  1                |  0                |  0                |  0
#   transfer_dtype                          |  0                |  0                |  3                |  0
# <----------------------------------------------------- op count: 4 ------------------------------------------------------>

工作内容2:添加test/amp子目录,放置AMP功能相关的单测。

三个API的英文文档预览如下:

  • collect_operator_stats
    image

  • enable_operator_stats_collection
    image

  • disable_operator_stats_collection
    image

@paddle-bot
Copy link

paddle-bot bot commented Mar 28, 2023

你的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.

zhangting2020
zhangting2020 previously approved these changes Mar 29, 2023
AnnaTrainingG
AnnaTrainingG previously approved these changes Mar 29, 2023
Copy link
Contributor

@AnnaTrainingG AnnaTrainingG left a comment

Choose a reason for hiding this comment

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

Good

XieYunshen
XieYunshen previously approved these changes Mar 29, 2023
Copy link
Contributor

@XieYunshen XieYunshen left a comment

Choose a reason for hiding this comment

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

LGTM for 单测重命名

lanxianghit
lanxianghit previously approved these changes Mar 29, 2023
@Xreki Xreki merged commit 7354432 into PaddlePaddle:develop Mar 30, 2023
@Xreki Xreki deleted the amp/operator_stats branch March 30, 2023 08:38
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.

6 participants