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.
This commit is contained in:
Jean-Marc Valin 2021-06-18 17:39:35 -04:00
parent 237245f815
commit c7ba313a67

View file

@ -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__,