huggingface / optimum

🚀 Accelerate training and inference of 🤗 Transformers and 🤗 Diffusers with easy to use hardware optimization tools
https://huggingface.co/docs/optimum/main/
Apache License 2.0
2.53k stars 453 forks source link

cannot import name 'ORTModelForSeq2SeqLM' from 'optimum.onnxruntime' #1207

Open aresa7796 opened 1 year ago

aresa7796 commented 1 year ago

System Info

optimum                       1.9.1
onnx                          1.14.0
onnxconverter-common          1.13.0
onnxruntime                   1.15.1
onnxruntime-tools             1.7.0
tf2onnx                       1.14.0
transformers                  4.31.0
torch                         2.0.1
torchaudio                    2.0.2
torchvision                   0.15.2

Who can help?

Hi, guys!

I got an error:

Traceback (most recent call last):
  File "/root/anaconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1099, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "/root/anaconda3/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/onnxruntime/modeling_seq2seq.py", line 41, in <module>
    from ..exporters.onnx import main_export
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/exporters/__init__.py", line 16, in <module>
    from .tasks import TasksManager  # noqa
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 137, in <module>
    class TasksManager:
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 270, in TasksManager
    "audio-spectrogram-transformer": supported_tasks_mapping(
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 109, in supported_tasks_mapping
    importlib.import_module(f"optimum.exporters.{backend}.model_configs"), config_cls_name
  File "/root/anaconda3/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/exporters/onnx/model_configs.py", line 42, in <module>
    from .base import ConfigBehavior, OnnxConfig, OnnxConfigWithPast, OnnxSeq2SeqConfigWithPast
  File "/root/anaconda3/lib/python3.10/site-packages/optimum/exporters/onnx/base.py", line 31, in <module>
    from ...onnx import merge_decoders
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/root/anaconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1089, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/root/anaconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1101, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import optimum.onnx.graph_transformations because of the following error (look up to see its traceback):
cannot import name 'ORTModelForSeq2SeqLM' from 'optimum.onnxruntime' (/root/anaconda3/lib/python3.10/site-packages/optimum/onnxruntime/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/mnt/public/demo/m2m_100_demo/onnx.py", line 2, in <module>
    from optimum.onnxruntime import ORTModelForSeq2SeqLM
  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist
  File "/root/anaconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1089, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "/root/anaconda3/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1101, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import optimum.onnxruntime.modeling_seq2seq because of the following error (look up to see its traceback):
Failed to import optimum.onnx.graph_transformations because of the following error (look up to see its traceback):
cannot import name 'ORTModelForSeq2SeqLM' from 'optimum.onnxruntime' (/root/anaconda3/lib/python3.10/site-packages/optimum/onnxruntime/__init__.py)

@JingyaHuang @echarlaix

Information

Tasks

Reproduction

I used this code:

from optimum.onnxruntime import ORTModelForSeq2SeqLM

Expected behavior

I used model is m2m100. Can you help me?

fxmarty commented 1 year ago

Hi, maybe you can try python -m pip uninstall optimum onnxruntime && python -m pip install optimum[onnxruntime]?

hieupth commented 1 year ago

Look like the same problem at https://github.com/huggingface/optimum/issues/1177 and I'm facing the same problem

regisss commented 1 year ago

@aresa7796 As discussed with @hieupth in #1177, your file /mnt/public/demo/m2m_100_demo/onnx.py is called onnx.py which messes up with the import of the onnx package. Could you rename it and let me know if that solves your issue?

sappho192 commented 9 months ago

@aresa7796 As discussed with @hieupth in #1177, your file /mnt/public/demo/m2m_100_demo/onnx.py is called onnx.py which messes up with the import of the onnx package. Could you rename it and let me know if that solves your issue?

I had a same problem with @hieupth , and renaming my test code file from "onnx.py" to "infer_onnx.py" resolved the problem. Thank you @regisss !