Skip to content

[fix] Dropout2d-3d no-batch-dim#69885

Closed
kshitij12345 wants to merge 22 commits intopytorch:masterfrom
kshitij12345:fix/dropout-2d-3d/no-batch-dim
Closed

[fix] Dropout2d-3d no-batch-dim#69885
kshitij12345 wants to merge 22 commits intopytorch:masterfrom
kshitij12345:fix/dropout-2d-3d/no-batch-dim

Conversation

@kshitij12345
Copy link
Copy Markdown
Collaborator

@kshitij12345 kshitij12345 commented Dec 14, 2021

@pytorch-probot
Copy link
Copy Markdown

pytorch-probot Bot commented Dec 14, 2021

CI Flow Status

⚛️ CI Flow

Ruleset - Version: v1
Ruleset - File: https://github.com/kshitij12345/pytorch/blob/1aad29b84da3f835206aed75da9125fc22e20846/.github/generated-ciflow-ruleset.json
PR ciflow labels: ciflow/default

Workflows Labels (bold enabled) Status
Triggered Workflows
linux-bionic-py3.6-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/noarch, ciflow/xla ✅ triggered
linux-docs ciflow/all, ciflow/cpu, ciflow/default, ciflow/docs, ciflow/linux ✅ triggered
linux-vulkan-bionic-py3.6-clang9 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/vulkan ✅ triggered
linux-xenial-cuda11.3-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3-clang5-mobile-build ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3-clang5-mobile-custom-build-static ciflow/all, ciflow/default, ciflow/linux, ciflow/mobile ✅ triggered
linux-xenial-py3.6-clang7-asan ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/sanitizers ✅ triggered
linux-xenial-py3.6-clang7-onnx ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux, ciflow/onnx ✅ triggered
linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3.6-gcc7 ciflow/all, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
linux-xenial-py3.6-gcc7-bazel-test ciflow/all, ciflow/bazel, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
pytorch-linux-xenial-py3-clang5-android-ndk-r19c-gradle-custom-build-single-full-jit ciflow/all, ciflow/android, ciflow/cpu, ciflow/default, ciflow/linux ✅ triggered
win-vs2019-cpu-py3 ciflow/all, ciflow/cpu, ciflow/default, ciflow/win ✅ triggered
win-vs2019-cuda11.3-py3 ciflow/all, ciflow/cuda, ciflow/default, ciflow/win ✅ triggered
Skipped Workflows
caffe2-linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux 🚫 skipped
docker-builds ciflow/all 🚫 skipped
ios-12-5-1-arm64 ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-coreml ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-custom-ops ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-full-jit ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-arm64-metal ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-x86-64 ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-x86-64-coreml ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
ios-12-5-1-x86-64-full-jit ciflow/all, ciflow/ios, ciflow/macos 🚫 skipped
libtorch-linux-xenial-cuda10.2-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux 🚫 skipped
libtorch-linux-xenial-cuda11.3-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux 🚫 skipped
linux-bionic-cuda10.2-py3.9-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/slow 🚫 skipped
linux-docs-push ciflow/all, ciflow/cpu, ciflow/linux, ciflow/scheduled 🚫 skipped
macos-10-15-py3-arm64 ciflow/all, ciflow/macos 🚫 skipped
macos-10-15-py3-lite-interpreter-x86-64 ciflow/all, ciflow/macos 🚫 skipped
macos-11-py3-x86-64 ciflow/all, ciflow/macos 🚫 skipped
parallelnative-linux-xenial-py3.6-gcc5.4 ciflow/all, ciflow/cpu, ciflow/linux 🚫 skipped
periodic-libtorch-linux-bionic-cuda11.5-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-libtorch-linux-xenial-cuda11.1-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/libtorch, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-bionic-cuda11.5-py3.6-gcc7 ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-linux-xenial-cuda10.2-py3-gcc7-slow-gradcheck ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled, ciflow/slow, ciflow/slow-gradcheck 🚫 skipped
periodic-linux-xenial-cuda11.1-py3.6-gcc7-debug ciflow/all, ciflow/cuda, ciflow/linux, ciflow/scheduled 🚫 skipped
periodic-win-vs2019-cuda11.1-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped
periodic-win-vs2019-cuda11.5-py3 ciflow/all, ciflow/cuda, ciflow/scheduled, ciflow/win 🚫 skipped

You can add a comment to the PR and tag @pytorchbot with the following commands:
# ciflow rerun, "ciflow/default" will always be added automatically
@pytorchbot ciflow rerun

# ciflow rerun with additional labels "-l <ciflow/label_name>", which is equivalent to adding these labels manually and trigger the rerun
@pytorchbot ciflow rerun -l ciflow/scheduled -l ciflow/slow

For more information, please take a look at the CI Flow Wiki.

@kshitij12345 kshitij12345 added the module: nn Related to torch.nn label Dec 14, 2021
Copy link
Copy Markdown
Contributor

@jbschlosser jbschlosser left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

FYI I think the failing checks are happening because the OpInfo for nn.functional.dropout2d is wrong - looks like it's generating inputs with dim in range [2, 4] instead of [3, 4].

Comment thread test/test_nn.py Outdated
@kshitij12345
Copy link
Copy Markdown
Collaborator Author

Looks like JIT tests are also failing. Will have a look.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

facebook-github-bot commented Dec 15, 2021

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 546af0d (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).

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

Click here to manually regenerate this comment.

@kshitij12345
Copy link
Copy Markdown
Collaborator Author

@jbschlosser I couldn't find a test for Dropout2d and Dropout3d where we check that channel is being zeroed, not sure as to how we can test that.

@jbschlosser
Copy link
Copy Markdown
Contributor

@jbschlosser I couldn't find a test for Dropout2d and Dropout3d where we check that channel is being zeroed, not sure as to how we can test that.

One option is to input a tensor that is known to be fully non-zero and check that the output only has entire channels zeroed out (i.e. anywhere a zero is present, the entire channel should also be zero).

Comment thread test/test_nn.py
for b, c in product(range(B), range(C)):
self.assertTrue(result[b, c].count_nonzero() in (0, channel_numel))

@expectedFailureXLA # seems like freeze_rng_state is not honoured by XLA
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.

boo :(

supports_out=False,
sample_inputs_func=partial(sample_inputs_dropout, train=True, min_input_dim=2),
# As per the docs, valid input dims are (4, 5)
sample_inputs_func=partial(sample_inputs_dropout, train=True, valid_input_dim=(4, 5)),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is OpInfo entry for feature_alpha_dropout.

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 is good for the purposes of this PR, but eventually FeatureAlphaDropout should be documented and tested to work on dims besides 4 and 5 (see #69960 (comment))

supports_out=False,
sample_inputs_func=partial(sample_inputs_dropout, min_input_dim=2),
# As per the docs, valid input dims are (3, 4)
sample_inputs_func=partial(sample_inputs_dropout, valid_input_dim=(3, 4)),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is OpInfo entry for dropout2d.

Comment thread test/cpp/api/functional.cpp
@kshitij12345 kshitij12345 marked this pull request as ready for review December 16, 2021 14:21
@kshitij12345 kshitij12345 requested a review from albanD as a code owner December 16, 2021 14:21
@albanD albanD removed their request for review December 16, 2021 14:22
@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

@jbschlosser
Copy link
Copy Markdown
Contributor

Hey @kshitij12345, FYI there's a whole bunch of internal breakage from this change. It seems there are people using dropout2d with 2D inputs expecting normal dropout to occur, which does happen to be the case. There may also be people passing 3D inputs expecting something, and redefining 3D to mean no-batch-dim input would silently break them, which is worse than loudly breaking them. So I propose a tweak to this PR to handle this case:

  1. Start by restricting input to 4D (N, C, H, W) for Dropout2d and throwing an error for other input dims. Change the docs back to indicate that this is the only supported shape. Do this for a full release to help remove invalid usages of 3D inputs with dropout2d.
  2. After a release cycle, we can add no-batch-dim support by allowing 3D. This should help avoid the silent breakage.

(do the analogous thing for Dropout3d / 5D input as well)

wdyt about this?

@kshitij12345
Copy link
Copy Markdown
Collaborator Author

Wouldn't this be weird? The support for no-batch-dim for these two modules was added in 1.10. We remove it in 1.11 and bring it back with new semantics in 1.12?

https://pytorch.org/docs/1.10.0/generated/torch.nn.Dropout2d.html?highlight=dropout2d#torch.nn.Dropout2d
https://pytorch.org/docs/1.10.0/generated/torch.nn.Dropout3d.html?highlight=dropout3d#torch.nn.Dropout3d

@kshitij12345
Copy link
Copy Markdown
Collaborator Author

@jbschlosser as discussed offline, I have updated the PR to be less strict.

Copy link
Copy Markdown
Contributor

@jbschlosser jbschlosser left a comment

Choose a reason for hiding this comment

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

Thanks for the update! Minor comments below for warning wording to make deprecations actionable

Comment thread torch/nn/functional.py Outdated
Comment on lines +1356 to +1357
warn_msg = ("dropout3d: 3-D input is being deprecated for Dropout3d."
" Look at the docs for correct input shapes and usage.")
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.

nit: deprecation should be actionable to remove the warning - in this case, switching to F.dropout is the way to go:

Received a 3D input to dropout3d, which is deprecated and will result in an error in a future release. To retain the behavior and silence this warning, please use dropout instead. Note that dropout3d exists to provide channel-wise dropout on inputs with 3 spatial dimensions, a channel dimension, and an optional batch dimension (i.e. 4D or 5D inputs).

Comment thread torch/nn/functional.py Outdated
Comment on lines +1317 to +1318
warn_msg = ("dropout2d: 2-D input is being deprecated for Dropout2d."
" Look at the docs for correct input shapes and usage.")
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.

Wording suggestion as below:

Received a 2D input to dropout2d, which is deprecated and will result in an error in a future release. To retain the behavior and silence this warning, please use dropout instead. Note that dropout2d exists to provide channel-wise dropout on inputs with 2 spatial dimensions, a channel dimension, and an optional batch dimension (i.e. 3D or 4D inputs).

@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

Comment thread torch/nn/functional.py Outdated
Copy link
Copy Markdown
Contributor

@jbschlosser jbschlosser left a comment

Choose a reason for hiding this comment

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

Thanks for the update! One minor thing and we can get this in :)

Comment thread torch/nn/functional.py Outdated
assert inp_dim in (2, 3, 4), msg
if inp_dim == 2:
if inp_dim not in (3, 4):
warn_msg = ("dropout2d: Received a 2D input to dropout2d, which is deprecated "
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.

nit: warning msg should correctly specify the dimension of the input now; here it's hardcoded to 2D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sorry. Thanks :)

Comment thread torch/nn/functional.py Outdated
assert inp_dim in (3, 4, 5), msg
if inp_dim == 3:
if inp_dim not in (4, 5):
warn_msg = ("dropout3d: Received a 3D input to dropout3d, which is deprecated "
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.

Same here

@facebook-github-bot
Copy link
Copy Markdown
Contributor

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

facebook-github-bot pushed a commit that referenced this pull request Feb 2, 2022
Summary:
Fixes #69801

TODO:
* [x] Update C++ API

cc albanD mruberry jbschlosser walterddr kshitij12345

Pull Request resolved: #69885

Reviewed By: mruberry

Differential Revision: D33175470

Pulled By: jbschlosser

fbshipit-source-id: c9d7d9e0f59ba290a0157725c338a345f3d58b9f
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 2, 2022

Hey kshitij12345.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@jbschlosser jbschlosser added the topic: bug fixes topic category label Feb 2, 2022
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Feb 3, 2022
Summary:
Fixes pytorch/pytorch#69801

TODO:
* [x] Update C++ API

cc albanD mruberry jbschlosser walterddr kshitij12345

Pull Request resolved: pytorch/pytorch#69885

Reviewed By: mruberry

Differential Revision: D33175470

Pulled By: jbschlosser

fbshipit-source-id: c9d7d9e0f59ba290a0157725c338a345f3d58b9f
(cherry picked from commit 7e4271a)
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Feb 3, 2022
Summary:
Fixes pytorch/pytorch#69801

TODO:
* [x] Update C++ API

cc albanD mruberry jbschlosser walterddr kshitij12345

Pull Request resolved: pytorch/pytorch#69885

Reviewed By: mruberry

Differential Revision: D33175470

Pulled By: jbschlosser

fbshipit-source-id: c9d7d9e0f59ba290a0157725c338a345f3d58b9f
(cherry picked from commit 7e4271a)
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Feb 9, 2022
Summary:
Fixes pytorch/pytorch#69801

TODO:
* [x] Update C++ API

cc albanD mruberry jbschlosser walterddr kshitij12345

Pull Request resolved: pytorch/pytorch#69885

Reviewed By: mruberry

Differential Revision: D33175470

Pulled By: jbschlosser

fbshipit-source-id: c9d7d9e0f59ba290a0157725c338a345f3d58b9f
(cherry picked from commit 7e4271a)
cyyever pushed a commit to cyyever/pytorch_private that referenced this pull request Feb 9, 2022
Summary:
Fixes pytorch/pytorch#69801

TODO:
* [x] Update C++ API

cc albanD mruberry jbschlosser walterddr kshitij12345

Pull Request resolved: pytorch/pytorch#69885

Reviewed By: mruberry

Differential Revision: D33175470

Pulled By: jbschlosser

fbshipit-source-id: c9d7d9e0f59ba290a0157725c338a345f3d58b9f
(cherry picked from commit 7e4271a)
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 25, 2026
Summary:
Fixes pytorch#69801

TODO:
* [x] Update C++ API

cc albanD mruberry jbschlosser walterddr kshitij12345

Pull Request resolved: pytorch#69885

Reviewed By: mruberry

Differential Revision: D33175470

Pulled By: jbschlosser

fbshipit-source-id: c9d7d9e0f59ba290a0157725c338a345f3d58b9f
(cherry picked from commit 7e4271a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dropout2d doesn't drop channels for (C, H, W)

4 participants