Open wppply opened 4 years ago
Looks like there is some bug in the optimizer script. @tianleiwu
@wppply @hariharans29 https://github.com/microsoft/onnxruntime/blob/fff0b41fcb7cb85321f65d68c1dedaaf7032fcb0/onnxruntime/python/tools/transformers/onnx_model_bert.py#L91
Remove [line 91-92], it work for me.
And i also change :https://github.com/microsoft/onnxruntime/blob/fff0b41fcb7cb85321f65d68c1dedaaf7032fcb0/onnxruntime/python/tools/transformers/onnx_model_bert.py#L159
to
if input.name in ["segment_ids:0", "input_mask:0", "input_ids:0"]:
But i find that model.optimizer.onnx this model does not faster than model.onnx.
My tinybert model is 2-transformer layers with 12 heads and 120 hidden_dim.
@wppply,
Thanks for reporting the issue.
The cause of the error is a path in ONNX graph like the following:
SkipLayerNormalization (SkipLayerNorm1) --> Reshape (bert/encoder/Reshape_1) --> SkipLayerNormalization (
SkipLayerNorm_AddBias_6)
The correct one:
SkipLayerNormalization (SkipLayerNorm1) --> SkipLayerNormalization (
SkipLayerNorm_AddBias_6)
For normal BERT graph, the Reshape will be removed in postprocess. However, for this model, the optimizer failed to fuse Attention and EmbedLayerNormalization (because subgraph pattern is different) so the Reshape node has not been removed.
@tianleiwu Thanks for reply. Will this issue be fixed in the next release?
meet the same error when i was used bert-base
After changing the codes @colourful-tree referred to, still got the same error. Package version: Using tensorflow=1.12.0, onnx=1.8.0, tf2onnx=1.7.2/995bd6, onnxruntime-noopenmp=1.6.0
process_embedding: Create Embedding node prune_graph: Graph pruned: 0 inputs, 0 outputs and 34 nodes are removed fuse_mask_2: Failed to fuse mask apply: Fused SkipLayerNormalization count: 24 prune_graph: Graph pruned: 0 inputs, 0 outputs and 0 nodes are removed apply: Fused FastGelu(add bias) count: 12 apply: Fused SkipLayerNormalization(add bias) count: 24 optimize: opset verion: 11
add this option in the optimizer.optimize_model
will help to solve the issue
optimization_options=BertOptimizationOptions("gpt2")
or manually make the change the option
enable_skip_layer_norm = False
This issue has been automatically marked as stale due to inactivity and will be closed in 7 days if no further activity occurs. If further support is needed, please provide an update and/or more details.
same error here - Onnx is becoming stale!
Describe the bug I am trying to follow this tutorial to transfer my 2 layer bert into ONNX and optimize with
onnxruntime_tools
. It works smoothly when I transfer my tf model from .pb to .onnx.Urgency If there are particular important use cases blocked by this or strict project-related timelines, please share more information and dates. If there are no hard deadlines, please specify none.
System information
To Reproduce I follow this tutorial https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/python/tools/transformers/notebooks/Tensorflow_Keras_Bert-Squad_OnnxRuntime_CPU.ipynb it works well for tf epxorted model --> export ONNX model --> inference --> export Optimized ONNX mdoel.
However it doesnt work after I
optimize_model
the optimization remove one redundant input "label_ids_1:0"
The following step would give me error on CPU
I uploaded my model here https://drive.google.com/drive/folders/1S7ekooSbXAu6UuyynW5RyGmL1FKtoYqh?usp=sharing
Expected behavior Expect to give me a loss like non-optimized one, and much faster 👍 Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here. If the issue is about a particular model, please share the model details as well to facilitate debugging.