mirror of
https://github.com/k2-fsa/icefall.git
synced 2025-12-11 06:55:27 +00:00
Fix randn to rand
This commit is contained in:
parent
e586cc319c
commit
d6aa386552
@ -915,13 +915,15 @@ class DoubleSwishFunction(torch.autograd.Function):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def forward(ctx, x: Tensor) -> Tensor:
|
def forward(ctx, x: Tensor) -> Tensor:
|
||||||
|
requires_grad = x.requires_grad
|
||||||
x = x.detach()
|
x = x.detach()
|
||||||
s = torch.sigmoid(x - 1.0)
|
s = torch.sigmoid(x - 1.0)
|
||||||
y = x * s
|
y = x * s
|
||||||
# discretize s. This should be expectation-preserving if we just divide the
|
if requires_grad:
|
||||||
# result by 255.
|
# discretize s. This should be expectation-preserving if we just divide the
|
||||||
s = ((s * 255) + torch.randn_like(s)).to(torch.uint8)
|
# result by 255.
|
||||||
ctx.save_for_backward(s, y)
|
s = ((s * 255) + torch.rand_like(s)).to(torch.uint8)
|
||||||
|
ctx.save_for_backward(s, y)
|
||||||
return y
|
return y
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user