Comments (2)
@XciciciX, Could you share some the detail steps to reproduce the issue?
For example, command lines to export onnx model, optimize onnx model, and test script. Or share the optimized onnx model. You can also look at operator spec if you suspect some attention node is not corrected fused: https://github.com/microsoft/onnxruntime/blob/main/docs/ContribOperators.md
from onnxruntime.
Thank you for your response. @tianleiwu
Here is part of the code related to model export.
model = whisper.load_model("medium")
x_mel = compute_features("./data/test.mp3")
x_audio = model.encoder(x_mel)
torch.onnx.export(
model.encoder,
(x_mel),
"./models/encoder.onnx",
input_names=["x"],
output_names=["out"],
dynamic_axes={
"x": {0: "batch"},
"out": {0: "batch"},
},
)
torch.onnx.export(
model.decoder,
(x_tokens, x_audio),
"./models/decoder.onnx",
input_names=["tokens", "audio"],
output_names=["out"],
dynamic_axes={
"tokens": {0: "batch", 1: "seq"},
"audio": {0: "batch"},
"out": {0: "batch", 1: "seq"},
},
)
Then, they are optimized by: python -m onnxruntime.transformers.optimizer --input ./whisper-medium-onnx/decoder.onnx --output ./whisper-medium-onnx-test/decoder__mha.onnx --float16 --model_type bart --num_heads 16 --hidden_size 1024 --use_multi_head_attention
Here are the exported models
https://drive.google.com/drive/folders/16tbQ46OB91hQtIC4XJJvwNVnl5YaVU60?usp=drive_link
encoder.onnx and decoder.onnx are not optimized. The ones with _mha are optimized.
Here is the test script. The original models can run. The optimized models can run too but the results are wrong.
import numpy as np
import onnxruntime
sess_encoder = onnxruntime.InferenceSession("./models/encoder.onnx", providers=["CUDAExecutionProvider"])
sess_decoder = onnxruntime.InferenceSession("./models/decoder.onnx", providers=["CUDAExecutionProvider"])
start = time.time()
x_mel_fp32 = compute_features("./data/test.mp3")
x_mel_fp16 = x_mel_fp32.to(dtype=torch.float16)
out_encoder, = sess_encoder.run(["out"], {"x": x_mel_fp32.numpy()})
tokens = list(tokenizer.sot_sequence_including_notimestamps)
next_token = tokenizer.sot
while len(tokens) <= max_tokens and next_token != tokenizer.eot:
out_decoder, = sess_decoder.run(
["out"],
{
"tokens": np.asarray([tokens], dtype="int64"),
"audio": out_encoder,
},
)
next_token = out_decoder[0, -1].argmax()
tokens.append(next_token)
print("took", time.time() - start, "seconds")
print(tokenizer.decode(tokens))
from onnxruntime.
Related Issues (20)
- [Feature Request] Add DFT support for CUDAExecutionProvider
- [Performance] Increased memory usage when loading from bytes HOT 5
- Can onnxruntime.quantization.quantize_dynamic() work with onnx-trt?
- CoreML EP inference result is improperly scaled HOT 3
- ORT 1.18.1 Release Candidates available for testing HOT 3
- [Build] "utf8_range::utf8_validity" does not exist HOT 5
- QDQ removal optimization from around MaxPool changes results with negative scale
- [Mobile] Cocoapods release archive zips are missing HOT 5
- Cannot create arena allocator with Environment::CreateAndRegisterAllocator on MAC M2 with clang HOT 1
- [Build] How to build for Android armeabi platform? HOT 1
- Issue with performing shape inference using symbolic_shape_infer.py with Phi-3 ONNX Models HOT 4
- [Performance] Mapfile support for certain external data files is not working HOT 1
- [Documentation] Setup the CUDA Environment is not detailed enough HOT 1
- [Documentation] phi-3 vision tutorial lacks samples for languages that are actually used for desktop development. HOT 1
- [Build] Build python interface for Onnxruntime-qnn on aarch64 Linux HOT 11
- [Build] ‘struct onnxruntime::ProviderHostCPU’ has no member named ‘UpsampleBase__AdjustOutputSizeAsPolicy’ when CONTRIB ops are disabled. HOT 15
- Initialization crash using OnnxRuntime 17.0 (previously working on 16.3)
- [Web] `Error: using ceil() in shape computation is not yet supported for AveragePool` HOT 2
- ORT 1.18 crashes on exit after using Cuda EP to run inference on a specific model HOT 2
- [Transformers Optimizer] CLIP-ViT encoder attention not getting fused HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onnxruntime.