mirror of
https://github.com/xiph/opus.git
synced 2025-05-29 14:49:14 +00:00
cleanup, add signed-unsigned biases
This commit is contained in:
parent
40b309d92b
commit
1707b960de
3 changed files with 11 additions and 7 deletions
|
@ -56,6 +56,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
const float *bias;
|
||||
const float *subias;
|
||||
const qweight *input_weights;
|
||||
const float *recurrent_weights;
|
||||
int nb_inputs;
|
||||
|
|
|
@ -138,6 +138,9 @@ def dump_gru_layer(self, f, hf):
|
|||
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 @@ def dump_gru_layer(self, f, hf):
|
|||
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));
|
||||
|
|
10
dnn/vec.h
10
dnn/vec.h
|
@ -194,6 +194,7 @@ static inline void sparse_sgemv_accum16(float *out, const float *w, int rows, co
|
|||
}
|
||||
|
||||
#ifdef DOT_PROD
|
||||
|
||||
#define SCALE (128.f*127.f)
|
||||
#define SCALE_1 (1.f/128.f/127.f)
|
||||
|
||||
|
@ -228,11 +229,6 @@ static inline void sgemv_accum8x4(float *out, const qweight *w, int rows, int co
|
|||
}
|
||||
for (i=0;i<rows;i++) out[i] *= SCALE_1;
|
||||
}
|
||||
#else
|
||||
#define sgemv_accum sgemv_accum8x4
|
||||
#endif
|
||||
|
||||
#ifdef DOT_PROD
|
||||
|
||||
|
||||
#ifdef USE_SU_BIAS
|
||||
|
@ -308,6 +304,10 @@ static inline void sparse_sgemv_accum8x4(float *out, const qweight *w, int rows,
|
|||
#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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue