Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23305

huggingface optimum circular dependency issue

$
0
0

I have a fresh virtual env where I am trying to exec an onnx model like so:

# Load Locally Saved ONNX Model and use for inferencefrom transformers import AutoTokenizerfrom optimum.onnxruntime import ORTModelForCustomTaskssentence = "This is a test sentence."local_onnx_model = ORTModelForCustomTasks.from_pretrained("./model_onnx")tokenizer = AutoTokenizer.from_pretrained("./model_onnx")inputs = tokenizer(    sentence,    padding="longest",    return_tensors="np",)outputs = local_onnx_model.forward(**inputs)print(outputs)

but it ouputs this annoying error:

The cache for model files in Transformers v4.22.0 has been updated. Migrating your old cache. This is a one-time only operation. You can interrupt this and resume the migration later on by calling `transformers.utils.move_cache()`.0it [00:00, ?it/s]2024-05-18 03:36:29.312177: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.2024-05-18 03:36:29.888001: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRTTraceback (most recent call last):  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1510, in _get_module    return importlib.import_module("." + module_name, self.__name__)  File "/home/foo/miniconda3/envs/new_virtual_env/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 "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/onnx/__main__.py", line 26, in <module>    from ...commands.export.onnx import parse_args_onnx  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/commands/__init__.py", line 17, in <module>    from .export import ExportCommand, ONNXExportCommand, TFLiteExportCommand  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/commands/export/__init__.py", line 16, in <module>    from .base import ExportCommand  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/commands/export/base.py", line 18, in <module>    from .onnx import ONNXExportCommand  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/commands/export/onnx.py", line 23, in <module>    from ...exporters import TasksManagerImportError: cannot import name 'TasksManager' from partially initialized module 'optimum.exporters' (most likely due to a circular import) (/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/__init__.py)The above exception was the direct cause of the following exception:Traceback (most recent call last):  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1510, in _get_module    return importlib.import_module("." + module_name, self.__name__)  File "/home/foo/miniconda3/envs/new_virtual_env/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 "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/onnx/graph_transformations.py", line 19, in <module>    import onnx  File "/home/foo/new_virtual_env/rezatec_cpy/src/onnx.py", line 1, in <module>    from optimum.exporters.onnx import main_export  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1500, in __getattr__    module = self._get_module(self._class_to_module[name])  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1512, in _get_module    raise RuntimeError(RuntimeError: Failed to import optimum.exporters.onnx.__main__ because of the following error (look up to see its traceback):cannot import name 'TasksManager' from partially initialized module 'optimum.exporters' (most likely due to a circular import) (/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/__init__.py)The above exception was the direct cause of the following exception:Traceback (most recent call last):  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1510, in _get_module    return importlib.import_module("." + module_name, self.__name__)  File "/home/foo/miniconda3/envs/new_virtual_env/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 "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/onnxruntime/modeling_ort.py", line 61, in <module>    from ..exporters import TasksManager  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/__init__.py", line 16, in <module>    from .tasks import TasksManager  # noqa  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 139, in <module>    class TasksManager:  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 297, in TasksManager"clip-text-model": supported_tasks_mapping(  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/tasks.py", line 111, in supported_tasks_mapping    importlib.import_module(f"optimum.exporters.{backend}.model_configs"), config_cls_name  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/importlib/__init__.py", line 126, in import_module    return _bootstrap._gcd_import(name[level:], package, level)  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/onnx/model_configs.py", line 23, in <module>    from ...onnx import merge_decoders  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1500, in __getattr__    module = self._get_module(self._class_to_module[name])  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1512, in _get_module    raise RuntimeError(RuntimeError: Failed to import optimum.onnx.graph_transformations because of the following error (look up to see its traceback):Failed to import optimum.exporters.onnx.__main__ because of the following error (look up to see its traceback):cannot import name 'TasksManager' from partially initialized module 'optimum.exporters' (most likely due to a circular import) (/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/__init__.py)The above exception was the direct cause of the following exception:Traceback (most recent call last):  File "/home/foo/new_virtual_env/rezatec_cpy/src/onnx2.py", line 1, in <module>    from optimum.onnxruntime import ORTModelForSequenceClassification  File "<frozen importlib._bootstrap>", line 1075, in _handle_fromlist  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1500, in __getattr__    module = self._get_module(self._class_to_module[name])  File "/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/transformers/utils/import_utils.py", line 1512, in _get_module    raise RuntimeError(RuntimeError: Failed to import optimum.onnxruntime.modeling_ort 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):Failed to import optimum.exporters.onnx.__main__ because of the following error (look up to see its traceback):cannot import name 'TasksManager' from partially initialized module 'optimum.exporters' (most likely due to a circular import) (/home/foo/miniconda3/envs/new_virtual_env/lib/python3.10/site-packages/optimum/exporters/__init__.py)

Its a new env and I have run:

pip install --upgrade --upgrade-strategy --no-cache-dir eager optimum[exporters,onnxruntime]

as per the docs to install the pkg.

Totally lost!


Viewing all articles
Browse latest Browse all 23305

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>