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

Use gpu for random number generation #1

Open
the-moliver opened this issue Mar 29, 2018 · 1 comment
Open

Use gpu for random number generation #1

the-moliver opened this issue Mar 29, 2018 · 1 comment

Comments

@the-moliver
Copy link

Thanks for posting this. However I found you can make things much faster by using the gpu for generating your random numbers as below:

class GaussianDropout(nn.Module):
    def __init__(self, alpha=1.0):
        super(GaussianDropout, self).__init__()
        self.alpha = torch.cuda.FloatTensor([alpha])
        
    def forward(self, x):
        """
        Sample noise   e ~ N(1, alpha)
        Multiply noise h = h_ * e
        """
        if self.train():
            epsilon = torch.cuda.FloatTensor(*x.size()).normal_() * self.alpha + 1

            epsilon = Variable(epsilon)

            return x * epsilon
        else:
            return x
@j-min
Copy link
Owner

j-min commented Apr 5, 2018

Thanks! I will merge PR if you make one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants