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 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组) #490

Merged
merged 17 commits into from
Oct 17, 2024

Conversation

decade-afk
Copy link
Contributor

@decade-afk decade-afk commented Sep 28, 2024

PR Docs

PaddlePaddle/docs#6893

PR APIs

itemsize
Tensor.bitwise_left_shift
Tensor.bitwise_left_shift_
Tensor.bitwise_right_shift
bitwise_right_shift_
Tensor.col_indices
data_ptr
Tensor.dim_order
Tensor.is_sparse_csr
Tensor.nbytes
Tensor.stride
Tensor.to_sparse_coo
bitwise_left_shift
bitwise_right_shift

Copy link

paddle-bot bot commented Sep 28, 2024

Thanks for your contribution!

@zhwesky2010
Copy link
Collaborator

zhwesky2010 commented Sep 29, 2024

@decade-afk CI验证单测失败:

2024-09-28 21:06:08 FAILED tests/test_Tensor_itemsize.py::test_case_1 - AttributeError: 'Tensor' ...
2024-09-28 21:06:08 FAILED tests/test_Tensor_itemsize.py::test_case_2 - AttributeError: 'Tensor' ...
2024-09-28 21:06:08 FAILED tests/test_Tensor_itemsize.py::test_case_3 - AttributeError: 'Tensor' ...
2024-09-28 21:06:08 =========== 3 failed, 8161 passed, 100 skipped in 189.87s (0:03:09) ============

@@ -436,6 +436,72 @@ def generate_code(self, kwargs):
return super().generate_code(kwargs)


class IsSparseCsrMatcher(BaseMatcher):
Copy link
Collaborator

Choose a reason for hiding this comment

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

用 Attribute2Func 这个Matcher就行



class TensorStrideMatcher(BaseMatcher):
def get_paddle_nodes(self, args, kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个应该不用重写更底层的get_paddle_nodes,不涉及到可变参数这些,重写generate_code就行

class TensorNbytesMatcher(BaseMatcher):
def get_paddle_class_attribute_nodes(self, node):
self.parse_func(node)
code = "int(paddle.numel({}) * {}.element_size())".format(
Copy link
Collaborator

Choose a reason for hiding this comment

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

按文档改组合方式

return code


class TensorItemsizeMatcher(BaseMatcher):
Copy link
Collaborator

Choose a reason for hiding this comment

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

这么一个简单的示例,无需重写Matcher吧,用GenericMatcher就行

)


def test_case_4():
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些测试例子也没必要删除,测试越丰富越好,而且你没有测out参数吧

unsupport=True,
reason="paddle does not support this function temporarily",
)
obj.run(pytorch_code, ["result"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

out参数是不是没测

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已经都改好了

@decade-afk
Copy link
Contributor Author

已经好了,请review,然后那个分布式我属实是不知道该怎么转写
@zhwesky2010

code = API_TEMPLATE.format(
self.get_paddle_api(), kwargs["input"], kwargs["other"]
)
if "out" in kwargs:
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个是因为out是torch.float32类型的问题吧?如果out与result类型一致就没问题。

@@ -82,10 +67,7 @@ def test_case_4():
"""
)
obj.run(
pytorch_code,
Copy link
Collaborator

Choose a reason for hiding this comment

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

torch.bitwise_left_shift(input, other)类型是int32,由于out类型为float32,才导致result为float32。out类型使用不对,应该是改成:out=torch.empty(3, dtype=torch.int32)

不用去把Matcher改错,去适配这个错误的用法。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

确实,现在已经好了,请review

out = torch.tensor([])
result = torch.bitwise_right_shift(input, other, out=out)
"""
)
obj.run(
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上

self.get_paddle_api(), kwargs["input"], kwargs["other"]
)
if "out" in kwargs:
code = "paddle.assign({}, {})".format(code, kwargs["out"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

那你直接用GenericMatcher不就行了?

return code


class BitwiseShiftMatcher(BaseMatcher):
Copy link
Collaborator

Choose a reason for hiding this comment

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

那你直接用GenericMatcher不就行了?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个忘了,已经改好了,请review

Copy link
Collaborator

@zhwesky2010 zhwesky2010 left a comment

Choose a reason for hiding this comment

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

LGTM

@zhwesky2010 zhwesky2010 merged commit b54dfba into PaddlePaddle:master Oct 17, 2024
7 checks passed
@luotao1
Copy link
Collaborator

luotao1 commented Oct 17, 2024

hi, @decade-afk

  • 非常感谢你对飞桨的贡献,我们正在运营一个PFCC组织,会通过定期分享技术知识与发布开发者主导任务的形式持续为飞桨做贡献,详情可见 https://github.com/luotao1 主页说明。
  • 如果你对PFCC有兴趣,请发送邮件至 ext_paddle_oss@baidu.com,我们会邀请你加入~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants