Skip to content

Structured kernel definition for upsample_nearest2d#50189

Closed
soulitzer wants to merge 6 commits intopytorch:masterfrom
soulitzer:upsample-structured-kernel
Closed

Structured kernel definition for upsample_nearest2d#50189
soulitzer wants to merge 6 commits intopytorch:masterfrom
soulitzer:upsample-structured-kernel

Conversation

@soulitzer
Copy link
Copy Markdown
Contributor

@soulitzer soulitzer commented Jan 7, 2021

See the structured kernel definition RFC for context.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Jan 7, 2021

💊 CI failures summary and remediations

As of commit 1d53205 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

@soulitzer soulitzer added the module: structured kernels Related to new structured kernels functionality label Jan 7, 2021
(input.numel() != 0 ||
(input.size(1) != 0 && input.size(2) != 0 && input.size(3) != 0)
) &&
input.dim() == 4,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you've just checked that input.dim() == 4, this is always true, and if it weren't, there would be trouble in input.size(3)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, this might actually be a useful check because input.size(3) might've been short-circuited if input.numel() != 0. Either way if we use prod_intlist method, we will have to keep this check.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

upsample_nearest_2d_common_check checks that input_size.size() == 4, so you can get to this line only if input.dim == 4, no need to check for it again.

// Allow for empty batch size but not other dimensions
TORCH_CHECK(
(input.numel() != 0 ||
(input.size(1) != 0 && input.size(2) != 0 && input.size(3) != 0)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

prod_intlist(input.sizes()+1, input.sizes().end())

) {
auto full_output_size = upsample_nearest2d_common_check(input_size, output_size);

check_dim_size(grad_output, 4, 0, full_output_size[0]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check_dim_size is pretty inefficient, you can compare sizes directly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

whoops, gonna have to fix upsample nearest 1d too

@soulitzer soulitzer requested a review from ngimel January 7, 2021 23:26
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 8, 2021

Codecov Report

Merging #50189 (1d53205) into master (ce37039) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master   #50189   +/-   ##
=======================================
  Coverage   80.68%   80.68%           
=======================================
  Files        1902     1902           
  Lines      206356   206339   -17     
=======================================
- Hits       166496   166491    -5     
+ Misses      39860    39848   -12     

@soulitzer soulitzer requested a review from ezyang January 8, 2021 16:08
@soulitzer soulitzer force-pushed the upsample-structured-kernel branch from f2f8ee5 to 17e7332 Compare January 9, 2021 00:21
nbatch,
channels,
int64_t input_width = input_size[2];
int64_t input_height = input_size[3];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks wrong

int64_t output_height = output_size[0];
int64_t output_width = output_size[1];
int64_t output_width = output_size[0];
int64_t output_height = output_size[1];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also looks wrong

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks wrong and not caught by test - can you please add a test with the different input and output width and height?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the code here is functionally correct; just the error message would be rendered wrong here.

grad_input.zero_();

upsample_nearest2d_backward_kernel(kCPU, grad_input, grad_output, scales_h, scales_w);
return {nbatch, channels, output_width, output_height};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This needs to be fixed too

@ezyang
Copy link
Copy Markdown
Contributor

ezyang commented Jan 11, 2021

Everything else looks fine.

@soulitzer soulitzer force-pushed the upsample-structured-kernel branch from 76fe1e3 to 1d53205 Compare January 11, 2021 20:03
@soulitzer soulitzer requested a review from ezyang January 11, 2021 21:31
@soulitzer
Copy link
Copy Markdown
Contributor Author

@ngimel I've made an update to added the tests, and the other issues from previous comments should be addressed as well. Would you mind taking another look?

Copy link
Copy Markdown
Collaborator

@ngimel ngimel left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@soulitzer has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@soulitzer merged this pull request in 19a8e68.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request has been reverted by ef6be0e.

@soulitzer
Copy link
Copy Markdown
Contributor Author

Unlanding this because it broke internal tests

@soulitzer soulitzer deleted the upsample-structured-kernel branch April 14, 2021 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed Merged module: structured kernels Related to new structured kernels functionality Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants