Skip to content

Commit

Permalink
Quantizing pitchdnn and rdovae weights
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvalin committed Oct 20, 2023
1 parent 290be25 commit 4598fe5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e
srcdir=`dirname $0`
test -n "$srcdir" && cd "$srcdir"

dnn/download_model.sh 9e76a7b
dnn/download_model.sh 290be25

echo "Updating build configuration files, please wait...."

Expand Down
20 changes: 14 additions & 6 deletions dnn/torch/neural-pitch/export_neuralpitch_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,26 @@ def c_export(args, model):
"""
)

layers = [
dense_layers = [
('if_upsample.0', "dense_if_upsampler_1"),
('if_upsample.2', "dense_if_upsampler_2"),
('conv.1', "conv2d_1"),
('conv.4', "conv2d_2"),
('conv.7', "conv2d_3"),
('downsample.0', "dense_downsampler"),
("upsample.0", "dense_final_upsampler")
]


for name, export_name in layers:
for name, export_name in dense_layers:
layer = model.get_submodule(name)
dump_torch_weights(writer, layer, name=export_name, verbose=True, quantize=True, scale=None)

conv_layers = [
('conv.1', "conv2d_1"),
('conv.4', "conv2d_2"),
('conv.7', "conv2d_3")
]


for name, export_name in conv_layers:
layer = model.get_submodule(name)
dump_torch_weights(writer, layer, name=export_name, verbose=True)

Expand All @@ -79,7 +87,7 @@ def c_export(args, model):
("GRU", "gru_1"),
]

max_rnn_units = max([dump_torch_weights(writer, model.get_submodule(name), export_name, verbose=True, input_sparse=False, quantize=False)
max_rnn_units = max([dump_torch_weights(writer, model.get_submodule(name), export_name, verbose=True, input_sparse=False, quantize=True, scale=None, recurrent_scale=None)
for name, export_name in gru_layers])

writer.header.write(
Expand Down
2 changes: 2 additions & 0 deletions dnn/write_lpcnet_weights.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#ifdef USE_WEIGHTS_FILE
#undef USE_WEIGHTS_FILE
#endif
#include "pitchdnn_data.c"
#include "fargan_data.c"
#include "plc_data.c"
#include "dred_rdovae_enc_data.c"
Expand Down Expand Up @@ -70,6 +71,7 @@ void write_weights(const WeightArray *list, FILE *fout)
int main(void)
{
FILE *fout = fopen("weights_blob.bin", "w");
write_weights(pitchdnn_arrays, fout);
write_weights(fargan_arrays, fout);
write_weights(lpcnet_plc_arrays, fout);
write_weights(rdovaeenc_arrays, fout);
Expand Down

0 comments on commit 4598fe5

Please sign in to comment.