-
Notifications
You must be signed in to change notification settings - Fork 6k
Interpolate fix on cuda for large output tensors #10067
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,14 @@ def forward(self, hidden_states: torch.Tensor, output_size: Optional[int] = None | |
# if `output_size` is passed we force the interpolation output | ||
# size and do not make use of `scale_factor=2` | ||
if self.interpolate: | ||
# upsample_nearest_nhwc also fails when the number of output elements is large | ||
# https://github.com/pytorch/pytorch/issues/141831 | ||
scale_factor = ( | ||
2 if output_size is None else max([f / s for f, s in zip(output_size, hidden_states.shape[-2:])]) | ||
yiyixuxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
if hidden_states.numel() * scale_factor > pow(2, 31): | ||
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. Consider keeping 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. I feel that 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. Along the same lines as #10067 (comment). |
||
hidden_states = hidden_states.contiguous() | ||
|
||
if output_size is None: | ||
hidden_states = F.interpolate(hidden_states, scale_factor=2.0, mode="nearest") | ||
else: | ||
|
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.
Do we need to check for
channels_first
orchannels_last
memory layout?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.
My assumption is it will behave the same way for any non-contiguous layouts, and that calling
.contiguous()
on a contiguous tensor will be a no-op. I'm also mimicking the same structure as in lines 161-163 above.