-
Notifications
You must be signed in to change notification settings - Fork 56
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
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5d46f40
【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)
decade-afk 5fed93f
【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)
decade-afk 587e426
【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)
decade-afk 6389a93
【Hackathon 7th No.42】NO.42 为 Paddle 代码转换工具新增 API 转换规则(第 9 组)
decade-afk c2ddba4
Merge branch 'PaddlePaddle:master' into itemsize
decade-afk 4041675
update
monster1015 bb52abd
update
decade-afk 286b66b
update
decade-afk b780348
Merge branch 'master' into itemsize
decade-afk e402151
update
decade-afk cfb2a60
Merge branch 'itemsize' of work:decade-afk/PaConvert into itemsize
decade-afk d1bfb6a
update
decade-afk 1f096fb
update
decade-afk 09be172
update
decade-afk 47bd025
update
decade-afk e6de29b
update
decade-afk f6d64fd
update
decade-afk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,6 +436,71 @@ def generate_code(self, kwargs): | |
return super().generate_code(kwargs) | ||
|
||
|
||
class TensorStrideMatcher(BaseMatcher): | ||
def generate_code(self, kwargs): | ||
if 'dim' not in kwargs or kwargs['dim'] == 'None': | ||
API_TEMPLATE = textwrap.dedent( | ||
""" | ||
{}.get_strides() | ||
""" | ||
) | ||
code = API_TEMPLATE.format(self.paddleClass) | ||
else: | ||
API_TEMPLATE = textwrap.dedent( | ||
""" | ||
{}.get_strides()[{}] | ||
""" | ||
) | ||
code = API_TEMPLATE.format(self.paddleClass, kwargs['dim']) | ||
return code | ||
|
||
|
||
class TensorToSparseCooMatcher(BaseMatcher): | ||
def generate_code(self, kwargs): | ||
API_TEMPLATE = textwrap.dedent( | ||
""" | ||
{}.to_sparse_coo(len({}.shape)) | ||
""" | ||
) | ||
code = API_TEMPLATE.format(self.paddleClass, self.paddleClass) | ||
return code | ||
|
||
|
||
class TensorNbytesMatcher(BaseMatcher): | ||
def get_paddle_class_attribute_nodes(self, node): | ||
self.parse_func(node) | ||
code = "{}.size * {}.element_size()".format( | ||
self.paddleClass, self.paddleClass | ||
) | ||
return ast.parse(code).body | ||
|
||
|
||
class DimOrderMatcher(BaseMatcher): | ||
def generate_code(self, kwargs): | ||
API_TEMPLATE = textwrap.dedent( | ||
""" | ||
tuple([i for i in range(len({}.shape))]) | ||
""" | ||
) | ||
code = API_TEMPLATE.format(self.paddleClass) | ||
return code | ||
|
||
|
||
class BitwiseShiftMatcher(BaseMatcher): | ||
def generate_code(self, kwargs): | ||
API_TEMPLATE = textwrap.dedent( | ||
""" | ||
{}(x={}, y={}) | ||
""" | ||
) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 这个是因为out是torch.float32类型的问题吧?如果out与result类型一致就没问题。 |
||
code = "paddle.assign({}.astype('float32'), {})".format(code, kwargs["out"]) | ||
return code | ||
|
||
|
||
class TRFMPreTrainedTokenizerMatcher(BaseMatcher): | ||
def generate_aux_code(self): | ||
CODE_TEMPLATE = textwrap.dedent( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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