From 85657946bbaf564c677c1847e00f3b6c64affd20 Mon Sep 17 00:00:00 2001 From: Daniel Povey Date: Sun, 23 Oct 2022 20:56:26 +0800 Subject: [PATCH] Try a more exact way to round to uint8 that should prevent ever wrapping around to zero --- egs/librispeech/ASR/pruned_transducer_stateless7/scaling.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/egs/librispeech/ASR/pruned_transducer_stateless7/scaling.py b/egs/librispeech/ASR/pruned_transducer_stateless7/scaling.py index be6f94412..d4c288545 100644 --- a/egs/librispeech/ASR/pruned_transducer_stateless7/scaling.py +++ b/egs/librispeech/ASR/pruned_transducer_stateless7/scaling.py @@ -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