pythontensorflowgoogle-colaboratorytensorflow-federated

module 'tensorflow_federated.python' has no attribute 'federated_computation'


I follow the instructions in the github that says to install Tensorflow Federated with Collab we need to install version 0.20.0 but I get this error when I try to run the toturials.

!pip install --quiet tensorflow-federated==0.20.0 # The latest version of tensorflow-federated is not working with the colab python version
!pip install --quiet --upgrade nest-asyncio
from __future__ import absolute_import, division, print_function

import collections

from six.moves import range
import numpy as np
import tensorflow as tf
# from tensorflow import compat

from tensorflow_federated import python as tff

np.random.seed(0)

tf.compat.v1.enable_v2_behavior()

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

Error:

module 'tensorflow_federated.python' has no attribute 'federated_computation'

What is the problem I don't understand? How can I install it on google colab. There is no resource for this problem.


Solution

  • Are you sure you need to import this

    from tensorflow_federated import python as tff
    

    instead of

    import tensorflow_federated as tff
    

    According to the Tensorflow docs, the federated_computation was under tensorflow_federated directly.