-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Export LayoutLMv2 to onnx #14368
Comments
I believe @NielsRogge can help out here |
I'm not an ONNX expert, however. Pinging @michaelbenayoun for this. |
@michaelbenayoun can you please help here. |
I think it might have to do with the fact that your dummy inputs don't have the image field, so the inputs might be off? |
It seems to come from the There are two ways of solving this issue:
|
Hi @michaelbenayoun ,
Now when I am trying to run the below code,
I am facing the below error.
One more thing, for dummy input I have provide image as |
+1 |
1 similar comment
+1 |
Hi, Would be great if you could Google the errors before pinging us (because we at Huggingface are pretty busy). Eg in this case, you can find the answer in the first result on Google: onnx/tutorials#63 (comment) => The reason is that LayoutLMv2 uses a visual backbone, which includes layers like AdapativeAvgPool2d which aren't supported natively by ONNX. |
Hi @NielsRogge , Would you please point out where I am making error in the code below.
Running the above code is raising the below error,
|
@fadi212 Have you tried using another |
my model is converted to onnx but at time of loading model to onnxruntime I am getting below error. |
Hi, Can you check out the solution provided here? Also, if you managed to convert the model to ONNX, feel free to open a PR which we can review, it will benefit the community a lot. Thanks! |
Hi @lalitr994 , |
@fadi212 can you share your repo. how you have converted and loaded onnx model to onnx runtime? I am stucked at loading model to run time. |
Hi @lalitr994 , logger = logging.get_logger(name) # pylint: disable=invalid-name class LayoutLMv2OnnxConfig(OnnxConfig):
class pool_layer(nn.Module):
def ensure_model_and_config_inputs_match(
def export_model(
if name == 'main': ` Also you will have to make the change these lines in modeling_layoutlmv2 in transformers library.
` |
Hi @fadi212! Thanks for your script! I'm having some trouble exporting the May I ask you what versions of the libraries have you installed, in particular Just for the record, the segfault happens consistently at line 218 of the picture, which is located inside an optimization routine called Interestingly, by explicitly setting the I think I have narrowed down the problem to the generation of invalid ONNX code (in particular, some |
Hi @viantirreau @lalitr994 , |
Thanks @fadi212 I will try my model with this brach |
In Onnx conversion I got warning like /torch/onnx/symbolic_helper.py:258: UserWarning: ONNX export failed on adaptive_avg_pool2d because input size not accessible not supported During infer from model I got the error below @fadi212 I followed your code but facing this issue. |
Hi @riqui-puig, The code is not merged yet but you can install that particualr branch and then you can convert your model using command line. |
Hi @fadi212 Command: !python -m transformers.onnx --model=microsoft/layoutlmv2-base-uncased onnx/ Error log:
|
Has this issue been resolved? If not then I would like to work on it. |
@avisinghal6 ONNX support is now handled by the optimum library, model configs can be found here |
I am trying to export LayoutLMv2 model to onnx but there is no support for that available in transformers library.
I have tried to follow the method available for layoutLM but that is not working.
Here is config class for LayoutLMv2
Running the export line is raising this error,
The text was updated successfully, but these errors were encountered: