From 354cfa107e7ebbdc9855c6e76487bf62057c9b48 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 30 Jan 2024 17:00:57 +0000 Subject: [PATCH] Update simulation step-by-step example (#2726) --- .../Part-I/client.py | 2 +- .../Part-II/client.py | 2 +- .../README.md | 13 ++++++------- .../requirements.txt | 2 ++ 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 examples/flower-simulation-step-by-step-pytorch/requirements.txt diff --git a/examples/flower-simulation-step-by-step-pytorch/Part-I/client.py b/examples/flower-simulation-step-by-step-pytorch/Part-I/client.py index b10c32d36c42..eac831ad1932 100644 --- a/examples/flower-simulation-step-by-step-pytorch/Part-I/client.py +++ b/examples/flower-simulation-step-by-step-pytorch/Part-I/client.py @@ -98,7 +98,7 @@ def client_fn(cid: str): trainloader=trainloaders[int(cid)], vallodaer=valloaders[int(cid)], num_classes=num_classes, - ) + ).to_client() # return the function to spawn client return client_fn diff --git a/examples/flower-simulation-step-by-step-pytorch/Part-II/client.py b/examples/flower-simulation-step-by-step-pytorch/Part-II/client.py index d269d4892a0e..7da9547d7362 100644 --- a/examples/flower-simulation-step-by-step-pytorch/Part-II/client.py +++ b/examples/flower-simulation-step-by-step-pytorch/Part-II/client.py @@ -75,6 +75,6 @@ def client_fn(cid: str): trainloader=trainloaders[int(cid)], vallodaer=valloaders[int(cid)], model_cfg=model_cfg, - ) + ).to_client() return client_fn diff --git a/examples/flower-simulation-step-by-step-pytorch/README.md b/examples/flower-simulation-step-by-step-pytorch/README.md index 55b8d837b090..beb8dd7f6f95 100644 --- a/examples/flower-simulation-step-by-step-pytorch/README.md +++ b/examples/flower-simulation-step-by-step-pytorch/README.md @@ -1,5 +1,7 @@ # Flower Simulation Step-by-Step +> Since this tutorial (and its video series) was put together, Flower has been updated a few times. As a result, some of the steps to construct the environment (see below) have been updated. Some parts of the code have also been updated. Overall, the content of this tutorial and how things work remains the same as in the video tutorials. + This directory contains the code developed in the `Flower Simulation` tutorial series on Youtube. You can find all the videos [here](https://www.youtube.com/playlist?list=PLNG4feLHqCWlnj8a_E1A_n5zr2-8pafTB) or clicking on the video preview below. - In `Part-I` (7 videos) we developed from scratch a complete Federated Learning pipeline for simulation using PyTorch. @@ -19,20 +21,17 @@ As presented in the video, we first need to create a Python environment. You are # I'm assuming you are running this on an Ubuntu 22.04 machine (GPU is not required) # create the environment -conda create -n flower_tutorial python=3.8 -y +conda create -n flower_tutorial python=3.9 -y # activate your environment (depending on how you installed conda you might need to use `conda activate ...` instead) source activate flower_tutorial # install PyToch (other versions would likely work) conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia -y -# conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 -c pytorch # If you don't have a GPU +# conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 -c pytorch -y # If you don't have a GPU -# install flower (for FL) and hydra (for configs) -pip install flwr==1.4.0 hydra-core==1.3.2 -# install ray -# you might see some warning messages after installing it (you can ignore them) -pip install ray==1.11.1 +# Install Flower and other dependencies +pip install -r requirements.txt ``` If you are running this on macOS with Apple Silicon (i.e. M1, M2), you'll need a different `grpcio` package if you see an error when running the code. To fix this do: diff --git a/examples/flower-simulation-step-by-step-pytorch/requirements.txt b/examples/flower-simulation-step-by-step-pytorch/requirements.txt new file mode 100644 index 000000000000..a322192ca711 --- /dev/null +++ b/examples/flower-simulation-step-by-step-pytorch/requirements.txt @@ -0,0 +1,2 @@ +flwr[simulation]>=1.0, <2.0 +hydra-core==1.3.2 \ No newline at end of file