Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exporting and loading ONNX models #556

Open
3 tasks
sammlapp opened this issue Sep 20, 2022 · 6 comments
Open
3 tasks

Support exporting and loading ONNX models #556

sammlapp opened this issue Sep 20, 2022 · 6 comments
Labels
blocked discuss Long term ideas to consider
Milestone

Comments

@sammlapp
Copy link
Collaborator

  • We should be able to export a model to ONNX so that someone could run predictions using the model without opensoundscape.

  • Second, we should be able to load an ONNX model and generate predictions. If this is best done with a simple torch script rather than by implementing something in opensoundscape, that's fine - we can just add documentation of how to do this

  • Third, we should be able to load and ONNX model into opensoundscape such that we could re-train (eg, warm-starting) within opensoundscape

It may be necessary or at least logical to use torchaudio to incorporate preprocessing steps into the model, as mentioned in #337

Be aware of the numpy & built-in types caveats for the torch.onnx module

@sammlapp sammlapp added this to the 0.8.0 milestone Sep 20, 2022
@sammlapp
Copy link
Collaborator Author

Because ONNX will require a numeric vector input, the input will logically be either (a) audio samples or (b) a pre-processed 2d representation of the audio such as a spectrogram, potentially with multiple channels. The advantage of passing the audio sample vector (wav) is that all preprocessing parameters will be included in the model; the only thing the user has to get right is the audio sampling rate. Option (b) gives more flexibility because pre-processing does not need to be packaged into the model, but allows more opportunity for pre-processing operations and parameters to be lost or mis-implemented when the model changes hands.

@sammlapp
Copy link
Collaborator Author

Pytorch support for stft with ONNX is still a work in progress

@sammlapp
Copy link
Collaborator Author

Apparently "torch.onnx.dynamo_export" will add some onnx operators. Also, we could apparently do some custom handling to use implemented onnx functions but I don't fully understand how (see https://github.com/Alexey-Kamenev/tensorrt-dft-plugins/blob/main/tests/test_dft.py#L35 and pytorch/pytorch#81075 (comment))

Modulus has done something similar https://github.com/NVIDIA/modulus/blob/main/modulus/models/afno/afno.py#L140

If/when we implement something like this, we will need all preprocessing steps (for inference in the exported ONNX model) to be part of the pytorch model, ie layers with forward methods. This raises the question of whether we will end up entirely changing from the use of librosa and scipy to directly using the torchaudio API.

@sammlapp
Copy link
Collaborator Author

sammlapp commented Nov 1, 2023

apparently now should work!

@sammlapp
Copy link
Collaborator Author

sammlapp commented Nov 6, 2023

there's a new torch issue to follow for fft export to ONNX: pytorch/pytorch#113067

@sammlapp sammlapp added the discuss Long term ideas to consider label Apr 12, 2024
@sammlapp
Copy link
Collaborator Author

stft + onnx seems to still not be ready (pytorch/pytorch#113067 (comment))

@sammlapp sammlapp added this to the 0.11.0 milestone Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked discuss Long term ideas to consider
Projects
None yet
Development

No branches or pull requests

2 participants