Skip to content

Commit

Permalink
update getting started notebooks for colab and 2.5rc (#2690)
Browse files Browse the repository at this point in the history
Co-authored-by: Chester Chen <[email protected]>
  • Loading branch information
SYangster and chesterxgchen authored Jul 12, 2024
1 parent 8ec804f commit f7ca641
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,41 @@
"## Setup environment"
]
},
{
"cell_type": "markdown",
"id": "ebc38cbf",
"metadata": {},
"source": [
"Install nvflare and dependencies:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33bba668-72ac-4e69-aaed-8d4254f547c0",
"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"
]
},
{
Expand Down Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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": {
Expand Down
51 changes: 48 additions & 3 deletions examples/getting_started/pt/nvflare_pt_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,41 @@
"## Setup environment"
]
},
{
"cell_type": "markdown",
"id": "f5496ffe",
"metadata": {},
"source": [
"Install nvflare and dependencies:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33bba668-72ac-4e69-aaed-8d4254f547c0",
"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"
]
},
{
Expand Down Expand Up @@ -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)"
]
},
{
Expand All @@ -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)."
]
},
{
Expand Down Expand Up @@ -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",
Expand Down
49 changes: 47 additions & 2 deletions examples/getting_started/tf/nvflare_tf_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,41 @@
"## Setup environment"
]
},
{
"cell_type": "markdown",
"id": "7cc7e4d2",
"metadata": {},
"source": [
"Install nvflare and dependencies:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33bba668-72ac-4e69-aaed-8d4254f547c0",
"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"
]
},
{
Expand Down Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit f7ca641

Please sign in to comment.