[torch.onnx] support torch.nn.functional.grid_sample#76159
[torch.onnx] support torch.nn.functional.grid_sample#76159crcrpar wants to merge 17 commits intopytorch:masterfrom
torch.nn.functional.grid_sample#76159Conversation
🔗 Helpful links
💊 CI failures summary and remediationsAs of commit 71f8806 (more details on the Dr. CI page): Expand to see more💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Please report bugs/suggestions to the (internal) Dr. CI Users group. |
|
@crcrpar thanks for contributing! Could you add a test case in You will need to update version to 16 here to enable CI run for opset 16 test with onnxruntime. Line 83 in ca37477 |
|
@crcrpar Looks like CI onnx check is failing on a few tests The |
|
Fixes #69674 |
0a0a42e to
5542914
Compare
|
Thanks @crcrpar ! I left a some comments regarding CI failure and the local test failure you noted. Otherwise this is ready to merge. |
| ops = [{"op_name": "GridSample"}] | ||
| ops = {16: ops} | ||
|
|
||
| class MyModule(Module): |
There was a problem hiding this comment.
Possible to use a more descriptive name for the module? E.g. GridSampleModule, TestGridSampleModule etc.
| def forward(self, x, grid, mode, padding_mode, align_corers): | ||
| return torch.nn.functional.grid_sample(x, grid, mode, padding_mode, align_corners) | ||
|
|
||
| for mode, padding_mode, align_corners in itertools.product( |
There was a problem hiding this comment.
Possible to parameterize this test? E.g.
pytorch/test/distributed/fsdp/test_fsdp_core.py
Lines 141 to 155 in b34b192
There was a problem hiding this comment.
locally parametrize didn't work so skipped it this time
There was a problem hiding this comment.
also, I'm not sure if we want a bunch of different test cases for one GridSample op.
There was a problem hiding this comment.
That's cool. I wouldn't worry about having different tests for an op, as long as it's clear what they are testing for. For now I would also recommend subtests: https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests
There was a problem hiding this comment.
I'm not that inclined to use that as that's not supported by pytest IIRC: https://docs.pytest.org/en/6.2.x/unittest.html#unittest-testcase-support
There was a problem hiding this comment.
Do you know if pytest will then skip the subtests or treat them as one test instead? It seems they provide support via a plugin: https://github.com/pytest-dev/pytest-subtests. Feel free to skip any changes in this PR!
There was a problem hiding this comment.
IIRC it was more similar to the latter when I used pytest for other tests with subtest.
I haven't checked the code nor sought for a plugin though
| from torch.nn.functional import GRID_SAMPLE_INTERPOLATION_MODES, GRID_SAMPLE_PADDING_MODES | ||
|
|
||
|
|
||
| # note (mkozuki): Why `grid_sampler` instead of `grid_sample`? |
There was a problem hiding this comment.
I would add this to the docstring instead.
There was a problem hiding this comment.
can't that be a follow-up thing? I didn't see any docstring in symbolic_opset files.
There was a problem hiding this comment.
It can be! Totally non blocking
|
Commented just as I was passing by! They are non-blocking |
|
Great, when can I use this? |
Thanks for asking! You should be able to find the updated version in PyTorch nightly once the pull request is merged. You can find installation guides for the nightly build on https://pytorch.org by selecting Preview(Nightly). |
|
Wow, while I don't understand what's in it, I really need this feature |
@HSJ-007 Could you share more on what you are trying to accomplish and how this feature can be useful? |
|
I'm going to finish a project, and it's tied to my graduation. I used the STN network |
| # note (mkozuki): Why `grid_sampler` instead of `grid_sample`? | ||
| # Because `torch.nn.functional.grid_sample` calls `torch.grid_sampler`. | ||
| @parse_args("v", "v", "i", "i", "b") | ||
| def grid_sampler(g, input, grid, mode_enum, padding_mode_enum, align_corners): |
There was a problem hiding this comment.
I would annotate the param and return types and include a docstring for the function.
|
@pytorchbot merge this |
Summary: summary - Adds `F.grid_sample` support - Adds a test case Fixes #27212 Pull Request resolved: #76159 Approved by: https://github.com/justinchuby, https://github.com/BowenBao Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/0ae3aa648e0d997af4d5c092a6ad7a06c8f65798 Reviewed By: malfet Differential Revision: D36101848 Pulled By: malfet fbshipit-source-id: bb271ec0a4728056a58bac469638c5019a6c46c7
summary
F.grid_samplesupportFixes #27212