I'm trying to convert a huggingface model into ONNX so I can use it in BigQuery ML. The latter one allows importing ONNX models. However transformers tokenizer
is never included into the model.
How do I export a model WITH tokenizer into a single ONNX file?
Here's what I tried:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import sys
# model_name is being passed in from the command line
model_name = sys.argv[1]
# Load tokenizer and PyTorch weights form the Hub
tokenizer = AutoTokenizer.from_pretrained(model_name)
pt_model = AutoModelForSequenceClassification.from_pretrained(model_name)
# replace slashes with underscores
model_name_underscored = model_name.replace("/", "_")
# Save to disk
tokenizer.save_pretrained(model_name_underscored)
pt_model.save_pretrained(model_name_underscored)
And then
python3 -m transformers.onnx --model=./$model_name_underscored ${model_name_underscored}_onnx/
After importing it to BigQuery ML I can see that the model expects tokenized input, not a plain text.
Alternatively, how do I use AutoTokenizer within BigQuery ML so that the output of the model would be identical to the one Python script produces?