-
Notifications
You must be signed in to change notification settings - Fork 826
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
interpolate api align #9118
Merged
mergify
merged 1 commit into
master
from
align_interpolate_scale_parameter_with_pytorch
Sep 21, 2022
Merged
interpolate api align #9118
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,16 @@ def forward(self, x): | |
raise ValueError( | ||
"recompute_scale_factor is not meaningful with an explicit size." | ||
) | ||
if isinstance(scale_factors, (list, tuple)): | ||
scale_factors = [ | ||
float(_.numpy()) if (flow.is_tensor(_) and len(_.size()) == 0) else _ | ||
for _ in scale_factors | ||
] | ||
if isinstance(output_size, (list, tuple)): | ||
output_size = [ | ||
int(_.numpy()) if (flow.is_tensor(_) and len(_.size()) == 0) else _ | ||
for _ in output_size | ||
] | ||
Comment on lines
+124
to
+133
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. 可以在 python 代码那边加一个 TODO,后面我打算加一个 scalar tensor 到 scalar 的隐式转换,这样可以一次性支持更多 functional 的 scalar tensor 输入。 另外这里的会用到 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. 好的 |
||
if self.mode == "area" and output_size is None: | ||
self.recompute_scale_factor = True | ||
if self.recompute_scale_factor is True: | ||
|
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
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.
这个对性能上影响应该很大,可否再实现一个版本的op,这个op直接接受这些float值作为输入tensor,而不是作为op的属性。
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它也会触发一次同步,我感觉不能要求所有算子都去特化吧,pytorch的interpolate也没有特化scale和size为tensor的情况。另外性能也不一定有问题吧,只是一个scalar同步了一下而已
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.
oneflow可能收到的影响更大一点,这个同步会导致main线程大段空白,从而导致cuda stream断流。
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.
如果 scalar tensor 是在 cpu 上,影响其实比较小(因为 cpu stream 上相对于比较空闲);如果是在 cuda 上,这个东西要一路传到 kernel 里才能保证不断流,这又和现在的 kernel 不一致,需要单独写才能做到想要的效果。
所以目前这种方案应该还好。
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.
好的,这种scalar tensor的同步感觉挺常见的,我们也不能要求所有kernel都重写一次