Skip to content

Commit

Permalink
Experimental Workflow interface (#632)
Browse files Browse the repository at this point in the history
* Remove CLA from OpenFL Repo

* Experimental workflow interface initial commit

* Added Vertical FL Example

* WIP

* LocalRuntime: Ray support with fallback to single process. Request GPUs through decorator. UI Code needs debugging for jupyter notebook (currently disabled). Bug fixes

* Fixed optimizer state in primary example

* Changes to support Flowgraph with Jupyter notebook

* Changes to support Flowgraph with Jupyter notebook

* Test case for validating subset of collaborator works correctly.

* Test to validate references.

* renamed the file

* Clean up next function

* Refactored next function working as expected

* Added a mutex in MetaflowInterface.create_task

* Test case for validating internalloops works correctly.

* Test case for validating internalloops works correctly.

* Included graph code in metaflow_utils

* added pathspec to open graph on browser

* Update workflow interface quickstart notebook

* Add files via upload

* Add files via upload

* Cleaned up Workflow Interface 101 tutorial. Added tutorials 102 (aggregator validation), and 201 (requesting exclusive GPUs)

* Updated with instructions for Google Colab. Cleared tutorial output

* Minor fix to workflow interface GPU tutorial

* Fixed after one round filter attributes issue

Fix After one round filter attributes does not work properly

* Documentation WIP

* corrected the spelling mistake

* Initial Version of Watermarking Tutorial

* Delete Workflow_Interface_MNIST.ipynb

Unnecessary changes committed

* Remove out of date example

* Remove old documentation from flow interface description. Section needs comprehensive descriptions still of interface / runtimes / features

* Add metaflow to 3rd party licenses

* Adds CI tests for PRs tagged with 'workflow_interface'

* CI Pipeline fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* passing input attribute to checkpoint

Making changes to save attribute "input" in datastore.

* Removing commented code

Removing commented code

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* CI Fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Fixed issues with test cases

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Remove unused dependencies

* Revert changes to metaflow utils

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Fixing lint errors

* Resolving lint suggestions

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* updated the test case for testflow reference with include and exclude

* Test Cases for Include and exclude works correctly.

* Global DP Workflow

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* ML Privacy Meter Workflow

Co-authored-by: Hongyan Chang <hongyan.chang@intel.com>
Co-authored-by: Anindya S. Paul <anindya.s.paul@intel.com>
Co-authored-by: Brandon Edwards <brandon.edwards@intel.com>
Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Initial version of the Watermarking notebook in Tutorial format

* GPU OOM fix.

Co-authored-by: Hongyan Chang <hongyan.chang@intel.com>
Co-authored-by: Anindya S. Paul <anindya.s.paul@intel.com>
Co-authored-by: Brandon Edwards <brandon.edwards@intel.com>
Co-authored-by: Patrick Foley <patrick.foley@intel.com>

* Fix optimizer memory leak.

Co-authored-by: Anindya S. Paul <anindya.s.paul@intel.com>
Co-authored-by: Brandon Edwards <brandon.edwards@intel.com>
Co-authored-by: Mansi Sharma <mansi.sharma@intel.com>
Co-authored-by: Patrick Foley <patrick.foley@intel.com>
Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Fix testing function to load tensors into device.

Co-authored-by: Hongyan Chang <hongyan.chang@intel.com>
Co-authored-by: Anindya S. Paul <anindya.s.paul@intel.com>
Co-authored-by: Brandon Edwards <brandon.edwards@intel.com>
Co-authored-by: Patrick Foley <patrick.foley@intel.com>
Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Update Summary 09/12/2022:
1. Generate Watermark dataset in notebook instead of downloading the entire WAFFLE archive
2. Installation of imagen from github source (required for Watermark dataset generation)
3. Updates to Tutorial text
4. Modularized Train function as it is being used in multiple places in the Workflow

* Reset and cleared outputs

* Delete dataset and dataloader attributes after each round.

Co-authored-by: Hongyan Chang <hongyan.chang@intel.com>
Co-authored-by: Anindya S. Paul <anindya.s.paul@intel.com>
Co-authored-by: Brandon Edwards <brandon.edwards@intel.com>
Co-authored-by: Patrick Foley patrick.foley@intel.com
Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Resolve ray object store memory leak. Makes single process default option for LocalRuntime

* Update readme.md

Update image links

* Pin requirements for workflow tests

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Updated testflow_internalloop.py to fix errors

* Updated to fix import errors and Lint issues

* Added copyright to Test cases

* Fix imports for tests

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* enable single_process or ray backend in local_runtime

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Update flow_interface.rst

* Fix lint warnings in openfl/experimental/placement/placement.py
- ./openfl/experimental/placement/placement.py:6:1: F401 'gc' imported but unused
- ./openfl/experimental/placement/placement.py:14:1: E302 expected 2 blank lines, found 1

* Fix lint warnings in openfl/experimental/utilities/utils.py
-  ./openfl/experimental/utilities/utils.py:6:1: E302 expected 2 blank lines, found 1

* Fix lint warnings in openfl/experimental/runtime/runtime.py
- ./openfl/experimental/runtime/runtime.py:24:100: E501 line too long (102 > 99 characters)
- ./openfl/experimental/runtime/runtime.py:35:26: E711 comparison to None should be 'if cond is not None:'
- ./openfl/experimental/runtime/runtime.py:60:16: F541 f-string is missing placeholders

* Fix lint warnings in openfl/experimental/interface/fl_spec.py
- ./openfl/experimental/interface/fl_spec.py:19:1: F401 'threading.Lock' imported but unused
- ./openfl/experimental/interface/fl_spec.py:20:1: F401 'time.sleep' imported but unused
- ./openfl/experimental/interface/fl_spec.py:255:13: F841 local variable 'func_refs' is assigned to but never used
- ./openfl/experimental/interface/fl_spec.py:256:13: F841 local variable 'remote_functions' is assigned to but never used
- ./openfl/experimental/interface/fl_spec.py:257:13: F841 local variable 'remote_ctx_refs' is assigned to but never used

* Fix lint warnings in openfl/experimental/utilities/metaflow_utils.py
- ./openfl/experimental/utilities/metaflow_utils.py:111:1: E800 Found commented out code
- ./openfl/experimental/utilities/metaflow_utils.py:128:24: C402 Unnecessary generator - rewrite as a dict comprehension.
- ./openfl/experimental/utilities/metaflow_utils.py:135:1: E800 Found commented out code
- ./openfl/experimental/utilities/metaflow_utils.py:152:1: E800 Found commented out code
- ./openfl/experimental/utilities/metaflow_utils.py:156:1: E800 Found commented out code
- ./openfl/experimental/utilities/metaflow_utils.py:260:61: FS001 '%' operator used
- ./openfl/experimental/utilities/metaflow_utils.py:264:21: F841 local variable 'e' is assigned to but never used
- ./openfl/experimental/utilities/metaflow_utils.py:276:60: FS001 '%' operator used
- ./openfl/experimental/utilities/metaflow_utils.py:280:25: F841 local variable 'e' is assigned to but never used
- ./openfl/experimental/utilities/metaflow_utils.py:282:21: F841 local variable 'e' is assigned to but never used
- ./openfl/experimental/utilities/metaflow_utils.py:394:42: FS002 '.format' used
- ./openfl/experimental/utilities/metaflow_utils.py:476:32: C408 Unnecessary dict call - rewrite as a literal.
- ./openfl/experimental/utilities/metaflow_utils.py:497:21: C408 Unnecessary dict call - rewrite as a literal.
- ./openfl/experimental/utilities/metaflow_utils.py:535:32: C408 Unnecessary dict call - rewrite as a literal.
- ./openfl/experimental/utilities/metaflow_utils.py:536:22: C408 Unnecessary dict call - rewrite as a literal.

* fix lint errorrs with black reformatting.

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* fix minor typo

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Update flow_interface.rst

* Update flow_interface.rst

* Refactored LocalRuntime and updated the runtime package file
	structure as follows:
1. Created seperate files for each Runtime
2. Refacoted excute_task method in LocalRuntime from FLSpec
3. Methods used commonly in both functions next, and execute_task
	are moved to utilities package runtime_utils.py file
4. Updated Watermarking Tutorial to correct the checkpoint
	usage (flflow.checkpoint to flflow._checkpoint)
5. Resolved flake8 suggestions in openfl/experimental package

* 1. Updated Watermarking Tutorial to correct the checkpoint
	usage (flflow.checkpoint to flflow._checkpoint)

* Add standardized requirements for workflow interface. Upgrade protobuf minor version

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Install common workflow requirements. Small updates to Privacy Meter

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Update global db requirements

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Vertical FL Examples

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Remove extra lines from notebook (no checkpointing for 2 party example)

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Fixed issue of aggregator privates are visible in collaborator steps via runtime.

* Update flow_interface.rst

* Modified collaborator to be a private attribute of LocalRuntime so that collaborator private variables are not accessible to aggregators

* Collaborator is made a private attribute of local runtime. Due to this local_runtime._collaborators is no longer accessible. Updated Workflow Interface testcases and Tutorials with this change

* Added a new Test case to validate accessibility of private attributes
- Aggregator private attributes are accessible only in Aggregator steps
- Collaborator private attributes are accessible only in Collaborator steps

* Addressing lint failures (WIP)

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Fixed Lint issues

* Lint fix

* Include more tests, validate both runtime backends

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Create Base Runtime Specification

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Added back readme.md

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Update readme.md

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* add versions for packages

Signed-off-by: Hongyan chang <hongyan@comp.nus.edu.sg>

* Addressing review comments

* fixing review comments

Signed-off-by: Mansi Sharma <mansi.sharma@intel.com>

* Added type hints, docstrings. Distinguishing private methods from public

* Fix circular dependencies resulting from type annotations

* Add type annotations

* Address lint naming errors

* More docstrings and type hints

* flake8 fixes

Signed-off-by: Patrick Foley <psfoley@gmail.com>

* Added cyclic institutional incremental learning example

* Resolve review comments - add docstrings to tests

* using Generator class for fixing seed

Signed-off-by: Mansi Sharma <mansi.sharma@intel.com>

* Make flake8 exceptions

* added doscstrings to several functions for better user understanding about the functionality

Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>

* Fix jupyter notebook links. Update documentation / create links from README

* More README updates

---------

Signed-off-by: Patrick Foley <psfoley@gmail.com>
Signed-off-by: Paul, Anindya S <anindya.s.paul@intel.com>
Signed-off-by: Hongyan chang <hongyan@comp.nus.edu.sg>
Signed-off-by: Mansi Sharma <mansi.sharma@intel.com>
Co-authored-by: Keerti Talwar <keertix.talwar@intel.com>
Co-authored-by: Greesh-N <greeshmax.greeshma@intel.com>
Co-authored-by: ParthM-GitHub <parthx.mandaliya@intel.com>
Co-authored-by: Sachin Gupta <saching.gupta.dsp@gmail.com>
Co-authored-by: Paul, Anindya S <anindya.s.paul@intel.com>
Co-authored-by: Hongyan Chang <hongyan.chang@intel.com>
Co-authored-by: Brandon Edwards <brandon.edwards@intel.com>
Co-authored-by: Mansi Sharma <mansi.sharma@intel.com>
Co-authored-by: Sachin Gupta <sachin.gupta.dsp@gmail.com>
Co-authored-by: Hongyan chang <hongyan@comp.nus.edu.sg>
  • Loading branch information
11 people authored Jan 11, 2023
1 parent b1e1d39 commit 942fccc
Show file tree
Hide file tree
Showing 73 changed files with 10,866 additions and 1 deletion.
82 changes: 82 additions & 0 deletions .github/workflows/experimental_workflow_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Workflow Interface Tests

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

permissions:
contents: read

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'workflow_interface')
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install metaflow==2.7.15 ray==2.1.0 torch
pip install .
- name: Workflow - Exclude Test (Single Process Backend)
run: |
python tests/github/experimental/testflow_exclude.py
- name: Workflow - Exclude Test (Ray Backend)
run: |
python tests/github/experimental/testflow_exclude.py ray
- name: Workflow - Include Test (Single Process Backend)
run: |
python tests/github/experimental/testflow_include.py
- name: Workflow - Include Test (Ray Backend)
run: |
python tests/github/experimental/testflow_include.py ray
- name: Workflow - Include / Exclude Test (Single Process Backend)
run: |
python tests/github/experimental/testflow_include_exclude.py
- name: Workflow - Include / Exclude Test (Ray Backend)
run: |
python tests/github/experimental/testflow_include_exclude.py ray
- name: Workflow - Internal Loop Test (Single Process Backend)
run: |
python tests/github/experimental/testflow_internalloop.py
- name: Workflow - Internal Loop Test (Ray Backend)
run: |
python tests/github/experimental/testflow_internalloop.py ray
- name: Workflow - Private Attributes (Single Process Backend)
run: |
python tests/github/experimental/testflow_privateattributes.py
- name: Workflow - Private Attributes (Ray Backend)
run: |
python tests/github/experimental/testflow_privateattributes.py ray
- name: Workflow - References (Single Process Backend)
run: |
python tests/github/experimental/testflow_reference.py
- name: Workflow - References (Ray Backend)
run: |
python tests/github/experimental/testflow_reference.py ray
- name: Workflow - References with Exclude (Single Process Backend)
run: |
python tests/github/experimental/testflow_reference_with_exclude.py
- name: Workflow - References with Exclude (Ray Backend)
run: |
python tests/github/experimental/testflow_reference_with_exclude.py ray
- name: Workflow - References with Include (Single Process Backend)
run: |
python tests/github/experimental/testflow_reference_with_include.py
- name: Workflow - References with Include (Ray Backend)
run: |
python tests/github/experimental/testflow_reference_with_include.py ray
- name: Workflow - Collaborator Subset (Single Process Backend)
run: |
python tests/github/experimental/testflow_subset_of_collaborators.py
- name: Workflow - Collaborator Subset (Ray Backend)
run: |
python tests/github/experimental/testflow_subset_of_collaborators.py ray
40 changes: 40 additions & 0 deletions LICENSE-3RD-PARTY
Original file line number Diff line number Diff line change
Expand Up @@ -1176,3 +1176,43 @@ From cryptography:
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

From metaflow:

Copyright 2020 Netflix, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

From privacy_meter

MIT License

Copyright (c) 2020 Data Privacy and Trustworthy Machine Learning Research Lab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Setup long-lived components to run many experiments in series. Recommended for F
- [Aggregator-based Workflow](https://openfl.readthedocs.io/en/latest/running_the_federation.html#aggregator-based-workflow):
Define an experiment and distribute it manually. All participants can verify model code and [FL plan](https://openfl.readthedocs.io/en/latest/running_the_federation.html#federated-learning-plan-fl-plan-settings) prior to execution. The federation is terminated when the experiment is finished

- [Workflow Interface](https://openfl.readthedocs.io/en/latest/workflow_interface.html) ([*experimental*](https://openfl.readthedocs.io/en/latest/experimental_features.html)):
Create complex experiments that extend beyond traditional horizontal federated learning. See the [experimental tutorials](https://github.com/intel/openfl/blob/develop/openfl-tutorials/experimental/) to learn how to coordinate [aggregator validation after collaborator model training](https://github.com/intel/openfl/tree/develop/openfl-tutorials/experimental/Workflow_Interface_102_Aggregator_Validation.ipynb), [perform global differentially private federated learning](https://github.com/psfoley/openfl/tree/experimental-workflow-interface/openfl-tutorials/experimental/Global_DP), measure the amount of private information embedded in a model after collaborator training with [privacy meter](https://github.com/intel/openfl/blob/develop/openfl-tutorials/experimental/Privacy_Meter/readme.md), or [add a watermark to a federated model](https://github.com/intel/openfl/blob/develop/openfl-tutorials/experimental/Workflow_Interface_301_MNIST_Watermarking.ipynb).

The quickest way to test OpenFL is to follow our [tutorials](https://github.com/intel/openfl/tree/develop/openfl-tutorials). </br>
Read the [blog post](https://towardsdatascience.com/go-federated-with-openfl-8bc145a5ead1) explaining steps to train a model with OpenFL. </br>
Check out the [online documentation](https://openfl.readthedocs.io/en/latest/index.html) to launch your first federation.
Expand Down
30 changes: 30 additions & 0 deletions docs/experimental_features.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. # Copyright (C) 2020-2022 Intel Corporation
.. # SPDX-License-Identifier: Apache-2.0
.. _experimental_features:

***************
Experimental Features
***************

This section includes a set of experimental features that our team wants feedback on before adding them into core |productName|.
Experimental features are *not* ready for production. These features are under active development and intended to make their way into core |productName|, but there are several key considerations to make when building on top of these:

1. *Backward compatibility is not guaranteed* - Our goal is to maintain backward compatibility whenever possible, but user feedback (and our own internal research)
may result in necessary changes to the APIs.

**Flow Interface**

Learn how to:
- Chain a series of tasks that run on aggregator or collaborator.
- Filter out information that should stay local
- Use Metaflow tools to analyze and debug experiments

- :doc:`flow_interface`

.. toctree::
:maxdepth: 4
:hidden:

flow_interface

1 change: 1 addition & 0 deletions docs/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ Familiarize with the APIs:
source/utilities/utilities
advanced_topics
source/workflow/running_the_federation.tutorial
experimental_features
20 changes: 20 additions & 0 deletions openfl-tutorials/experimental/Global_DP/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

## Differential Privacy (DP)
Neural networks when trained adequately, pose a risk of learning labels and unique patterns in training data. In a distributed training setup like federated learning, such behaviors cause a significant security compromise since the model owner is now privy to some patterns in the training data. Hence, a privacy protection criterion that provides a mathematically provable guarantee of privacy protection is required. Differential Privacy is one such method which rules out memorization of sensitive information. For our case, we use collaborator level privacy, meaning that the final model is epsilon, delta differentially private with respect to inclusion or exclusion of any one collaborator.

## Global DP example
Global DP implementation uses the [Opacus library](https://opacus.ai/) to perform global differentially private federated learning. At each round, a subset of collaborators are selected using a Poisson distribution over all collaborators, the selected collaborators perform local training with periodic clipping of their model delta (with respect to the current global model) to bound their contribution to the average of local model updates. Gaussian noise is then added to the average of these local models at the aggregator. The result of this federated training is then differentially private with respect to the inclusion (or exclusion) of any one collaborator into the training. A Renyi differential privacy (RDP) accountant is used at the aggregator to determine the epsilon, delta for which the final model is epsilon, delta differentially private with respect to inclusion or exclusion of any one collaborator. This tutorial has two implementations which are listed below. The two implementations are statistically equivalent, but incorporate Opacus interfaces at two different levels. Both implementations use the same code for local training and periodic clipping.

Prerequisites:

`pip install -r ../requirements_workflow_interface.txt`
`pip install -r requirements_global_dp.txt`

1. `Workflow_Interface_Mnist_Implementation_1.py` uses lower level RDPAccountant and DPDataLoader Opacus objects to perform the privacy accounting and collaborator selection respectively. Local model aggregation and noising is implemented independent of Opacus, and final accounting is calculated by the RDPAccountant, using information about how many rounds of training was performed. To run with this version:

`python Workflow_Interface_Mnist_Implementation_1.py --config_path test_config.yml`

2. `Workflow_Interface_Mnist_Implementation_2.py` uses the higher level PrivacyEngine Opacus object to wrap (using the 'make_private' method) a global data loader (serving up collaborator names), and a global optimizer (performing the local model aggregation and noising), with RDP accounting being performed internally by PrivacyEngine utilizing the fact that it tracks the usage of these wrapped objects over the course of training. To run with this version:

`python Workflow_Interface_Mnist_Implementation_2.py --config_path test_config.yml`

Loading

0 comments on commit 942fccc

Please sign in to comment.