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

[bug fix] fix fp16 dtype checking for argmax op #50811

Merged
merged 3 commits into from
Feb 27, 2023

Conversation

zhangting2020
Copy link
Contributor

@zhangting2020 zhangting2020 commented Feb 23, 2023

PR types

Bug fixes

PR changes

APIs

Describe

问题描述:在静态图模式下,输入为FP16类型时,argmax会报TypeError。

import paddle
import numpy as np

paddle.enable_static()

x_np = np.random.random((10, 16)).astype('float16')
x = paddle.static.data(shape=[10, 16], name='x', dtype='float16')
out = paddle.argmax(x)

exe = paddle.static.Executor()
exe.run(paddle.static.default_startup_program())
out = exe.run(feed={'x': x_np},
            fetch_list=[out])

报错:

Traceback (most recent call last):
  File "test_argmax.py", line 8, in <module>
    out = paddle.argmax(x)
  File "/usr/local/lib/python3.7/dist-packages/paddle/tensor/search.py", line 201, in argmax
    'paddle.argmax',
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/data_feeder.py", line 115, in check_variable_and_dtype
    check_dtype(input.dtype, input_name, expected_dtype, op_name, extra_message)
  File "/usr/local/lib/python3.7/dist-packages/paddle/fluid/data_feeder.py", line 191, in check_dtype
    extra_message,
TypeError: The data type of 'x' in paddle.argmax must be ['float32', 'float64', 'int16', 'int32', 'int64', 'uint8'], but received float16.

修复方案

@paddle-bot
Copy link

paddle-bot bot commented Feb 23, 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.

AnnaTrainingG
AnnaTrainingG previously approved these changes Feb 24, 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.

LGTM

@PaddlePaddle PaddlePaddle locked and limited conversation to collaborators Feb 24, 2023
@PaddlePaddle PaddlePaddle unlocked this conversation Feb 24, 2023
@zhangting2020 zhangting2020 reopened this Feb 24, 2023
@luotao1 luotao1 merged commit f3aec87 into PaddlePaddle:develop Feb 27, 2023
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