-
Notifications
You must be signed in to change notification settings - Fork 53
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
Conversation
Thanks for your contribution! |
@decade-afk CI验证单测失败:
|
paconvert/api_matcher.py
Outdated
@@ -436,6 +436,72 @@ def generate_code(self, kwargs): | |||
return super().generate_code(kwargs) | |||
|
|||
|
|||
class IsSparseCsrMatcher(BaseMatcher): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用 Attribute2Func 这个Matcher就行
paconvert/api_matcher.py
Outdated
|
||
|
||
class TensorStrideMatcher(BaseMatcher): | ||
def get_paddle_nodes(self, args, kwargs): |
There was a problem hiding this comment.
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就行
paconvert/api_matcher.py
Outdated
class TensorNbytesMatcher(BaseMatcher): | ||
def get_paddle_class_attribute_nodes(self, node): | ||
self.parse_func(node) | ||
code = "int(paddle.numel({}) * {}.element_size())".format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按文档改组合方式
paconvert/api_matcher.py
Outdated
return code | ||
|
||
|
||
class TensorItemsizeMatcher(BaseMatcher): |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
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"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out参数是不是没测
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已经都改好了
已经好了,请review,然后那个分布式我属实是不知道该怎么转写 |
paconvert/api_matcher.py
Outdated
code = API_TEMPLATE.format( | ||
self.get_paddle_api(), kwargs["input"], kwargs["other"] | ||
) | ||
if "out" in kwargs: |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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改错,去适配这个错误的用法。
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
paconvert/api_matcher.py
Outdated
self.get_paddle_api(), kwargs["input"], kwargs["other"] | ||
) | ||
if "out" in kwargs: | ||
code = "paddle.assign({}, {})".format(code, kwargs["out"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那你直接用GenericMatcher不就行了?
paconvert/api_matcher.py
Outdated
return code | ||
|
||
|
||
class BitwiseShiftMatcher(BaseMatcher): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那你直接用GenericMatcher不就行了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个忘了,已经改好了,请review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
hi, @decade-afk
|
PR Docs
PaddlePaddle/docs#6893
PR APIs