Try a more exact way to round to uint8 that should prevent ever wrapping around to zero

This commit is contained in:
Daniel Povey 2022-10-23 20:56:26 +08:00
parent d6aa386552
commit 85657946bb

View File

@ -922,7 +922,8 @@ class DoubleSwishFunction(torch.autograd.Function):
if requires_grad:
# discretize s. This should be expectation-preserving if we just divide the
# result by 255.
s = ((s * 255) + torch.rand_like(s)).to(torch.uint8)
s = s.to(torch.float)
s = ((s * 254.99) + torch.rand_like(s)).to(torch.uint8)
ctx.save_for_backward(s, y)
return y