Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get reshape error for Tensorflow BERT model #204

Closed
jayjaywg opened this issue Dec 18, 2018 · 5 comments
Closed

Get reshape error for Tensorflow BERT model #204

jayjaywg opened this issue Dec 18, 2018 · 5 comments

Comments

@jayjaywg
Copy link
Member

Hi,

I converted tensorflow BERT model to onnx by https://github.com/onnx/tensorflow-onnx, but when i do inference, i met error as

GENERAL ERROR : c:\agent_work\3\s\onnxruntime\core\providers\cpu\tensor\reshape_helper.h:43 onnxruntime::ReshapeHelper::ReshapeHelper gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{70,767}

the model have three inputs with shape [100,70], i don't know where did 767 come from? can anyone help?

@jayjaywg jayjaywg changed the title Get reshape error for Tensorflow BERT model, onnxruntime\core\providers\cpu\tensor\reshape_helper.h:43 onnxruntime::ReshapeHelper::ReshapeHelper gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{70,767} Get reshape error for Tensorflow BERT model Dec 18, 2018
@yufenglee
Copy link
Member

@jayjaywg the input shape:{70,767} is for operator reshape, not the model input. I guess there may be something wrong with the converter. Could you please share the model to @pengwa and @guschmue ? Or log an issue in https://github.com/onnx/tensorflow-onnx instead?

@guschmue
Copy link
Contributor

guschmue commented Jan 2, 2019

To convert a tensorflow bert model, follow the instructions here:
https://gist.github.com/guschmue/9f2ba608414bef13fa67cdf278ca1e99

@WilliamTambellini
Copy link
Contributor

Hi @guschmue
Could you please precise what you mean by :
"We want to use placeholders but the TpuEstimator used in run_squad.py doesn't support this,
we require a small change in run_squad.py / model_fn_builder to pass in a argument to a flag
to use TpuEstimator or standard Estimator."
in export_to_saved_model.py ?
Kind

@guschmue
Copy link
Contributor

guschmue commented Feb 27, 2019

Sorry, did not get a notify for the question.
This comment in export_to_saved_model.py - we want the input to be a Placeholder when we export the model as saved_model but with the TpuEstimator that is used in bert that doesn't work so in export_to_saved_model.py (which is mostly a copy of run_squad.py) I replaced the TpuEstimator with a normal Estimator. This is the code in if USE_TPU_ESTIMATOR

@WilliamTambellini
Copy link
Contributor

Ok thanks. So perhaps the error I encounter is unrelated to that comment :

INFO:tensorflow:Done calling model_fn.
Traceback (most recent call last):
File "../export_to_saved_model.py", line 113, in
tf.app.run()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "../export_to_saved_model.py", line 108, in main
serving_input_receiver_fn=serving_input_receiver_fn)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 663, in export_savedmodel
mode=model_fn_lib.ModeKeys.PREDICT)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 789, in _export_saved_model_for_mode
strip_default_attrs=strip_default_attrs)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 907, in _export_all_saved_models
mode=model_fn_lib.ModeKeys.PREDICT)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 984, in _add_meta_graph_for_mode
config=self.config)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/estimator/estimator.py", line 1199, in _call_model_fn
raise ValueError('model_fn should return an EstimatorSpec.')
ValueError: model_fn should return an EstimatorSpec.

TBC. Tks.

mateusztabaka pushed a commit to mateusztabaka/onnxruntime that referenced this issue Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants