Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FederatedRuntime Workflow for CI Pipeline - 301 Watermarking notebook run #1267

Merged
merged 29 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fbf358a
FederatedRuntime Workflow for CI Pipeline - 301 Watermarking notebook…
noopurintel Jan 13, 2025
d1a9744
Display output on screen
noopurintel Jan 13, 2025
e7512e0
5 Rounds
noopurintel Jan 13, 2025
cb4dcbe
Removed extra ) bracket
noopurintel Jan 13, 2025
903ca3e
Timeout of 30 min due to 5 rounds
noopurintel Jan 13, 2025
d1f42e8
End the loop after all rounds
noopurintel Jan 13, 2025
024220c
Review comments incor
noopurintel Jan 15, 2025
49bfe5d
Merge branch 'develop' into develop
noopurintel Jan 15, 2025
2865d67
Retry the envoy fetch
noopurintel Jan 15, 2025
4293de0
Added invalid code just to verify negative scenario
noopurintel Jan 15, 2025
60d4ff4
Added invalid code just to verify negative scenario
noopurintel Jan 15, 2025
c1d8106
20m job timeout
noopurintel Jan 15, 2025
6b64ff4
Revert invalid code and stdout notebook run
noopurintel Jan 15, 2025
9edbb2f
Use markdown with stdout
noopurintel Jan 15, 2025
eda05cf
Induced error for testing
noopurintel Jan 15, 2025
e9a2b37
Reverted error, added 10s sleep in github fetch logic
noopurintel Jan 15, 2025
cb14071
Code format check
noopurintel Jan 15, 2025
5a164da
pytest for the notebook
noopurintel Jan 15, 2025
487d6e5
Pip install ipython ipykernel
noopurintel Jan 15, 2025
dbe1d7b
Minor changes
noopurintel Jan 15, 2025
edd6c75
Test summary step corrected for wf_functional_e2e workflow
noopurintel Jan 15, 2025
3e3a52b
3 rounds instead of 5
noopurintel Jan 15, 2025
0eeb3e9
Merge branch 'develop' into develop
noopurintel Jan 15, 2025
299628f
Job name change
noopurintel Jan 16, 2025
ebe0a7b
Merge branch 'develop' into develop
noopurintel Jan 16, 2025
69b1d1a
Review comments incorp
noopurintel Jan 16, 2025
55eaa1c
Increased timeout to 30m for CI pipeline jobs
noopurintel Jan 16, 2025
c4529c8
Increased timeout to 30m for CI pipeline jobs
noopurintel Jan 16, 2025
ff862bf
Merge branch 'develop' into develop
noopurintel Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions .github/workflows/federated_runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#---------------------------------------------------------------------------
# Workflow to run 301_MNIST_Watermarking notebook
# Authors - Noopur, Payal Chaurasiya
#---------------------------------------------------------------------------
name: Federated Runtime 301 MNIST Watermarking

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

workflow_dispatch:

permissions:
contents: read

jobs:
run_notebook:
if: github.event.pull_request.draft == false
runs-on: ubuntu-22.04
timeout-minutes: 15
steps:
- name: Checkout OpenFL repository
uses: actions/[email protected]
with:
fetch-depth: 2 # needed for detecting changes
submodules: "true"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install Jupyter Lab Package
run: pip install jupyterlab

- name: Install dependencies # Without this step, fx command will not work
id: install_dependencies
run: |
python -m pip install --upgrade pip
pip install .

- name: Create results folder for logs
run: | # Present working director - /home/runner/work/openfl/openfl
mkdir -p /home/runner/results
cd /home/runner/results
touch director.log bangalore.log chandler.log && chmod 755 director.log bangalore.log chandler.log

- name: Activate and run the director in background
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking
fx experimental activate
cd director
nohup ./start_director.sh &> ~/results/director.log &
sleep 30 # DO NOT remove - envoys will simply exit if director is not ready

- name: Run the envoy Bangalore in background
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking/Bangalore
nohup ./start_envoy.sh Bangalore Bangalore_config.yaml &> ~/results/bangalore.log &

- name: Run the envoy Chandler in background
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking/Chandler
nohup ./start_envoy.sh Chandler Chandler_config.yaml &> ~/results/chandler.log &

- name: Check if envoys are connected to the director
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking
timeout=60
connected=false
while [ $timeout -gt 0 ]; do
if grep "Bangalore is connected to the director" ~/results/bangalore.log && grep "Chandler is connected to the director" ~/results/chandler.log; then
noopurintel marked this conversation as resolved.
Show resolved Hide resolved
connected=true
break
else
echo "Waiting for both envoys to connect to the director"
fi
sleep 5
timeout=$((timeout-5))
done
if [ $connected = false ]; then
echo "Envoys are not connected to the director in 60 seconds"
echo "| Failure Reason |" >> $GITHUB_STEP_SUMMARY
echo "| -------------- |" >> $GITHUB_STEP_SUMMARY
echo "Envoys are not connected to the director in 60 seconds" >> $GITHUB_STEP_SUMMARY
exit 1
fi

- name: Run Notebook
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking/workspace
jupyter nbconvert --execute --to notebook ./MNIST_Watermarking.ipynb
noopurintel marked this conversation as resolved.
Show resolved Hide resolved
echo "Notebook run completed"

- name: Check if the experiment was successful using logs
run: |
cd openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking

if ! grep "End of Federation reached." ~/results/bangalore.log; then
echo "Federation didn't reach end for Bangalore envoy"
fi
if ! grep "End of Federation reached." ~/results/chandler.log; then
echo "Federation didn't reach end for Chandler envoy"
fi
if ! grep "Experiment FederatedFlow_MNIST_Watermarking was finished successfully" ~/results/director.log; then
echo "Experiment didn't finish successfully"
exit 1
fi

echo "Notebook run was successful"
echo "| Aggregated model validation score |" >> $GITHUB_STEP_SUMMARY
echo "| -------------- |" >> $GITHUB_STEP_SUMMARY
echo $(grep -oP 'Aggregated model validation score = \K[\d.]+' ~/results/director.log | tail -1) >> $GITHUB_STEP_SUMMARY

- name: Tar files
if: ${{ always() }} # collect artifacts regardless of failures
run: |
tar -cvf notebook.tar \
./openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking/workspace/MNIST_Watermarking.nbconvert.ipynb \
./openfl-tutorials/experimental/workflow/FederatedRuntime/301_MNIST_Watermarking/workspace/MNIST_Watermarking.ipynb \
~/results \
--ignore-failed-read
echo "TAR file created"

- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: ${{ always() }} # collect artifacts regardless of failures
with:
name: federated_runtime_301_watermarking_${{ github.run_id }}
path: notebook.tar
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
"#| default_exp experiment"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aab0576a",
"metadata": {},
"outputs": [],
"source": [
"# Below code is to display the output of the code in the notebook during GitHub workflow run\n",
noopurintel marked this conversation as resolved.
Show resolved Hide resolved
"# Comment it out if you are running the code in your local environment/Google Colab\n",
"import sys\n",
"sys.stdout = open('/dev/stdout', 'w')"
noopurintel marked this conversation as resolved.
Show resolved Hide resolved
]
},
{
"cell_type": "markdown",
"id": "62449b5f",
Expand Down Expand Up @@ -245,7 +258,7 @@
" watermark_pretrain_optimizer=None,\n",
" watermark_retrain_optimizer=None,\n",
" round_number=0,\n",
" n_rounds=1,\n",
" n_rounds=5,\n",
" **kwargs,\n",
" ):\n",
" super().__init__(**kwargs)\n",
Expand All @@ -271,6 +284,7 @@
" )\n",
" self.round_number = round_number\n",
" self.n_rounds = n_rounds\n",
" self.current_round = 1\n",
noopurintel marked this conversation as resolved.
Show resolved Hide resolved
" self.watermark_pretraining_completed = False\n",
"\n",
" @aggregator\n",
Expand Down Expand Up @@ -425,7 +439,19 @@
" + f\" Acc: {self.watermark_retrain_validation_score:<.6f}\")\n",
" retrain_round += 1\n",
"\n",
" self.next(self.end)\n",
" self.next(self.internal_loop)\n",
" \n",
" @aggregator\n",
" def internal_loop(self):\n",
" \"\"\"\n",
" Internal loop to continue the Federated Learning process.\n",
" \"\"\"\n",
" if self.current_round == self.n_rounds:\n",
" print(f\"\\nCompleted training for all {self.n_rounds} round(s)\\n\")\n",
" else:\n",
" print(f\"\\nCompleted round: {self.current_round})\\n\")\n",
" self.current_round += 1\n",
" self.next(self.aggregated_model_validation, foreach='collaborators')\n",
"\n",
" @aggregator\n",
" def end(self):\n",
Expand Down
Loading