Skip to content

Commit

Permalink
[nit][dropout] add a no-op codepath for p=0 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
blefaudeux committed Oct 29, 2021
1 parent 23389bd commit 13d2e46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/test_triton_dropout.py
Expand Up @@ -55,7 +55,7 @@ def test_dropout(shape, amp):

# Check that 0 means no dropout
y = dropout(x, p=0)
assert torch.allclose(x.to(y.dtype), y, rtol=tol)
assert torch.allclose(x.to(y.dtype), y, rtol=tol), f"{x[x>y]}"

# Check that 1 means dropout for sure
y = dropout(x, p=1)
Expand Down
5 changes: 4 additions & 1 deletion xformers/triton/dropout.py
Expand Up @@ -69,4 +69,7 @@ def grid(meta):


def dropout(x: torch.Tensor, p: float):
return _dropout.apply(x, p)
if p > 0.0:
return _dropout.apply(x, p)

return x
4 changes: 2 additions & 2 deletions xformers/triton/k_dropout.py
Expand Up @@ -24,7 +24,7 @@
)
@triton.jit
def k_dropout(
Y, X, S,
Y, X, SEEDS,
stride,
N,
p,
Expand All @@ -51,7 +51,7 @@ def k_dropout(
x = tl.load(x_ptrs, mask=mask)

# randomly prune it
seed = S + row
seed = SEEDS + row
random = tl.rand(seed.to(tl.int32), offsets)
x_keep = random > p

Expand Down

0 comments on commit 13d2e46

Please sign in to comment.