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

【Hackathon 5th No.14】Add combinations API to Paddle #57792

Merged
merged 15 commits into from
Dec 1, 2023

Conversation

Patrick-Star125
Copy link
Contributor

@Patrick-Star125 Patrick-Star125 commented Sep 27, 2023

PR types

New features

PR changes

APIs

Description

Add combinations API to Paddle

Link

Rfc PR: PaddlePaddle/community#654
docs PR: PaddlePaddle/docs#6287

待完成

  • RFC文档修改
  • 中文文档

@paddle-bot
Copy link

paddle-bot bot commented Sep 27, 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.

@paddle-bot paddle-bot bot added the contributor External developers label Sep 27, 2023
@Patrick-Star125 Patrick-Star125 changed the title 【Hackathon 5 No.14】Add combinations API to Paddle 【Hackathon 5th No.14】Add combinations API to Paddle Sep 28, 2023
@xuxinyi389
Copy link
Contributor

有中文RFC文档吗

@Patrick-Star125
Copy link
Contributor Author

有中文RFC文档吗

PaddlePaddle/community#654

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 5, 2023

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

@xuxinyi389
Copy link
Contributor

codestyle-check流水线失败。安装pre-commit后,重新提交。

def modify_setting(self):
self.dtype_np = 'int64'
self.x_shape = [10]
self.r = 0
Copy link
Contributor

Choose a reason for hiding this comment

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

缺少r>x_shape情况的单测

class TestIndexFillAPI2(TestCombinationsAPIBase):
def modify_setting(self):
self.dtype_np = 'int64'
self.x_shape = [10]
Copy link
Contributor

Choose a reason for hiding this comment

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

缺少了输入为empty情况下的单测

@Patrick-Star125
Copy link
Contributor Author

Patrick-Star125 commented Oct 16, 2023

增加了输入shape为[0]的测试同时r>x_shape的测试


"""
if len(x.shape) != 1:
raise TypeError(f"Expect a 1-D vector, but got x shape {x.shape}")
if not isinstance(r, int) or r < 0:
raise ValueError(f"Expect a non-negative int, but got r={r}")

if r == 0:
if r == 0 or r > x.shape[0]:
return paddle.empty([0], dtype=x.dtype)
Copy link
Contributor

Choose a reason for hiding this comment

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

empty的形状设计好像有些问题,pytorch在不同情况下的empty的size是不同的。相关设计后续补充到rfc文档中。

Copy link
Contributor Author

@Patrick-Star125 Patrick-Star125 Oct 17, 2023

Choose a reason for hiding this comment

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

我之前错误理解empty表示输入形状为空的tensor了,已添加empty相关测试

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Oct 31, 2023

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

expected = paddle.empty([0, 4])
np.testing.assert_allclose(c, expected)

# test empty imput
Copy link
Contributor

Choose a reason for hiding this comment

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

typo error

paddle.device.set_device(place)
a = paddle.to_tensor([1, 2, 3])
c = paddle.combinations(a, r=4)
expected = paddle.empty([0, 4])
Copy link
Contributor

Choose a reason for hiding this comment

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

一般是不推荐人为给定期望输入用来测试的,是否有其他类似库函数用于测试。

a = paddle.empty([0])
c1 = paddle.combinations(a)
c2 = paddle.combinations(a, with_replacement=True)
expected = paddle.empty([0, 2])
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

@Patrick-Star125
Copy link
Contributor Author

1.更改了测试的输入和输出
2.因为torch.stack和paddle.stack的行为差异,增加了with_replacement相关的判断逻辑

@xuxinyi389
Copy link
Contributor

1.更改了测试的输入和输出 2.因为torch.stack和paddle.stack的行为差异,增加了with_replacement相关的判断逻辑

确认下coverage流水线没有通过的原因

@xuxinyi389
Copy link
Contributor

LGTM

jeff41404
jeff41404 previously approved these changes Nov 22, 2023
Copy link
Contributor

@jeff41404 jeff41404 left a comment

Choose a reason for hiding this comment

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

LGTM

"""
Compute combinations of length r of the given tensor. The behavior is similar to python’s itertools.combinations
when with_replacement is set to False, and itertools.combinations_with_replacement when with_replacement is set to True.
Args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Args:
Args:

Comment on lines 7078 to 7079
Returns:
out (Tensor): tensor concatenated by combinations, same dtype with x
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Returns:
out (Tensor): tensor concatenated by combinations, same dtype with x
Returns:
out (Tensor). Tensor concatenated by combinations, same dtype with x.

Comment on lines +7082 to +7089
>>> import paddle
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32')
>>> res = paddle.combinations(x)
>>> print(res)
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True,
[[1, 2],
[1, 3],
[2, 3]])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
>>> import paddle
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32')
>>> res = paddle.combinations(x)
>>> print(res)
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True,
[[1, 2],
[1, 3],
[2, 3]])
>>> import paddle
>>> x = paddle.to_tensor([1, 2, 3], dtype='int32')
>>> res = paddle.combinations(x)
>>> print(res)
Tensor(shape=[3, 2], dtype=int32, place=Place(gpu:0), stop_gradient=True,
[[1, 2],
[1, 3],
[2, 3]])

Copy link
Contributor

Choose a reason for hiding this comment

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

严格按照模板(包括空行)

Copy link

paddle-ci-bot bot commented Nov 26, 2023

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

sunzhongkai588
sunzhongkai588 previously approved these changes Nov 27, 2023
Copy link
Contributor

@sunzhongkai588 sunzhongkai588 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 docs

@luotao1
Copy link
Contributor

luotao1 commented Nov 29, 2023

@Patrick-Star125 请处理下冲突

@Patrick-Star125
Copy link
Contributor Author

Done

@luotao1 luotao1 merged commit 2ff612c into PaddlePaddle:develop Dec 1, 2023
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants