huggingface / huggingface/setfit
Token padding makes ONNX inference 6x slower, is attention_mask being used properly?
- Dominant language
- Jupyter Notebook
- Stars
- 2.8k
- Forks
- 267
- Avg merge
- 36m
- Merged PRs (30d)
- 5
Description
Here's some code that loads in my ONNX model and tokenizes 293 short examples. The longest length in the set is 153 tokens:
```python
input_text = test_ds['text']
import onnxruntime
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(model_id)
inputs = tokenizer(
input_text,
max_length=512,
padding='longest',
truncation=True,
return_attention_mask=True,
return_token_type_ids=True,
return_tensors="np",
)
session = onnxruntime.InferenceSession(onnx_path)
```
```python
onnx_preds = session.run(None, dict(inputs))[0]
```
This runs in about 15-20 seconds for me. However, when I set `padding='max_length'` it takes about 1min20secs. Isn't the point of `attention_mask` to avoid this? The base model is `intfloat/e5-small`, Microsoft's e5 model which AFAICT is similar to mpnet.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.