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

Allow nn.ChannelShuffle to run without erroring on CUDA tensors #105351

Closed
wants to merge 1 commit into from

Conversation

isdanni
Copy link
Contributor

@isdanni isdanni commented Jul 17, 2023

Summary: Include GPU support for nn.ChannelShuffle & update test.

Fix: #104603

Test Plan: Please see GitHub Actions.

Differential Revision: D47523764

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 17, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/105351

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 5afad35:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: nn release notes category label Jul 17, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D47523764

@isdanni
Copy link
Contributor Author

isdanni commented Jul 17, 2023

Could you please review this diff? :)

cc @kimishpatel @mikaylagawarecki

@mikaylagawarecki mikaylagawarecki changed the title Add GPU support for nn.ChannelShuffle Allow nn.ChannelShuffle to run without error on CUDA tensors Jul 17, 2023
@mikaylagawarecki mikaylagawarecki changed the title Allow nn.ChannelShuffle to run without error on CUDA tensors Allow nn.ChannelShuffle to run without erroring on CUDA tensors Jul 17, 2023
test/test_nn.py Outdated
@@ -6490,6 +6490,10 @@ def test_affine_grid_3d(self):
self.assertEqual(input_cpu.grad, input_gpu.grad)

def test_channel_shuffle(self):
device_list = ['cpu']
Copy link
Contributor

Choose a reason for hiding this comment

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

you can move this test to TestNNDeviceType to parameterize over device rather than using a device_list here

Copy link
Contributor

@mikaylagawarecki mikaylagawarecki left a comment

Choose a reason for hiding this comment

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

Thanks @isdanni for the fix. I modified the PR title slightly to avoid giving the impression that a CUDA kernel had been added for ChannelShuffle :)

I'm not sure whether you have any interest here but I am curious whether you would be interested in adding a ModuleInfo for torch.nn.ChannelShuffle.

At a high level, ModuleInfos allow a more centralized testing framework for nn.Module, each ModuleInfo in the module_db over here has an associated sample_inputs function and tests in test_modules.py are run over each the sample_inputs for each module.

I can provide more detail if you would be interested. But for this PR just moving the test to the TestNNDeviceType class is sufficient :)

…rch#105351)

Summary:
Pull Request resolved: pytorch#105351

Include GPU support for `nn.ChannelShuffle` & update test.

Test Plan: Please see GitHub Actions.

Differential Revision: D47523764

fbshipit-source-id: 70c6c7e385386adf3b2dcec25003ab42a3ed0121
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D47523764

@isdanni
Copy link
Contributor Author

isdanni commented Jul 18, 2023

Thanks @isdanni for the fix. I modified the PR title slightly to avoid giving the impression that a CUDA kernel had been added for ChannelShuffle :)

I'm not sure whether you have any interest here but I am curious whether you would be interested in adding a ModuleInfo for torch.nn.ChannelShuffle.

At a high level, ModuleInfos allow a more centralized testing framework for nn.Module, each ModuleInfo in the module_db over here has an associated sample_inputs function and tests in test_modules.py are run over each the sample_inputs for each module.

I can provide more detail if you would be interested. But for this PR just moving the test to the TestNNDeviceType class is sufficient :)

Thanks for the quick review! I moved it under TestNNDeviceType and added @skipMeta(Since we are only testing CPU and CUDA atm).

I'm interested in adding ModuleInfo for nn.ChannelShuffle. Will send a separate PR soon. And yes a bit extra information would definitely be helpful :)

@mikaylagawarecki mikaylagawarecki added the topic: improvements topic category label Jul 18, 2023
Copy link
Contributor

@mikaylagawarecki mikaylagawarecki left a comment

Choose a reason for hiding this comment

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

Thanks!

@mikaylagawarecki
Copy link
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 18, 2023
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@kimishpatel
Copy link
Contributor

Just for my understanding, there is no cuda impl for channel shuffle in this diff. Then how is it allowing channel shuffle to run when input tensors are cuda tensors? Are you converting them to cpu tensors somewhere?

@mikaylagawarecki
Copy link
Contributor

@kimishpatel adding

dispatch:
    CPU, CUDA: cpu_impl

in native_functions allows the CPU impl to be run for CUDA tensors is my understanding, so this doesn't actually add a CUDA impl but just prevents ChannelShuffle from erroring out if it is passed inputs that are on CUDA. Does that sound reasonable to you?

@kimishpatel
Copy link
Contributor

@kimishpatel adding

dispatch:
    CPU, CUDA: cpu_impl

in native_functions allows the CPU impl to be run for CUDA tensors is my understanding, so this doesn't actually add a CUDA impl but just prevents ChannelShuffle from erroring out if it is passed inputs that are on CUDA. Does that sound reasonable to you?

Right. I understood that, but what I dont understand is what happens when you actually dispatch to CPU impl. Shouldnt it error out then?

isdanni added a commit to isdanni/pytorch that referenced this pull request Nov 17, 2023
Summary:
Pull Request resolved: pytorch#106525

Add ModuleInfo for torch.nn.ChannelShuffle:

pytorch#105351 (review)

Test Plan: Please see GitHub Actions.

Differential Revision: D48021100

fbshipit-source-id: d00d20c631e9d8f261239305343d07ae70f55b54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request fb-exported Merged release notes: nn release notes category topic: improvements topic category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistency in nn.ChannelShuffle Behavior with Empty Input Tensor on CPU and CUDA
5 participants