From c7ba313a674afafcb4963a992e185fcd43b247a8 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 18 Jun 2021 17:39:35 -0400 Subject: [PATCH] Adding extra constraint to avoid saturation for SSE/AVX2 When implementing using SSSE3 or AVX2, our dot products can saturate if two adjacent weights sum to more than 127. --- dnn/training_tf2/lpcnet.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dnn/training_tf2/lpcnet.py b/dnn/training_tf2/lpcnet.py index bc4a97bf..6fa87597 100644 --- a/dnn/training_tf2/lpcnet.py +++ b/dnn/training_tf2/lpcnet.py @@ -131,7 +131,10 @@ class WeightClip(Constraint): self.c = c def __call__(self, p): - return K.clip(p, -self.c, self.c) + # Ensure that abs of adjacent weights don't sum to more than 127. Otherwise there's a risk of + # saturation when implementing dot products with SSSE3 or AVX2. + return self.c*p/tf.maximum(self.c, tf.repeat(tf.abs(p[:, 1::2])+tf.abs(p[:, 0::2]), 2, axis=1)) + #return K.clip(p, -self.c, self.c) def get_config(self): return {'name': self.__class__.__name__,