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

Fix device placement linspace (Closes #18) #20

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions taildropout.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ def forward(self, input: Tensor) -> Tensor:
mode = 'first_k'

if mode == 'random':
type_out = input.type()
type_out = input.dtype
device = input.device

# No cuda torch.linspace for old versions of pytorch.
linspace = torch.arange(1, n_features + 1, 1).type(type_out)
linspace = torch.arange(1, n_features + 1, 1, device=device,dtype=type_out)
# resized [1,n_features] if input 2d, [1,1,..,n_features] if nd
newshape = replace_w_ones_except(input.shape, self.dropout_dim)
linspace.resize_(newshape)
Expand All @@ -147,7 +147,7 @@ def forward(self, input: Tensor) -> Tensor:

# make [n_batch,1] noise if input 2d
newshape = replace_w_ones_except(input.shape, self.batch_dim)
uniform = input.new(*newshape).uniform_()
uniform = torch.rand(newshape, device=device, dtype=type_out)
mask = prob < uniform # 43% of cpu cumtime
mask = mask.type(type_out) # 30% of cpu cumtime
return input * mask # 23% of cpu cumtime # Note works due to broadcasting
Expand Down