optimum icon indicating copy to clipboard operation
optimum copied to clipboard

Module 'tensorflow' has no attribute 'contrib'

Open juancopi81 opened this issue 1 year ago • 2 comments

System Info

Optimum version: 1.13.2
Python 3.9.16
Tensorflow 2.12.0'

Who can help?

@JingyaHuang @echarlaix

Information

  • [X] The official example scripts
  • [ ] My own modified scripts

Tasks

  • [X] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [ ] My own task or dataset (give details below)

Reproduction (minimal, reproducible, runnable)

I am following the inpainting example in the docs and when I try:

import PIL
import requests
import torch
from io import BytesIO
from optimum.onnxruntime import ORTStableDiffusionInpaintPipeline

I get the following error:

...

RuntimeError: Failed to import optimum.onnxruntime.modeling_diffusion because of the following error (look up to see its traceback):
Failed to import transformers.pipelines because of the following error (look up to see its traceback):
module 'tensorflow' has no attribute 'contrib'

I understand that it is related with my TF version. Would you have support for this version?

Expected behavior

The imported libraries.

juancopi81 avatar Nov 01 '23 18:11 juancopi81

@juancopi81 Thank you. Could you share the full traceback?

fxmarty avatar Nov 02 '23 11:11 fxmarty

Sure! Thanks for your answer. Here it is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:1110, in _LazyModule._get_module(self, module_name)
   1109 try:
-> 1110     return importlib.import_module("." + module_name, self.__name__)
   1111 except Exception as e:

File /opt/conda/envs/venv/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:986, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:680, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:850, in exec_module(self, module)

File <frozen importlib._bootstrap>:228, in _call_with_frames_removed(f, *args, **kwds)

File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/pipelines/__init__.py:73
     72 from .question_answering import QuestionAnsweringArgumentHandler, QuestionAnsweringPipeline
---> 73 from .table_question_answering import TableQuestionAnsweringArgumentHandler, TableQuestionAnsweringPipeline
     74 from .text2text_generation import SummarizationPipeline, Text2TextGenerationPipeline, TranslationPipeline

File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/pipelines/table_question_answering.py:27
     25 import tensorflow as tf
---> 27 import tensorflow_probability as tfp
     29 from ..models.auto.modeling_tf_auto import (
     30     TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
     31     TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
     32 )

File /opt/conda/envs/venv/lib/python3.9/site-packages/tensorflow_probability/__init__.py:78
     77 # from tensorflow_probability.google import staging  # DisableOnExport
---> 78 from tensorflow_probability.python import *  # pylint: disable=wildcard-import
     79 from tensorflow_probability.python.version import __version__

File /opt/conda/envs/venv/lib/python3.9/site-packages/tensorflow_probability/python/__init__.py:21
     19 from __future__ import print_function
---> 21 from tensorflow_probability.python import bijectors
     22 from tensorflow_probability.python import distributions

File /opt/conda/envs/venv/lib/python3.9/site-packages/tensorflow_probability/python/bijectors/__init__.py:46
     45 from tensorflow_probability.python.bijectors.matrix_inverse_tril import MatrixInverseTriL
---> 46 from tensorflow_probability.python.bijectors.matveclu import MatvecLU
     47 from tensorflow_probability.python.bijectors.normal_cdf import NormalCDF

File /opt/conda/envs/venv/lib/python3.9/site-packages/tensorflow_probability/python/bijectors/matveclu.py:24
     23 from tensorflow_probability.python.bijectors import bijector
---> 24 from tensorflow_probability.python.math.linalg import lu_reconstruct
     25 from tensorflow_probability.python.math.linalg import lu_solve

File /opt/conda/envs/venv/lib/python3.9/site-packages/tensorflow_probability/python/math/__init__.py:22
     21 from tensorflow_probability.python.math.custom_gradient import custom_gradient
---> 22 from tensorflow_probability.python.math.diag_jacobian import diag_jacobian
     23 from tensorflow_probability.python.math.interpolation import batch_interp_regular_1d_grid

File /opt/conda/envs/venv/lib/python3.9/site-packages/tensorflow_probability/python/math/diag_jacobian.py:24
     22 import tensorflow as tf
---> 24 tfe = tf.contrib.eager
     26 __all__ = [
     27     'diag_jacobian',
     28 ]

AttributeError: module 'tensorflow' has no attribute 'contrib'

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

RuntimeError                              Traceback (most recent call last)
File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:1110, in _LazyModule._get_module(self, module_name)
   1109 try:
-> 1110     return importlib.import_module("." + module_name, self.__name__)
   1111 except Exception as e:

File /opt/conda/envs/venv/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:986, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:680, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:850, in exec_module(self, module)

File <frozen importlib._bootstrap>:228, in _call_with_frames_removed(f, *args, **kwds)

File /opt/conda/envs/venv/lib/python3.9/site-packages/optimum/onnxruntime/modeling_diffusion.py:43
     42 from ..onnx.utils import _get_external_data_paths
---> 43 from ..pipelines.diffusers.pipeline_stable_diffusion import StableDiffusionPipelineMixin
     44 from ..pipelines.diffusers.pipeline_stable_diffusion_img2img import StableDiffusionImg2ImgPipelineMixin

File /opt/conda/envs/venv/lib/python3.9/site-packages/optimum/pipelines/__init__.py:16
      1 # coding=utf-8
      2 # Copyright 2023 The HuggingFace Team. All rights reserved.
      3 #
   (...)
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
---> 16 from .pipelines_base import (
     17     MAPPING_LOADING_FUNC,
     18     ORT_SUPPORTED_TASKS,
     19     load_bettertransformer,
     20     load_ort_pipeline,
     21     pipeline,
     22 )

File /opt/conda/envs/venv/lib/python3.9/site-packages/optimum/pipelines/pipelines_base.py:19
     17 from typing import Any, Dict, Optional, Union
---> 19 from transformers import (
     20     AudioClassificationPipeline,
     21     AutoConfig,
     22     AutomaticSpeechRecognitionPipeline,
     23     FeatureExtractionPipeline,
     24     FillMaskPipeline,
     25     ImageClassificationPipeline,
     26     ImageSegmentationPipeline,
     27     ImageToTextPipeline,
     28     Pipeline,
     29     PreTrainedTokenizer,
     30     PreTrainedTokenizerFast,
     31     QuestionAnsweringPipeline,
     32     SequenceFeatureExtractor,
     33     SummarizationPipeline,
     34     Text2TextGenerationPipeline,
     35     TextClassificationPipeline,
     36     TextGenerationPipeline,
     37     TokenClassificationPipeline,
     38     TranslationPipeline,
     39     ZeroShotClassificationPipeline,
     40 )
     41 from transformers import pipeline as transformers_pipeline

File <frozen importlib._bootstrap>:1055, in _handle_fromlist(module, fromlist, import_, recursive)

File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:1100, in _LazyModule.__getattr__(self, name)
   1099 elif name in self._class_to_module.keys():
-> 1100     module = self._get_module(self._class_to_module[name])
   1101     value = getattr(module, name)

File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:1112, in _LazyModule._get_module(self, module_name)
   1111 except Exception as e:
-> 1112     raise RuntimeError(
   1113         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1114         f" traceback):\n{e}"
   1115     ) from e

RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
module 'tensorflow' has no attribute 'contrib'

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

RuntimeError                              Traceback (most recent call last)
Cell In[7], line 5
      3 import torch
      4 from io import BytesIO
----> 5 from optimum.onnxruntime import ORTStableDiffusionInpaintPipeline

File <frozen importlib._bootstrap>:1055, in _handle_fromlist(module, fromlist, import_, recursive)

File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:1100, in _LazyModule.__getattr__(self, name)
   1098     value = self._get_module(name)
   1099 elif name in self._class_to_module.keys():
-> 1100     module = self._get_module(self._class_to_module[name])
   1101     value = getattr(module, name)
   1102 else:

File /opt/conda/envs/venv/lib/python3.9/site-packages/transformers/utils/import_utils.py:1112, in _LazyModule._get_module(self, module_name)
   1110     return importlib.import_module("." + module_name, self.__name__)
   1111 except Exception as e:
-> 1112     raise RuntimeError(
   1113         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1114         f" traceback):\n{e}"
   1115     ) from e

RuntimeError: Failed to import optimum.onnxruntime.modeling_diffusion because of the following error (look up to see its traceback):
Failed to import transformers.pipelines because of the following error (look up to see its traceback):
module 'tensorflow' has no attribute 'contrib'

juancopi81 avatar Nov 02 '23 13:11 juancopi81