Skip to content

【Hackathon 6th No.10】Add isin API to Paddle -part - #64001

Merged
luotao1 merged 9 commits into
PaddlePaddle:developfrom
NKNaN:hack10part2
Jun 3, 2024
Merged

luotao1 merged 9 commits into
PaddlePaddle:developfrom
NKNaN:hack10part2

Conversation

@NKNaN

@NKNaN NKNaN commented Apr 30, 2024

Copy link
Copy Markdown
Contributor

PR Category

User Experience

PR Types

New features

Description

rfcs: PaddlePaddle/community#884

@paddle-bot

paddle-bot Bot commented Apr 30, 2024

Copy link
Copy Markdown

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

@paddle-bot paddle-bot Bot added the contributor External developers label Apr 30, 2024
@luotao1 luotao1 self-assigned this May 7, 2024
@luotao1 luotao1 added the API label May 7, 2024
>>> print(res)
Tensor(shape=[5], dtype=bool, place=Place(cpu), stop_gradient=True,
[True, False, False, True, False])
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

参考 pytorch 在 _decompose 中的设计:当 test_elements 元素个数较少时直接进行暴力搜索,较多时则采取基于排序的算法:若 assume_unique=True,则用稳定排序的 argsort 进行实现;若 assume_unique=False,则用 searchsorted 进行实现。

示例代码中,能否体现出 assume_unique=True/False 的区别?注释中是否要加入这段说明

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.

增加了一个 assume_unique 设置错误导致结果出错的例子;
在下面代码中加了不同分支对应不同做法的注释

luotao1
luotao1 previously approved these changes May 13, 2024
Comment thread python/paddle/tensor/math.py Outdated
return paddle.equal(paddle.imag(x), 0)


def isin(elements, test_elements, assume_unique=False, invert=False, name=None):

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.

Accroding to API design guidelines standard, use x instead of elements and test_x instead of test_elements

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.

revised.

'float32',
'float64',
'int32',
'int64',

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.

should we support bfloat16 and float16?

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.

Temporarily not since paddle.searchsorted only support 'float32', 'float64', 'int32' and 'int64'.

'float32',
'float64',
'int32',
'int64',

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.

same date type issue as above

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.

Temporarily not since paddle.searchsorted only support 'float32', 'float64', 'int32' and 'int64'.

@NKNaN

NKNaN commented May 14, 2024

Copy link
Copy Markdown
Contributor Author

@jeff41404 paddle.searchsorted currently does not support fp16 and bf16. I think the reason may be that the two input tensors' data type of paddle.searchsorted could be different, and since fp16 and bf16 has lower precision than float32 and float64, the comparision between them may be less meaningful.

@jeff41404

jeff41404 commented May 15, 2024 •

Copy link
Copy Markdown
Contributor

@jeff41404 paddle.searchsorted currently does not support fp16 and bf16. I think the reason may be that the two input tensors' data type of paddle.searchsorted could be different, and since fp16 and bf16 has lower precision than float32 and float64, the comparision between them may be less meaningful.

the logic of searchsorted also supports comparing two inputs with different data types. Registering the fp16 and bf16 data types in the Operator should support these two data types. searchsorted operator was developed many years ago, when fp16 and bf16 were not yet widely used, and it was not intentionally unsupported due to accuracy or lower precision.

@NKNaN

NKNaN commented May 15, 2024

Copy link
Copy Markdown
Contributor Author

the logic of searchsorted also supports comparing two inputs with different data types. Registering the fp16 and bf16 data types in the Operator should support these two data types. searchsorted operator was developed many years ago, when fp16 and bf16 were not yet widely used, and it was not intentionally unsupported due to accuracy or lower precision.

Got it. Let me update the searchsorted to support fp16 and bf16 first.

@paddle-ci-bot

paddle-ci-bot Bot commented May 21, 2024

Copy link
Copy Markdown

Sorry to inform you that ce38eb2's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@jeff41404 jeff41404 left a comment

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.

LGTM

@sunzhongkai588 sunzhongkai588 left a comment

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.

LGTM for docs

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