Eduardo Maciel
Eduardo Maciel

Reputation: 31

"Module 'tensorflow.python.distribute.values' has no attribute 'AutoPolicy'" from importing Tensorflow Hub

I've been trying to run this TensorFlow tutorial on my computer, but while running the following code I've been getting the error from the title:

import os
import shutil

import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text as text
from official.nlp import optimization  # to create AdamW optmizer

import matplotlib.pyplot as plt

tf.get_logger().setLevel('ERROR')
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'

This is the entire error traceback. While running it in the tutorial's Collab notebook there doesn't seem any problem whatsoever.

AttributeErrorTraceback (most recent call last)
<ipython-input-7-3afaa91eeb1f> in <module>
      3 
      4 import tensorflow as tf
----> 5 import tensorflow_hub as hub
      6 import tensorflow_text as text
      7 from official.nlp import optimization  # to create AdamW optmizer

/usr/local/lib/python3.6/dist-packages/tensorflow_hub/__init__.py in <module>
     86 
     87 
---> 88 from tensorflow_hub.estimator import LatestModuleExporter
     89 from tensorflow_hub.estimator import register_module_for_export
     90 from tensorflow_hub.feature_column import image_embedding_column

/usr/local/lib/python3.6/dist-packages/tensorflow_hub/estimator.py in <module>
     60 
     61 
---> 62 class LatestModuleExporter(tf.compat.v1.estimator.Exporter):
     63   """Regularly exports registered modules into timestamped directories.
     64 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy_loader.py in __getattr__(self, item)
     60 
     61   def __getattr__(self, item):
---> 62     module = self._load()
     63     return getattr(module, item)
     64 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy_loader.py in _load(self)
     43     """Load the module and insert it into the parent's globals."""
     44     # Import the target module and insert it into the parent's namespace
---> 45     module = importlib.import_module(self.__name__)
     46     self._parent_module_globals[self._local_name] = module
     47 

/usr/lib/python3.6/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127 
    128 

/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/__init__.py in <module>
      8 import sys as _sys
      9 
---> 10 from tensorflow_estimator.python.estimator.api._v1.estimator import experimental
     11 from tensorflow_estimator.python.estimator.api._v1.estimator import export
     12 from tensorflow_estimator.python.estimator.api._v1.estimator import inputs

/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/experimental/__init__.py in <module>
      8 import sys as _sys
      9 
---> 10 from tensorflow_estimator.python.estimator.canned.dnn import dnn_logit_fn_builder
     11 from tensorflow_estimator.python.estimator.canned.kmeans import KMeansClustering as KMeans
     12 from tensorflow_estimator.python.estimator.canned.linear import LinearSDCA

/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/canned/dnn.py in <module>
     29 from tensorflow.python.keras.utils import losses_utils
     30 from tensorflow.python.util.tf_export import estimator_export
---> 31 from tensorflow_estimator.python.estimator import estimator
     32 from tensorflow_estimator.python.estimator.canned import head as head_lib
     33 from tensorflow_estimator.python.estimator.canned import optimizers

/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/estimator.py in <module>
     50 from tensorflow.python.util.tf_export import estimator_export
     51 from tensorflow_estimator.python.estimator import model_fn as model_fn_lib
---> 52 from tensorflow_estimator.python.estimator import run_config
     53 from tensorflow_estimator.python.estimator import util as estimator_util
     54 from tensorflow_estimator.python.estimator.export import export_lib

/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/run_config.py in <module>
     28 from tensorflow.core.protobuf import rewriter_config_pb2
     29 from tensorflow.python.distribute import estimator_training as distribute_coordinator_training
---> 30 from tensorflow.python.distribute import parameter_server_strategy_v2
     31 from tensorflow.python.util import compat_internal
     32 from tensorflow.python.util import function_utils

/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/parameter_server_strategy_v2.py in <module>
     26 
     27 from tensorflow.python.distribute import distribute_lib
---> 28 from tensorflow.python.distribute import distribute_utils
     29 from tensorflow.python.distribute import parameter_server_strategy
     30 from tensorflow.python.distribute import sharded_variable

/usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_utils.py in <module>
    372 # (synchronization=ON_READ, aggregation=NONE,SUM,MEAN,ONLY_FIRST_REPLICA)
    373 VARIABLE_POLICY_MAPPING = {
--> 374     vs.VariableSynchronization.AUTO: values_lib.AutoPolicy,
    375     vs.VariableSynchronization.ON_WRITE: values_lib.OnWritePolicy,
    376     vs.VariableSynchronization.ON_READ: values_lib.OnReadPolicy,

AttributeError: module 'tensorflow.python.distribute.values' has no attribute 'AutoPolicy'

Is there any particular reason as to why is this happening?

Thank you in advance.

Upvotes: 1

Views: 3060

Answers (1)

MorganR
MorganR

Reputation: 81

My guess is this could be related to a version mismatch between the versions you're using for tensorflow and tensorflow_hub.

It looks like AutoPolicy was removed from TF in a recent commit, so if you built tensorflow from source and included this commit, then that could be the issue. If you want to build TF from source, checkout the latest official release before building (2.4.1).

Upvotes: 1

Related Questions