From 7b657098997f7e24c58daedc8b7aa0d9fc510e5e Mon Sep 17 00:00:00 2001 From: Sean Yang Date: Thu, 11 Jul 2024 17:54:43 -0700 Subject: [PATCH] update getting started notebooks for colab and 2.5rc --- .../nvflare_lightning_getting_started.ipynb | 49 +++++++++++++++++- .../pt/nvflare_pt_getting_started.ipynb | 51 +++++++++++++++++-- .../tf/nvflare_tf_getting_started.ipynb | 49 +++++++++++++++++- 3 files changed, 142 insertions(+), 7 deletions(-) diff --git a/examples/getting_started/pt/nvflare_lightning_getting_started.ipynb b/examples/getting_started/pt/nvflare_lightning_getting_started.ipynb index 12236bb58a..de68424250 100644 --- a/examples/getting_started/pt/nvflare_lightning_getting_started.ipynb +++ b/examples/getting_started/pt/nvflare_lightning_getting_started.ipynb @@ -39,6 +39,14 @@ "## Setup environment" ] }, + { + "cell_type": "markdown", + "id": "ebc38cbf", + "metadata": {}, + "source": [ + "Install nvflare and dependencies:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -46,7 +54,26 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -q -r nvflare~=2.5.0rc pytorch_lightning" + "! pip install --ignore-installed blinker\n", + "! pip install nvflare~=2.5.0rc pytorch_lightning" + ] + }, + { + "cell_type": "markdown", + "id": "76354477", + "metadata": {}, + "source": [ + "If running in Google Colab, download the source code for this example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a382cae", + "metadata": {}, + "outputs": [], + "source": [ + "! npx degit NVIDIA/NVFlare/examples/getting_started/pt/src src" ] }, { @@ -386,7 +413,7 @@ " executor = ScriptExecutor(\n", " task_script_path=\"src/cifar10_lightning_fl.py\", task_script_args=\"\" # f\"--batch_size 32 --data_path /tmp/data/site-{i}\"\n", " )\n", - " job.to(executor, f\"site-{i}\", gpu=0)" + " job.to(executor, f\"site-{i+1}\", gpu=0)" ] }, { @@ -430,6 +457,24 @@ "source": [ "job.simulator_run(\"/tmp/nvflare/jobs/workdir\")" ] + }, + { + "cell_type": "markdown", + "id": "3f56e377", + "metadata": {}, + "source": [ + "If using Google Colab and the output is not showing correctly, export the job and run it with the simulator command instead:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "52ed0d5d", + "metadata": {}, + "outputs": [], + "source": [ + "! nvflare simulator -w /tmp/nvflare/jobs/workdir -n 2 -t 2 -gpu 0 /tmp/nvflare/jobs/job_config/cifar10_fedavg_lightning" + ] } ], "metadata": { diff --git a/examples/getting_started/pt/nvflare_pt_getting_started.ipynb b/examples/getting_started/pt/nvflare_pt_getting_started.ipynb index 353626d9d0..8cdf81a097 100644 --- a/examples/getting_started/pt/nvflare_pt_getting_started.ipynb +++ b/examples/getting_started/pt/nvflare_pt_getting_started.ipynb @@ -39,6 +39,14 @@ "## Setup environment" ] }, + { + "cell_type": "markdown", + "id": "f5496ffe", + "metadata": {}, + "source": [ + "Install nvflare and dependencies:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -46,7 +54,26 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -q -r nvflare~=2.5.0rc torch torchvision tensorboard" + "! pip install --ignore-installed blinker\n", + "! pip install nvflare~=2.5.0rc torch torchvision tensorboard" + ] + }, + { + "cell_type": "markdown", + "id": "baa517fe", + "metadata": {}, + "source": [ + "If running in Google Colab, download the source code for this example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4c139be6", + "metadata": {}, + "outputs": [], + "source": [ + "! npx degit NVIDIA/NVFlare/examples/getting_started/pt/src src" ] }, { @@ -325,7 +352,7 @@ " executor = ScriptExecutor(\n", " task_script_path=\"src/cifar10_fl.py\", task_script_args=\"\" # f\"--batch_size 32 --data_path /tmp/data/site-{i}\"\n", " )\n", - " job.to(executor, f\"site-{i}\", gpu=0)" + " job.to(executor, f\"site-{i+1}\", gpu=0)" ] }, { @@ -336,7 +363,7 @@ "That's it!\n", "\n", "#### 6. Optionally export the job\n", - "Now, we could export the job and submit it to a real NVFlare deployment using the [Admin client](https://nvflare.readthedocs.io/en/main/real_world_fl/operation.html) or [FLARE API](https://nvflare.readthedocs.io/en/main/real_world_fl/flare_api.html). " + "Now, we could export the job and submit it to a real NVFlare deployment using the [Admin client](https://nvflare.readthedocs.io/en/main/real_world_fl/operation.html) or [FLARE API](https://nvflare.readthedocs.io/en/main/real_world_fl/flare_api.html)." ] }, { @@ -370,6 +397,24 @@ "job.simulator_run(\"/tmp/nvflare/jobs/workdir\")" ] }, + { + "cell_type": "markdown", + "id": "9ccbe893", + "metadata": {}, + "source": [ + "If using Google Colab and the output is not showing correctly, export the job and run it with the simulator command instead:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0e46a45d", + "metadata": {}, + "outputs": [], + "source": [ + "! nvflare simulator -w /tmp/nvflare/jobs/workdir -n 2 -t 2 -gpu 0 /tmp/nvflare/jobs/job_config/cifar10_fedavg" + ] + }, { "cell_type": "markdown", "id": "f474ddfa-0d2e-4d7f-b033-8ccfbbd57a75", diff --git a/examples/getting_started/tf/nvflare_tf_getting_started.ipynb b/examples/getting_started/tf/nvflare_tf_getting_started.ipynb index 8b58562846..af87d0af9b 100644 --- a/examples/getting_started/tf/nvflare_tf_getting_started.ipynb +++ b/examples/getting_started/tf/nvflare_tf_getting_started.ipynb @@ -39,6 +39,14 @@ "## Setup environment" ] }, + { + "cell_type": "markdown", + "id": "7cc7e4d2", + "metadata": {}, + "source": [ + "Install nvflare and dependencies:" + ] + }, { "cell_type": "code", "execution_count": null, @@ -46,7 +54,26 @@ "metadata": {}, "outputs": [], "source": [ - "!pip install -q -r nvflare~=2.5.0rc tensorflow" + "! pip install --ignore-installed blinker\n", + "! pip install nvflare~=2.5.0rc tensorflow" + ] + }, + { + "cell_type": "markdown", + "id": "57945dcd", + "metadata": {}, + "source": [ + "If running in Google Colab, download the source code for this example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "993b7696", + "metadata": {}, + "outputs": [], + "source": [ + "! npx degit NVIDIA/NVFlare/examples/getting_started/tf/src src" ] }, { @@ -321,7 +348,7 @@ " task_script_path=\"src/cifar10_tf_fl.py\", task_script_args=\"\" # f\"--batch_size 32 --data_path /tmp/data/site-{i}\"\n", " params_exchange_format=ExchangeFormat.NUMPY,\n", " )\n", - " job.to(executor, f\"site-{i}\", gpu=0)" + " job.to(executor, f\"site-{i+1}\", gpu=0)" ] }, { @@ -365,6 +392,24 @@ "source": [ "job.simulator_run(\"/tmp/nvflare/jobs/workdir\")" ] + }, + { + "cell_type": "markdown", + "id": "44ee8632", + "metadata": {}, + "source": [ + "If using Google Colab and the output is not showing correctly, export the job and run it with the simulator command instead:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ec915ec", + "metadata": {}, + "outputs": [], + "source": [ + "! nvflare simulator -w /tmp/nvflare/jobs/workdir -n 2 -t 2 -gpu 0 /tmp/nvflare/jobs/job_config/cifar10_tf_fedavg" + ] } ], "metadata": {