Goal: to successfully save and load in a HuggingFace NLP model.
Kernel: conda_pytorch_p36
. I performed Restart & Run All, and refreshed file view in working directory.
I'm following along with this code tutorial, the first Python code module.
Update: I need to have a transformers.onnx
file. Where can I download this?
pip install transformers
pip install onnxruntime
pip install onnx
Code:
import onnxruntime as ort
from transformers import BertTokenizerFast
tokenizer = BertTokenizerFast.from_pretrained("bert-base-cased")
ort_session = ort.InferenceSession("onnx/bert-base-cased/model.onnx")
inputs = tokenizer("Using BERT in ONNX!", return_tensors="np")
outputs = ort_session.run(["last_hidden_state", "pooler_output"], dict(inputs))
Traceback:
---------------------------------------------------------------------------
NoSuchFile Traceback (most recent call last)
<ipython-input-5-6c2daa1cf144> in <module>
5 tokenizer = BertTokenizerFast.from_pretrained("bert-base-cased")
6
----> 7 ort_session = ort.InferenceSession("onnx/bert-base-cased/model.onnx")
8
9 inputs = tokenizer("Using BERT in ONNX!", return_tensors="np")
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py in __init__(self, path_or_bytes, sess_options, providers, provider_options)
278
279 try:
--> 280 self._create_inference_session(providers, provider_options)
281 except RuntimeError:
282 if self._enable_fallback:
~/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py in _create_inference_session(self, providers, provider_options)
305 session_options = self._sess_options if self._sess_options else C.get_default_session_options()
306 if self._model_path:
--> 307 sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
308 else:
309 sess = C.InferenceSession(session_options, self._model_bytes, False, self._read_config_from_model)
NoSuchFile: [ONNXRuntimeError] : 3 : NO_SUCHFILE : Load model from onnx/bert-base-cased/model.onnx failed:Load model onnx/bert-base-cased/model.onnx failed. File doesn't exist
Please let me know if there's anything else I can add to post.