"Cyclic Weight Transfer" (CWT) is an alternative to the scatter-and-gather approach used in FedAvg. CWT uses the CyclicController to pass the model weights from one site to the next for repeated fine-tuning.
NOTE: This example uses the MNIST handwritten digits dataset and will load its data within the trainer code.
You can follow the hello_world notebook or the following:
Follow the Installation instructions to install NVFlare.
Install additional requirements:
pip3 install tensorflow
Prepare the data first:
bash ./prepare_data.sh
Use nvflare simulator to run the hello-examples:
nvflare simulator -w /tmp/nvflare/ -n 2 -t 2 ./jobs/hello-cyclic
You can find the running logs and results inside the simulator's workspace/simulate_job
$ ls /tmp/nvflare/simulate_job/
app_server app_site-1 app_site-2 log.txt
For running with GPUs, we recommend using NVIDIA TensorFlow docker
If you choose to run the example using GPUs, it is important to note that, by default, TensorFlow will attempt to allocate all available GPU memory at the start. In scenarios where multiple clients are involved, you have a couple of options to address this.
One approach is to include specific flags to prevent TensorFlow from allocating all GPU memory. For instance:
TF_FORCE_GPU_ALLOW_GROWTH=true nvflare simulator -w /tmp/nvflare/ -n 2 -t 2 ./jobs/hello-cyclic
If you possess more GPUs than clients, an alternative strategy is to run one client on each GPU. This can be achieved as illustrated below:
TF_FORCE_GPU_ALLOW_GROWTH=true nvflare simulator -w /tmp/nvflare/ -n 2 -gpu 0,1 ./jobs/hello-cyclic