microsoft / microsoft/onnxruntime

ONNX model very slow for Sentence transformer model when max_seq_len of tokens = 512

Open
#9,911 5 comments 0 reactions 2 assignees View on GitHub

@gh-yewang is already working on this.

Since Dec 2, 2021.

Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

I am using a Roberta based Sentence transformer model for a chatbot. For inference I have exported the model to ONNX. When the max_length of the tokens <= 128 , the perfomance of the model is fine. But once the token length increases to 512, the ONNX model's output decreases drastically.
Even if I quantize the base model and then export to ONNX, there is no change in preformance for seq length of 512 tokens

Specs

  • OS Platform and Distribution (Mac OS Monterey)
  • ONNX Runtime installed using pip
  • ONNX Runtime version: 1.8.1
  • Python version: 3.6

I am running the model on CPU.

The code which was used to export from Sentence transformer model to ONNX model is given below

torch.onnx.export(model, (inputs['input_ids']), "roberta_model.onnx", opset_version=11, do_constant_folding=True, input_names=['input_ids'], output_names=['start', 'end'], dynamic_axes={'input_ids': [1]})

And this is how I am performing inference

options = onnxruntime.SessionOptions() options.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_ENABLE_ALL options.intra_op_num_threads = 1 self.onnxmodel = onnxruntime.InferenceSession(model_path, options)

Even if I remove options from the above snippet. The results seem to be similar.

The avg response time for inferencing on 512 tokens is around 1.3-1.4 seconds on an instance with 8vCPUs.

Can something be done about this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.