-
Notifications
You must be signed in to change notification settings - Fork 111
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
[Help is wanted] Support mace/onnx/tflite #51
Comments
Hi, I am working on exporting an onnx model from rnn-t. Do you have any plan or roadmap for this issue? I exported encoder (Conformer) with these steps:
With these changes, I am able to convert encoder to onnx version.
If we check outputs are same or not:
atol=1e-7 returns False. I am also working on Decoder and Joiner |
Great work! Thanks! For
I recommend using if torch.jit.is_scripting() or torch.onnx.is_in_onnx_export():
return x (See https://pytorch.org/docs/stable/onnx.html#torch.onnx.is_in_onnx_export) For
Could you please make a PR to icefall with your fix?
Since you are starting with https://github.com/k2-fsa/icefall/tree/master/egs/librispeech/ASR/pruned_transducer_stateless3, I think you will get three files after exporting to onnx:
After exporting to onnx, I would recommend creating a file After testing that the export goes well, I suggest creating a file like what Now it comes to the sherpa part. We have to select one runtime that supports onnx. I suggest that we start with https://github.com/microsoft/onnxruntime/. We can switch to other runtimes when we have more experience with [EDITED]: We may choose to support compiling sherpa into some binaries/libraries for deployment, without depending on libtorch. |
I notice that I forget to add a step above. I also change torch.as_strided() function with my implementation. When I try to export with torch.as_strided(), I got this error:
Hence, I changed conformer.py:RelPositionMultiheadAttention().rel_shift():
to
where
|
Hi, exporting onnx models is almost done. https://github.com/EmreOzkose/icefall/tree/onnx. When I tested with a sample wav, pretrained.py and onnx_pretrained.wav files are giving the same input. However there are some issue:
|
@EmreOzkose |
That looks to me like there was a bug in
This looks to me like there was a bug in the onnx export code that specific version of Torch you were using. The current code looks nothing like the code in your error message, so I am assuming the issue was fixed long ago. |
The reason is that you are passing a However, in your re-implementation of |
Incidentally, the use of as_strided() in the implementation may not be 100% necessary. You could look at the history of that code, at some point I implemented it that way as I felt it was either easier to understand or more efficient, but it should be equivalent to the previous implementation. |
if torch.jit.is_tracing():
rows = torch.arange(start=time1 - 1, end=-1, step=-1)
cols = torch.arange(time1)
rows = rows.repeat(batch_size * num_heads).unsqueeze(-1)
indexes = rows + cols
x = x.reshape(-1, n)
x = torch.gather(x, dim=1, index=indexes)
x = x.reshape(batch_size, num_heads, time1, time1)
return x
else:
# Note: TorchScript requires explicit arg for stride()
batch_stride = x.stride(0)
head_stride = x.stride(1)
time1_stride = x.stride(2)
n_stride = x.stride(3)
return x.as_strided(
(batch_size, num_heads, time1, time2),
(batch_stride, head_stride, time1_stride - n_stride, n_stride),
storage_offset=n_stride * (time1 - 1),
) I have written a version using |
Hi, after Icefall, I also integrated onnx models to Sherpa and pushed them to my fork. There are 2 issues:
I also had to change egs/librispeech/ASR/pruned_transducer_stateless3/export.py, added exporting layers of Joiner. In my experiments, rtf is decreased by approximately 1/3 on CPU. jit model: 0.0937 |
@EmreOzkose Supporting more than one inference framework in Would you mind porting your onnx related c++ code to https://github.com/k2-fsa/sherpa-onnx Thanks! |
Yes, that looks good to me. |
libtorch
is easy to use. However, the size of its shared libraries is large, see below.It is nice to support the following frameworks that are more lightweight compared to libtorch.
(More frameworks may be added later)
The text was updated successfully, but these errors were encountered: