Skip to content
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

Fix upsample_bilinear to respect align_corner argument #1254

Merged
merged 7 commits into from
Jan 16, 2024

Conversation

BowenBao
Copy link
Contributor

@BowenBao BowenBao commented Jan 16, 2024

Fixes #1159 (comment) which indeed turns out to be a problem uncovered by PyTorch CI https://github.com/pytorch/pytorch/actions/runs/7508784822/job/20445196351?pr=117314.

Fixes align_corner default value. The default value from pytorch signature is False https://pytorch.org/docs/stable/generated/torch.nn.Upsample.html#torch.nn.Upsample.
That said, it shouldn't matter since align_corner in aten signature in native_functions.yaml is a required argument, so in practice this function will never be invoked w/o align_corner.

Above is outdated. The case is more complicated. #1254 (comment).

In short this PR fixes the torchlib op signature to match with aten spec, and updates input wrangler for test case to bridge from sample test inputs for function torch.nn.functional.upsample_bilinear.

@BowenBao BowenBao added the bug Something isn't working label Jan 16, 2024
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (5b9c318) 78.78% compared to head (ab8ec04) 78.77%.

Files Patch % Lines
...ipt/tests/function_libs/torch_lib/ops_test_data.py 38.46% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1254      +/-   ##
==========================================
- Coverage   78.78%   78.77%   -0.01%     
==========================================
  Files         119      119              
  Lines       15679    15691      +12     
  Branches     2481     2483       +2     
==========================================
+ Hits        12353    12361       +8     
- Misses       2919     2921       +2     
- Partials      407      409       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BowenBao
Copy link
Contributor Author

@justinchuby The reason why it passes on onnxscript side is that we are not testing the nn.functional.interpolate test case from common_methods_invocations.py, which fails on pytorch side. I don't know how to properly add the test case for this, it is a large test case with various variants. The upsample test case we test on probably didn't have align_corner flag variation in its sample inputs.

We need more e2e pytorch export tests when adding ops in torchlib to ensure it works.

@BowenBao BowenBao added the topic: torch_lib Related to the torch/aten function lib in development label Jan 16, 2024
@justinchuby
Copy link
Collaborator

Thanks!

We need more e2e pytorch export tests when adding ops in torchlib to ensure it works.

Do you have suggestions? Currently we rely on tests in PyTorch for integration tests.

result = _aten_upsample_bilinear2d_output_size(self, output_size)
result = _aten_upsample_bilinear2d_output_size(
self, output_size, coordinate_transformation_mode
)
else:
assert scales_h is not None
assert scales_h == scales_w, f"scale_h({scales_h}) != scale_w({scales_w})"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this still valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unclear to me, looks like different scale values are not covered in tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link

github-actions bot commented Jan 16, 2024

Test Results

     24 files  ±0      24 suites  ±0   1h 35m 57s ⏱️ - 10m 57s
 11 389 tests ±0   8 440 ✅ ±0    2 944 💤  - 1    5 ❌ +1 
257 716 runs  +1  58 569 ✅ ±0  199 008 💤 ±0  139 ❌ +1 

For more details on these failures, see this check.

Results for commit ab8ec04. ± Comparison against base commit 5b9c318.

♻️ This comment has been updated with latest results.

@BowenBao
Copy link
Contributor Author

Do you have suggestions? Currently we rely on tests in PyTorch for integration tests.

Based on current infra, one would need to add both test cases to onnxscript and pytorch ... Otherwise, the wrangler itself and operator signature implementation part is missing coverage.

Comment on lines 2306 to 2312
if output_size is not None:
result = _aten_upsample_bilinear2d_output_size(self, output_size)
result = _aten_upsample_bilinear2d_output_size(
self, output_size, coordinate_transformation_mode
)
else:
assert scales_h is not None
assert scales_h == scales_w, f"scale_h({scales_h}) != scale_w({scales_w})"
Copy link
Collaborator

@justinchuby justinchuby Jan 16, 2024

Choose a reason for hiding this comment

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

Should we reverse the check - omit output_size when the scales are not None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have link to spec whether which one takes precedence over the other?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

But testing suggested otherwise

Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
@BowenBao BowenBao merged commit bec23ad into main Jan 16, 2024
33 of 37 checks passed
@BowenBao BowenBao deleted the bowbao/fix_align_corner branch January 16, 2024 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working topic: torch_lib Related to the torch/aten function lib in development
Projects
Development

Successfully merging this pull request may close these issues.

[torchlib] Implement various upsample functions
2 participants