Skip to content
This repository was archived by the owner on Oct 13, 2021. It is now read-only.
This repository was archived by the owner on Oct 13, 2021. It is now read-only.

Invalid graph when converting TFBertForSequenceClassification #719

@ZJaume

Description

@ZJaume

Are text classifiaction huggingface models supported? I'm getting invalid graph when running this:

import os
from transformers import TFBertForSequenceClassification
import keras2onnx
model_keras = TFBertForSequenceClassification.from_pretrained('bert-base-cased')
model_onnx = keras2onnx.convert_keras(model_keras, model_keras.name)

import psutil
import onnxruntime
os.environ["OMP_NUM_THREADS"] = str(psutil.cpu_count(logical=True))
os.environ["OMP_WAIT_POLICY"] = 'ACTIVE'

sess_options = onnxruntime.SessionOptions()
session = onnxruntime.InferenceSession(model_onnx.SerializeToString(), sess_options)
All model checkpoint layers were used when initializing TFBertForSequenceClassification.

Some layers of TFBertForSequenceClassification were not initialized from the model checkpoint at bert-base-cased and are newly initialized: ['classifier']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
tf executing eager_mode: True
tf.keras model eager_mode: False
WARNING:tensorflow:The parameters `output_attentions`, `output_hidden_states` and `use_cache` cannot be updated when calling a model.They have to be set to True/False in the config object (i.e.: `config=XConfig.from_pretrained('name', output_attentions=True)`).
WARNING:tensorflow:The parameter `return_dict` cannot be set in graph mode and will always be set to `True`.
The ONNX operator number change on the optimization: 2428 -> 1618
Traceback (most recent call last):
  File "convert_example.py", line 16, in <module>
    session = onnxruntime.InferenceSession(model_onnx.SerializeToString(), sess_options)
  File "/work/jzaragoza/bicleaner-neural/venv/lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 280, in __init__
    self._create_inference_session(providers, provider_options)
  File "/work/jzaragoza/bicleaner-neural/venv/lib/python3.7/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 309, in _create_inference_session
    sess = C.InferenceSession(session_options, self._model_bytes, False, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : This is an invalid model. Error in Node:tf_bert_for_sequence_classification/bert/Shape:0_squeeze : Unrecognized attribute: axes for operator Squeeze

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions