federated icon indicating copy to clipboard operation
federated copied to clipboard

Can't use federated like Tutorials

Open afan0918 opened this issue 2 years ago • 1 comments

Describe the bug A clear and concise description of what the bug is. It is often helpful to provide a link to a colab notebook that reproduces the bug.

On ubuntu22.0.4(wsl), there is an error in the documentation code.(python = 3.10.4 new virtual environment by virtualenv)

code from https://www.tensorflow.org/federated/tutorials/federated_learning_for_image_classification

!pip install --quiet --upgrade tensorflow-federated
!pip install --quiet --upgrade nest-asyncio

import nest_asyncio
nest_asyncio.apply()
%load_ext tensorboard
import collections

import numpy as np
import tensorflow as tf
import tensorflow_federated as tff

np.random.seed(0)

tff.federated_computation(lambda: 'Hello, World!')()

Error occurred.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In [3], line 5
      3 import numpy as np
      4 import tensorflow as tf
----> 5 import tensorflow_federated as tff
      7 np.random.seed(0)
      9 tff.federated_computation(lambda: 'Hello, World!')()

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_federated/__init__.py:20
     16 import sys
     18 from tensorflow_federated.version import __version__  # pylint: disable=g-bad-import-order
---> 20 from tensorflow_federated.python import aggregators
     21 from tensorflow_federated.python import analytics
     22 from tensorflow_federated.python import learning

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_federated/python/aggregators/__init__.py:25
     14 """Libraries for constructing federated aggregation.
     15 
     16 For example uses of the symbols in this module, see
   (...)
     21 https://www.tensorflow.org/federated/tutorials/custom_aggregators) tutorial.
     22 """
     24 from tensorflow_federated.python.aggregators.concat import concat_factory
---> 25 from tensorflow_federated.python.aggregators.differential_privacy import DifferentiallyPrivateFactory
     26 from tensorflow_federated.python.aggregators.encoded import EncodedSumFactory
     27 from tensorflow_federated.python.aggregators.factory import AggregationFactory

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_federated/python/aggregators/differential_privacy.py:27
     24 import warnings
     26 import tensorflow as tf
---> 27 import tensorflow_privacy as tfp
     29 from tensorflow_federated.python.aggregators import factory
     30 from tensorflow_federated.python.aggregators import sum_factory

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_privacy/__init__.py:37
     35 from tensorflow_privacy.privacy.dp_query.dp_query import DPQuery
     36 from tensorflow_privacy.privacy.dp_query.dp_query import SumAggregationDPQuery
---> 37 from tensorflow_privacy.privacy.dp_query.discrete_gaussian_query import DiscreteGaussianSumQuery
     38 from tensorflow_privacy.privacy.dp_query.distributed_discrete_gaussian_query import DistributedDiscreteGaussianSumQuery
     39 from tensorflow_privacy.privacy.dp_query.distributed_skellam_query import DistributedSkellamSumQuery

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_privacy/privacy/dp_query/discrete_gaussian_query.py:20
     18 import dp_accounting
     19 import tensorflow as tf
---> 20 from tensorflow_privacy.privacy.dp_query import discrete_gaussian_utils
     21 from tensorflow_privacy.privacy.dp_query import dp_query
     24 class DiscreteGaussianSumQuery(dp_query.SumAggregationDPQuery):

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_privacy/privacy/dp_query/discrete_gaussian_utils.py:29
     14 """Util functions for drawing discrete Gaussian samples.
     15 
     16 The following functions implement a vectorized TF version of the sampling
   (...)
     25 parameters.
     26 """
     28 import tensorflow as tf
---> 29 import tensorflow_probability as tf_prob
     32 def _sample_discrete_laplace(t, shape):
     33   """Sample from discrete Laplace with scale t.
     34 
     35   This method is based on the observation that sampling from Z ~ Lap(t) is
   (...)
     47     A tensor of the specified shape filled with random values.
     48   """

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_probability/__init__.py:23
     20 from tensorflow_probability import substrates
     21 # from tensorflow_probability.google import staging  # DisableOnExport
     22 # from tensorflow_probability.google import tfp_google  # DisableOnExport
---> 23 from tensorflow_probability.python import *  # pylint: disable=wildcard-import
     24 from tensorflow_probability.python.version import __version__

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_probability/python/__init__.py:138
    135 if _tf_loaded():
    136   # Non-lazy load of packages that register with tensorflow or keras.
    137   for pkg_name in _maybe_nonlazy_load:
--> 138     dir(globals()[pkg_name])  # Forces loading the package from its lazy loader.
    141 all_util.remove_undocumented(__name__, _lazy_load + _maybe_nonlazy_load)

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_probability/python/internal/lazy_loader.py:57, in LazyLoader.__dir__(self)
     56 def __dir__(self):
---> 57   module = self._load()
     58   return dir(module)

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_probability/python/internal/lazy_loader.py:37, in LazyLoader._load(self)
     35 """Load the module and insert it into the parent's globals."""
     36 if callable(self._on_first_access):
---> 37   self._on_first_access()
     38   self._on_first_access = None
     39 # Import the target module and insert it into the parent's namespace

File /home/afan/Federated Learning/lib/python3.10/site-packages/tensorflow_probability/python/__init__.py:59, in _validate_tf_environment(package)
     55 #   required_tensorflow_version = '1.15'  # Needed internally -- DisableOnExport
     57   if (distutils.version.LooseVersion(tf.__version__) <
     58       distutils.version.LooseVersion(required_tensorflow_version)):
---> 59     raise ImportError(
     60         'This version of TensorFlow Probability requires TensorFlow '
     61         'version >= {required}; Detected an installation of version {present}. '
     62         'Please upgrade TensorFlow to proceed.'.format(
     63             required=required_tensorflow_version,
     64             present=tf.__version__))
     66   if (package == 'mcmc' and
     67       tf.config.experimental.tensor_float_32_execution_enabled()):
     68     # Must import here, because symbols get pruned to __all__.
     69     import warnings

ImportError: This version of TensorFlow Probability requires TensorFlow version >= 2.10; Detected an installation of version 2.9.2. Please upgrade TensorFlow to proceed.

Environment (please complete the following information):

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 22.04(WSL)
  • Python package versions (e.g., TensorFlow Federated, TensorFlow):
tensorflow                    2.9.2
tensorflow-datasets           4.6.0
tensorflow-estimator          2.9.0
tensorflow-federated          0.33.0
tensorflow-io-gcs-filesystem  0.27.0
tensorflow-metadata           1.10.0
tensorflow-model-optimization 0.7.3
tensorflow-privacy            0.8.5
tensorflow-probability        0.18.0
  • Python version: 3.10.4
  • Bazel version (if building from source):
  • CUDA/cuDNN version:
$ nvcc  --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:59:34_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0
  • What TensorFlow Federated execution stack are you using?

Note: You can collect the Python package information by running pip3 freeze from the command line and most of the other information can be collected using TensorFlows environment capture script.

Expected behavior A clear and concise description of what you expected to happen.

output as Tutorials

b'Hello, World!'

Additional context Add any other context about the problem here.

ImportError: This version of TensorFlow Probability requires TensorFlow version >= 2.10; Detected an installation of version 2.9.2. Please upgrade TensorFlow to proceed.

I have been to try uninstall TensorFlow 2.9.2 and install TensorFlow 2.10.0

but other error occurred.

ImportError: This version of TensorFlow Probability requires TensorFlow version >= 2.10; Detected an installation of version 2.9.2. Please upgrade TensorFlow to proceed.

afan0918 avatar Sep 14 '22 16:09 afan0918

There are version incompatibilities between TFF and Python 3.10, across all versions of TFF. But installing tensorflow-federated==0.36.0 (the latest version) in an environment with Python 3.9 should work.

hardik-vala avatar Sep 22 '22 01:09 hardik-vala