opus icon indicating copy to clipboard operation
opus copied to clipboard

Fix opus_demo lossgen when using weights file

Open jim-signal opened this issue 1 year ago • 5 comments

When trying to test opus_demo with both USE_WEIGHTS_FILE and ENABLE_LOSSGEN, it does not work. The "loss generator" data is invalid and therefore does not apply the loss.

This PR adds the lossgen data to the lpcnet weights file and loads it when running the opus_demo, when needed.

jim-signal avatar Apr 24 '24 01:04 jim-signal

Actually, on this one I think the best fix may be to always include the lossgen weights in the build rather than the blob. After all, the weights aren't in libopus and opus_demo isn't meant to be shipped anyway. Makes sense?

jmvalin avatar Apr 24 '24 05:04 jmvalin

Yes, I agree. I had tried that before but it wasn't working. However, I find that if I add

#undef USE_WEIGHTS_FILE

to the lossgen_data.h, that works. The lossgen_init() function in lossgen.c also needs the USE_WEIGHTS_FILE block adjusted.

I am not sure where lossgen_data.* is generated to adjust that or if you'd prefer to also remove all references to USE_WEIGHTS_FILE in lossgen_data.c.

jim-signal avatar Apr 24 '24 16:04 jim-signal

@janpbuethe Any idea if there's an easy way to not have the #ifdef USE_WEIGHTS_FILE when dumping the weights? The alternative would be to have lossgen.c #include "lossgen_data.c" after an #undef USE_WEIGHTS_FILE

jmvalin avatar May 02 '24 05:05 jmvalin

CWriter in the weight-exchange library has an argument enable_binary_blob which defaults to True. Setting it to False should (in theory) solve the problem.

janpbuethe avatar May 03 '24 13:05 janpbuethe

@jim-signal can you give the exp_lossgen_fix1 branch a try and see if it fixes the problem?

jmvalin avatar May 06 '24 03:05 jmvalin

Yes, that works. If I turn on USE_WEIGHTS_FILE:

  • opus_demo is about 670KB and properly does not include the weight data
  • ./dump_weights_blob yields a ~3.3MB weights_blob.bin
  • Running opus_demo with sim_loss and with/without DRED results in expected results

Thanks! Feel free to close this and merge your own patch.

jim-signal avatar May 22 '24 14:05 jim-signal

@jim-signal So I merged a more complete patch to main. Let me know if there's any issue with it.

jmvalin avatar May 22 '24 17:05 jmvalin