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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement noise_shape keyword for Dropout layers #20058

Open
around1991 opened this issue May 2, 2019 · 7 comments
Open

Implement noise_shape keyword for Dropout layers #20058

around1991 opened this issue May 2, 2019 · 7 comments
Labels
feature A request for a proper, new feature. module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@around1991
Copy link

馃殌 Feature

Tensorflow has a noise_shape keyword for tf.nn.dropout, which specifies which dimensions should have dropout masks calculated independently and which dimensions should have shared dropout masks. PyTorch should have a similar feature too.

Motivation

This is a very useful feature to have (for example, if we process the same example multiple times, we may want to tie dropout masks for each time we see that example), and while easy to implement independently, would be good to have common functionality for.

Pitch

Include extra kwarg to torch.nn.Dropout called noise_shape, with the same functionality as tf.nn.dropout.

Alternatives

Fairly easy to implement independently, but would save hassle for many people if there was a core implementation.

@ifedan ifedan added feature A request for a proper, new feature. module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels May 2, 2019
@zhangguanheng66
Copy link
Contributor

@soumith I have a look at this feature request. If we decide to implement it, I'm happy to take this small task.

@soumith
Copy link
Member

soumith commented May 27, 2019

i think this is worth doing, but the first step to hook it up to is F.dropout in nn/functional.py
It ends up calling _VF.dropout with probability p. We should give a noise_shape to _VF.dropout which by default is the same shape as input, but otherwise it'll be a broadcastable shape.

For example:

inp = torch.randn(10, 3, 224, 224)
noise_shape = torch.Size([1, 3, 1, 1])

In here, the same random mask will be broadcasted to shape of 10, 3, 224, 224 where, masks are shared between all images across all pixels, but per-channel.

@visionscaper
Copy link

I was curious to know if anyone picked this up?

@soumith
Copy link
Member

soumith commented Jul 4, 2019

@visionscaper nope

@shihongzhi
Copy link
Contributor

I'd like to pick this up.

@visionscaper
Copy link

Sounds great @shihongzhi!

@alanhdu
Copy link
Contributor

alanhdu commented Jan 21, 2021

Hi! This is a papercut that we would also like to see solved. Is there anything we can do to speed this along?

cc @cxhernandez

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A request for a proper, new feature. module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants