From ea7a2d7849fd69541cab8243e527d19614603c2d Mon Sep 17 00:00:00 2001 From: Viktor Valadi <42983197+viktorvaladi@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:15:02 +0200 Subject: [PATCH] Docs/SK-796 | Update flower readme (#582) --- examples/flower-client/README.rst | 51 ++++++++++++++------- examples/flower-client/client/entrypoint.py | 2 +- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/examples/flower-client/README.rst b/examples/flower-client/README.rst index 2093caf3f..dfe0bca8f 100644 --- a/examples/flower-client/README.rst +++ b/examples/flower-client/README.rst @@ -1,12 +1,12 @@ -Using Flower ClientApps in FEDn -------------------------------- +FEDn Project: Flower ClientApps in FEDn +--------------------------------------- This example demonstrates how to run a Flower 'ClientApp' on FEDn. The FEDn compute package 'client/entrypoint' uses a built-in Flower compatibiltiy adapter for convenient wrapping of the Flower client. See `flwr_client.py` and `flwr_task.py` for the Flower client code (which is adapted from -https://github.com/adap/flower/tree/main/examples/app-pytorch). +https://github.com/adap/flower/tree/main/examples/app-pytorch). Running the example @@ -42,19 +42,19 @@ Next, generate a seed model (the first model in the global model trail): fedn run build --path client -Next, you will upload the compute package and seed model to +This creates a seed.npz in the root of the project folder. Next, you will upload the compute package and seed model to a FEDn network. Here you have two main options: using FEDn Studio -(recommended for new users), or a pseudo-local deployment +(recommended for new users), or a self-managed pseudo-distributed deployment on your own machine. If you are using FEDn Studio (recommended): ------------------------------------------------------ +------------------------------------------- Follow instructions here to register for Studio and start a project: https://fedn.readthedocs.io/en/stable/studio.html. In your Studio project: -- From the "Sessions" menu, upload the compute package and seed model. +- From the "Sessions" menu, upload the compute package (package.tgz) and seed model (seed.npz). - Register a client and obtain the corresponding 'client.yaml'. On your local machine / client, start the FEDn client: @@ -62,9 +62,7 @@ On your local machine / client, start the FEDn client: .. code-block:: - export FEDN_AUTH_SCHEME=Bearer - export FEDN_PACKAGE_EXTRACT_DIR=package - CLIENT_NUMBER=0 fedn run client -in client.yaml --secure=True --force-ssl + fedn run client -in client.yaml --secure=True --force-ssl Or, if you prefer to use Docker (this might take a long time): @@ -74,15 +72,14 @@ Or, if you prefer to use Docker (this might take a long time): docker run \ -v $PWD/client.yaml:/app/client.yaml \ -e CLIENT_NUMBER=0 \ - -e FEDN_AUTH_SCHEME=Bearer \ -e FEDN_PACKAGE_EXTRACT_DIR=package \ - ghcr.io/scaleoutsystems/fedn/fedn:master run client -in client.yaml --secure=True --force-ssl + ghcr.io/scaleoutsystems/fedn/fedn:0.9.0 run client -in client.yaml --secure=True --force-ssl -If you are running FEDn in pseudo-local mode: ------------------------------------------------------------------- +If you are running FEDn in local development mode: +-------------------------------------------------- -Deploy a FEDn network on local host (see `https://fedn.readthedocs.io/en/stable/quickstart.html`). +Deploy a FEDn network on local host (see `https://fedn.readthedocs.io/en/stable/quickstart.html#local-development-deployment-using-docker-compose`). Use the FEDn API Client to initalize FEDn with the compute package and seed model: @@ -107,6 +104,26 @@ Then start the client (using Docker) -v $PWD/client.yaml:/app/client.yaml \ --network=fedn_default \ -e CLIENT_NUMBER=0 \ - -e FEDN_AUTH_SCHEME=Bearer \ -e FEDN_PACKAGE_EXTRACT_DIR=package \ - ghcr.io/scaleoutsystems/fedn/fedn:master run client -in client.yaml + ghcr.io/scaleoutsystems/fedn/fedn:0.9.0 run client -in client.yaml + + +Scaling to multiple clients +------------------------------------------------------------------ + +To scale the experiment with additional clients on the same host, execute the run command +again from another terminal. If running from another host, add another 'client.yaml', install +fedn, and execute the run command. In both cases inject a client number as an environment +varible which is used for distributing data (see 'flwr_task.py'). + +For Unix Operating Systems: + +.. code-block:: + + CLIENT_NUMBER=0 fedn run client -in client.yaml --secure=True --force-ssl + +Using Windows PowerShell: + +.. code-block:: + + & { $env:CLIENT_NUMBER="0"; fedn run client -in client.yaml --secure=$true --force-ssl } diff --git a/examples/flower-client/client/entrypoint.py b/examples/flower-client/client/entrypoint.py index 24f20773e..e80e7d4b5 100755 --- a/examples/flower-client/client/entrypoint.py +++ b/examples/flower-client/client/entrypoint.py @@ -30,7 +30,7 @@ def save_parameters(out_path, parameters_np): helper.save(parameters_np, out_path) -def init_seed(out_path="seed.npz"): +def init_seed(out_path="../seed.npz"): """Initialize seed model and save it to file. :param out_path: The path to save the seed model to.