IBM / federated-learning-lib

A library for federated learning (a distributed machine learning process) in an enterprise environment.
Other
498 stars 135 forks source link

install errors for python>3.6 and tensorflow>1.15 #111

Open gubertoli opened 2 years ago

gubertoli commented 2 years ago

Hi, I am using a computer with Python 3.8.0. I read the release note of IBM FL 1.0.6 (on slack) and it mentions the support for Python 3.8. So, first I tried to directly install from git repository, but it breaks during pip install -r requirements.txt once the Tensorflow==1.15 neither Tensorflow==2.1 is available for Python 3.8.

Then, I downgraded to Python 3.6, upgraded pip (pip install --upgrade pip) and changed the requirements.txt from Tensorflow 1.15 to tensorflow==2.1 then the setup finished.

But, running the MNIST example from set-up guide, I got the following error after succesfully running generate_data.py:

(venv) $ python examples/generate_configs.py -f iter_avg -m keras -n 2 -d mnist -p examples/data/mnist/random
Using TensorFlow backend.
/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/google/auth/crypt/_cryptography_rsa.py:22: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography and will be removed in a future release.
  import cryptography.exceptions
Finished generating config file for aggregator. Files can be found in:  /home/gustavo/Desktop/federated-learning-lib/examples/configs/iter_avg/keras/config_agg.yml
Traceback (most recent call last):
  File "examples/generate_configs.py", line 297, in <module>
    dataset, party_data_path, folder_configs, task_name)
  File "examples/generate_configs.py", line 228, in generate_party_config
    'model': generate_model_config(module, model, folder_configs, dataset, party_id=i),
  File "examples/generate_configs.py", line 170, in generate_model_config
    model = get_model_config(folder_configs, dataset, is_agg, party_id, model=model)
  File "/home/gustavo/Desktop/federated-learning-lib/examples/iter_avg/generate_configs.py", line 69, in get_model_config
    return method(folder_configs, dataset, is_agg=is_agg, party_id=0)
  File "/home/gustavo/Desktop/federated-learning-lib/examples/iter_avg/model_keras.py", line 24, in get_model_config
    return get_mnist_model_config(folder_configs)
  File "/home/gustavo/Desktop/federated-learning-lib/examples/iter_avg/model_keras.py", line 50, in get_mnist_model_config
    model = Sequential()
  File "/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/keras/engine/sequential.py", line 87, in __init__
    super(Sequential, self).__init__(name=name)
  File "/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/keras/engine/network.py", line 96, in __init__
    self._init_subclassed_network(**kwargs)
  File "/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/keras/engine/network.py", line 294, in _init_subclassed_network
    self._base_init(name=name)
  File "/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/keras/engine/network.py", line 109, in _base_init
    name = prefix + '_' + str(K.get_uid(prefix))
  File "/home/gustavo/Desktop/federated-learning-lib/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 74, in get_uid
    graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

Then, I also downgraded from Tensorflow 2.1 to Tensorflow 1.15. And then the set-up example using MNIST finally works! :)

So it is not clear the claim that it works with Python 3.8 and TF v2. My question is, how to effectively make IBM-FL work with TF v2 and Python 3.8 ? I reviewed previous issues and I think that this step-by-step relates to #93 and #91

gubertoli commented 2 years ago

An additional comment... I confirmed that the example of the fusion algorithm iter_avg with keras runs with TensorFlow 1.15. However, the fedavgplus example with tf runs with TensorFlow 2.1.

Yi-Zoey commented 2 years ago

Hi @gubertoli Thanks for trying out IBM FL!

If you want to use Python 3.8, then only TensorFlow 2.X version will support this python version. Therefore, you will probably need TensorFlow 2.4. And in our tutorial, we clarify that KerasFLModel only supports pure Keras model and TensorFlow 1.15. Then if you are on TFv2 models, you will need TensorFlowFLModel, i.e., to try out our examples, you will use python examples/generate_configs.py -f iter_avg -m tf-n 2 -d mnist -p examples/data/mnist/random.

I will suggest you trying the combination of python 3.8 and TensorFlow 2.4.1 and also use our latest release version.