shithub: opus

Download patch

ref: 1707b960dee936f6730544e01ad3cd0fb055dbdb
parent: 40b309d92bf735af174e44e657c749bd6b5e92ba
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue Dec 29 20:11:55 EST 2020

cleanup, add signed-unsigned biases

--- a/dnn/nnet.h
+++ b/dnn/nnet.h
@@ -56,6 +56,7 @@
 
 typedef struct {
   const float *bias;
+  const float *subias;
   const qweight *input_weights;
   const float *recurrent_weights;
   int nb_inputs;
--- a/dnn/training_tf2/dump_lpcnet.py
+++ b/dnn/training_tf2/dump_lpcnet.py
@@ -138,6 +138,9 @@
     f.write('#endif /*DOT_PROD*/\n')
     printVector(f, weights[1], name + '_recurrent_weights')
     printVector(f, weights[-1], name + '_bias')
+    subias = weights[-1].copy()
+    subias[0,:] = subias[0,:] - np.sum(np.clip(weights[0], -1, 1),axis=0)
+    printVector(f, subias, name + '_subias')
     if hasattr(self, 'activation'):
         activation = self.activation.__name__.upper()
     else:
@@ -148,8 +151,8 @@
         reset_after = 1
     neurons = weights[0].shape[1]//3
     max_rnn_neurons = max(max_rnn_neurons, neurons)
-    f.write('const GRULayer {} = {{\n   {}_bias,\n   {}_weights,\n   {}_recurrent_weights,\n   {}, {}, ACTIVATION_{}, {}\n}};\n\n'
-            .format(name, name, name, name, weights[0].shape[0], weights[0].shape[1]//3, activation, reset_after))
+    f.write('const GRULayer {} = {{\n   {}_bias,\n   {}_subias,\n   {}_weights,\n   {}_recurrent_weights,\n   {}, {}, ACTIVATION_{}, {}\n}};\n\n'
+            .format(name, name, name, name, name, weights[0].shape[0], weights[0].shape[1]//3, activation, reset_after))
     hf.write('#define {}_OUT_SIZE {}\n'.format(name.upper(), weights[0].shape[1]//3))
     hf.write('#define {}_STATE_SIZE {}\n'.format(name.upper(), weights[0].shape[1]//3))
     hf.write('extern const GRULayer {};\n\n'.format(name));
--- a/dnn/vec.h
+++ b/dnn/vec.h
@@ -194,6 +194,7 @@
 }
 
 #ifdef DOT_PROD
+
 #define SCALE (128.f*127.f)
 #define SCALE_1 (1.f/128.f/127.f)
 
@@ -228,13 +229,8 @@
    }
    for (i=0;i<rows;i++) out[i] *= SCALE_1;
 }
-#else
-#define sgemv_accum sgemv_accum8x4
-#endif
 
-#ifdef DOT_PROD
 
-
 #ifdef USE_SU_BIAS
 static inline void sparse_sgemv_accum8x4(float *out, const qweight *w, int rows, int cols, const int *idx, const float *_x)
 {
@@ -308,6 +304,10 @@
 #endif /*USE_SU_BIAS*/
 
 #else /*DOT_PROD*/
+
+#define sgemv_accum sgemv_accum8x4
+
+
 static inline void sparse_sgemv_accum8x4(float *out, const qweight *w, int rows, int ignore, const int *idx, const float *x)
 {
    int i, j;
--