microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.73k stars 2.94k forks source link

Longformer `convert_to_onnx.py` not working due to missing imports #19149

Open cesarrodrig opened 10 months ago

cesarrodrig commented 10 months ago

Describe the issue

When using onnxruntime/python/tools/transformers/models/longformer/convert_to_onnx.py and following its instructions, there are import errors, specifically from torch_onnx_export_helper import torch_onnx_export and from onnx_model_bert import BertOnnxModel. I've putting the steps into a Dockerfile running python 3.8 to make sure the environment was the same and I still get the import errors.

To reproduce

Dockerfile:

FROM python:3.8-bullseye

RUN python3 -m pip install torch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
RUN python3 -m pip install coloredlogs flatbuffers numpy packaging sympy protobuf==3.20.1 onnx==1.12.0 transformers==4.18.0
RUN python3 -m pip install -i https://test.pypi.org/simple/ ort-nightly
RUN python3 -m pip install onnxruntime==1.11

RUN git clone https://github.com/microsoft/onnxruntime.git

RUN cd onnxruntime/onnxruntime/python/tools/transformers/models/longformer/torch_extensions && \
    rm -rf build && \
    python setup.py install

RUN cd onnxruntime/onnxruntime/python/tools/transformers/models/longformer && \
    python convert_to_onnx.py --model longformer-base-4096 --precision fp16 --optimize_onnx

Urgency

No response

Platform

Linux

OS Version

debian:11

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

922a2f0

ONNX Runtime API

Python

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

tianjie491 commented 9 months ago

May be the reason for the import package position
sys.path.append("YOUR PATH/onnxruntime/onnxruntime/python/tools/transformers/")