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

[API/OP] Support FP16/BF16 in paddle.nonzero API/OP #51640

Merged

Conversation

haohongxiang
Copy link
Contributor

PR types

Bug fixes

PR changes

OPs

Describe

[API/OP] Support FP16/BF16 in paddle.nonzero API/OP

@paddle-bot
Copy link

paddle-bot bot commented Mar 14, 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.

phi::NonZeroKernel,
int,
bool,
phi::dtype::float16,
Copy link
Contributor

Choose a reason for hiding this comment

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

xpu无需修改

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

'int16',
'int32',
'int64',
'bfloat16',
Copy link
Contributor

Choose a reason for hiding this comment

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

暂时使用uint16

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

}

def return_outputs(self):
return {'Out': np.transpose(np.nonzero(self.inputs['Condition']))}
Copy link
Contributor

Choose a reason for hiding this comment

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

这里为什么要transpose呢

Copy link
Contributor Author

@haohongxiang haohongxiang Mar 27, 2023

Choose a reason for hiding this comment

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

numpy.nonzero默认返回的是 tuple 类型,可以理解为所有非0元素的x下标和y下标分别放置在不同 array 中,即返回由2个 array 组成的 tuple ;此功能对应 paddle API 中参数as_tupleTrue的case(默认为False)。因此numpy.nonzero(x)等价于paddle.nonzero(x, as_tuple=True)numpy.transpose (numpy.nonzero(x))等价于paddle.nonzero(x)

Copy link
Contributor

@ZzSean ZzSean left a comment

Choose a reason for hiding this comment

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

LGTM

@haohongxiang haohongxiang merged commit 2e92357 into PaddlePaddle:develop Mar 28, 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.

2 participants