anira-project / anira

an architecture for neural network inference in real-time audio applications
https://doi.org/10.1109/IS262782.2024.10704099
Apache License 2.0
130 stars 5 forks source link

Setting the USE_LIBTORCH doesn't have any effect ? #10

Closed mchagneux closed 2 weeks ago

mchagneux commented 2 weeks ago

Hi,

I'm trying to restrict my project to the libtorch backend for now for ease of use. I'm importing the pre-built anira library (0.1.2) via find_package(anira REQUIRED), then setting

target_compile_definitions(${MY_TARGET_NAME} PUBLIC 
                                           ... other compile defs
                                           USE_LIBTORCH)

then adding include dirs and linking to the binaries, but this doesn't set the macro properly. Is there something else I should know or do ?

vackva commented 2 weeks ago

Hi again!

The USE_LIBTORCH definition won’t have the desired effect in this case. Once a shared library is compiled, trying to change a definition afterwards won’t work anymore, as they are processed at compile time.

In this case, you have two options: either include anira as a submodule in your project (check nn-inference-template as an example) or build anira separately and include it as a "pre-built" library, as you're currently doing. In both case customize the build by setting ANIRA_WITH_ONNXRUNTIME and ANIRA_WITH_TFLITE to OFF before configuring your CMake project.

Let me know if you need further assistance!

mchagneux commented 2 weeks ago

Oh alright, got it, thanks for the answer! If I simply want to not use the other backends, is it fine if I just give empty initializers in the constructors of the inference configs ? Like, just populate the libtorch fields.

faressc commented 2 weeks ago

Hi Mattis, for the anira version 0.1.3 this is not possible unfortunately. But the version on the develop branch does support to only pass models to some of the backends that had been included in anira. This new version also has many improvements and features such as multichannel support and multiple input and output tensor support. Also we did change the API a little (coherence between camelcase and snakecase) and the readme files are not fully up to date yet. But you can have a look at the examples in order to update your code to work with the new version. The readme files will also be updated soon and then we will have a major new release on the main branch. This will happen latest on Wednesday.

vackva commented 2 weeks ago

Question answered. Also added a feature to anira to allow submission of a model configuration for a single backend, even if the library is built with multiple backends. This is now available with anira v1.0.0.