Skip to content

Commit

Permalink
Merge branch 'main' into improve_ci_speed
Browse files Browse the repository at this point in the history
* main:
  Remove line with typo from script (#2001)
  Fix simulation error caused by Pydantic version in Ray (#2002)
  Update mxnet examples dependency versions (#1982)
  Update torch version in pyproject.toml files (#1993)
  Update tensorflow examples dependency versions (#1984)
  Fix the baseline template docstrings (#1983)
  Fix Baselines CI PyLint error by using Resampling (#1998)
  Make tensorflow optional when using tensorboard (#1879)
  Update dependencies for MXNet example (#1988)
  Fix `starlette` vulnerability (#1992)
  Fix vulnerability detected by Dependabot (#1990)
  Fix dependabot critical errors (#1989)
  Add Ruff UP check (#1946)
  Update torch examples dependency versions (#1981)
  Remove && from the end of lines in test.sh (#1979)
  Baselines docs updates (#1977)
  Fixes GitHub CI issue because of behaviour change (#1976)
  • Loading branch information
tanertopal committed Jul 5, 2023
2 parents caeefb7 + afbdad4 commit afe26c3
Show file tree
Hide file tree
Showing 53 changed files with 245 additions and 234 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flower-swift_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Pushes src/swift to flower-swift repository
uses: cpina/github-action-push-to-another-repository@0a14457
uses: cpina/github-action-push-to-another-repository@0a14457bb28b04dfa1652e0ffdfda866d2845c73
env:
SSH_DEPLOY_KEY: ${{ secrets.FLOWER_SWIFT_SSH }}
with:
Expand Down
1 change: 1 addition & 0 deletions baselines/baseline_template/baseline_template/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Template baseline package."""
10 changes: 5 additions & 5 deletions baselines/baseline_template/baseline_template/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##################################################################################
# Please use this module to define your client class and a function to construct #
# such clients. Most of the code here is expected to be defined inside a class #
# that inherits from `flwr.client.NumPyClient` or `flwr.client.Client`. #
##################################################################################
"""Define your client class and a function to construct such clients.
Please overwrite `flwr.client.NumPyClient` or `flwr.client.Client` and create a function
to instantiate your client.
"""
19 changes: 10 additions & 9 deletions baselines/baseline_template/baseline_template/dataset.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
##################################################################################
# Please use this module to define the functions to create the dataloaders for #
# your dataset (for both the clients and the server). If you are using a custom #
# dataset class, this module is the place to define it. If your dataset requires #
# to be downloaded (and this is not done automatically -- e.g. as it is the case #
# for many dataset in TorchVision) and partitioned, please include all those #
# functions and logic in the `dataset_preparation.py` module. You can all those #
# functions from functions/methods defined here of course. #
##################################################################################
"""Handle basic dataset creation.
In case of PyTorch it should return dataloaders for your dataset (for both the clients
and the server). If you are using a custom dataset class, this module is the place to
define it. If your dataset requires to be downloaded (and this is not done
automatically -- e.g. as it is the case for many dataset in TorchVision) and
partitioned, please include all those functions and logic in the
`dataset_preparation.py` module. You can use all those functions from functions/methods
defined here of course.
"""
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
####################################################################################
# So you have a dataset that needs to be partitioned? Or does your dataset require #
# a non-standard way of obtaining it (i.e. because you are not limiting your base- #
# line to MNIST, CIFAR-10 et al)? Then this is the module for you! Please add here #
# all the necessary logic to either download, uncompress, pre/post-process your #
# dataset (or all of the above). If the desired way of running your baseline is #
# to first download the dataset and partition it and then run the experiments, #
# please uncomment the lines below and tell us in the README.md (see the "Running #
# the Experiment" block) that this file should be executed first. #
####################################################################################


"""Handle the dataset partitioning and (optionally) complex downloads.
Please add here all the necessary logic to either download, uncompress, pre/post-process
your dataset (or all of the above). If the desired way of running your baseline is to
first download the dataset and partition it and then run the experiments, please
uncomment the lines below and tell us in the README.md (see the "Running the Experiment"
block) that this file should be executed first.
"""
# import hydra
# from hydra.core.hydra_config import HydraConfig
# from hydra.utils import call, instantiate
Expand Down
35 changes: 15 additions & 20 deletions baselines/baseline_template/baseline_template/main.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
###########################################################################
# This is the main file, it creates and connects all the building #
# blocks of your experiment (processes the dataset, defines the clients, #
# the strategy, and how the global model is going to be evaluated, etc) #
# and it starts the simulation. At the end, this script saves the results.#
###########################################################################

"""Create and connect the building blocks for your experiments; start the simulation.
It includes processioning the dataset, instantiate strategy, specify how the global
model is going to be evaluated, etc. At the end, this script saves the results.
"""
# these are the basic packages you'll need here
# feel free to remove some if aren't needed
import flwr as fl
import hydra
from hydra.core.hydra_config import HydraConfig
from hydra.utils import call, instantiate
from omegaconf import DictConfig, OmegaConf


@hydra.main(config_path="conf", config_name="base", version_base=None)
def main(cfg: DictConfig) -> None:
"""Main function to run this baseline.
"""Run the baseline.
Parameters
----------
cfg : DictConfig
An omegaconf object that stores the hydra config.
"""

## 1. print parsed config
## 1. Print parsed config
print(OmegaConf.to_yaml(cfg))

## 2. prepare your dataset
## 2. Prepare your dataset
# here you should call a function in datasets.py that returns whatever is needed to:
# (1) ensure the server can access the dataset used to evaluate your model after aggregation
# (2) tell each client what dataset partitions they should use (e.g. a this could be a location
# in the file system, a list of dataloader, a list of ids to extract from a dataset, it's up to you)
# (1) ensure the server can access the dataset used to evaluate your model after
# aggregation
# (2) tell each client what dataset partitions they should use (e.g. a this could
# be a location in the file system, a list of dataloader, a list of ids to extract
# from a dataset, it's up to you)

## 3. Define your clients
# Define a function that returns another function that will be used during simulation
# to instantiate each individual client
# Define a function that returns another function that will be used during
# simulation to instantiate each individual client
# client_fn = client.<my_function_that_returns_a_function>()

## 4. Define your strategy
Expand All @@ -55,4 +50,4 @@ def main(cfg: DictConfig) -> None:
# data = strategy.get_my_custom_data() -- assuming you have such method defined.
# Hydra will generate for you a directory each time you run the code. You
# can retrieve the path to that directory with this:
# save_path = HydraConfig.get().runtime.output_dir
# save_path = HydraConfig.get().runtime.output_dir
14 changes: 7 additions & 7 deletions baselines/baseline_template/baseline_template/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##################################################################################
# Please use this module to define your models, and training and eval #
# functions. If your model is 100% off-the-shelf (e.g. directly from torchvision #
# without requiring modifications) you might be better off instantiating your #
# model directly from the Hydra config. In this way, swapping your model for #
# another one can be done without changing the python code at all #
##################################################################################
"""Define our models, and training and eval functions.
If your model is 100% off-the-shelf (e.g. directly from torchvision without requiring
modifications) you might be better off instantiating your model directly from the Hydra
config. In this way, swapping your model for another one can be done without changing
the python code at all
"""
11 changes: 5 additions & 6 deletions baselines/baseline_template/baseline_template/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
##############################################################################
# Please use this module to define the function called by your strategy in #
# order to evaluate the state of the global model. You might use this module #
# also to define a new Server class (please note this is not needed in most #
# settings). #
##############################################################################
"""Create global evaluation function.
Optionally, also define a new Server class (please note this is not needed in most
settings).
"""
10 changes: 5 additions & 5 deletions baselines/baseline_template/baseline_template/strategy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#############################################################################
# Only use this module if you need to define a custom strategy whether #
# because it is not yet implemented in Flower or because you want to extend #
# or modify the functionality of an existing strategy. #
#############################################################################
"""Optionally define a custom strategy.
Needed only when the strategy is not yet implemented in Flower or because you want to
extend or modify the functionality of an existing strategy.
"""
11 changes: 6 additions & 5 deletions baselines/baseline_template/baseline_template/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#################################################################################
# Please define here any utility function that's not directly relevant to #
# the other (more FL specific) python modules. For example, you may define #
# here things like: loading a model from a checkpoint, saving results, plotting #
#################################################################################
"""Define any utility function.
They are not directly relevant to the other (more FL specific) python modules. For
example, you may define here things like: loading a model from a checkpoint, saving
results, plotting.
"""
1 change: 0 additions & 1 deletion baselines/flwr_baselines/dev/setup-defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ else
# If pyenv is already installed, check for a newer version
read -p 'Pyenv already installed, do you want to updating it y/[n]? ' update
update="${update:-"n"}"
update="${update,,}"

if [ $update == "y" ]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _preprocess_images(self) -> pd.DataFrame:
file_path = row["path_by_writer"]
img = Image.open(file_path)
gray = img.convert("L")
gray.thumbnail(resized_size, Image.LANCZOS)
gray.thumbnail(resized_size, Image.Resampling.LANCZOS)
writer_id = row["writer_id"]
character = row["character"]
if writer_id not in writer_to_character_to_count:
Expand Down
1 change: 0 additions & 1 deletion dev/setup-defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ else
# If pyenv is already installed, check for a newer version
read -p 'Pyenv already installed, do you want to updating it y/[n]? ' update
update="${update:-"n"}"
update="${update,,}"

if [ $update == "y" ]
then
Expand Down
66 changes: 33 additions & 33 deletions dev/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,52 @@ echo "=== test.sh ==="

echo "- Start Python checks"

echo "- clang-format: start" &&
clang-format --Werror --dry-run src/proto/flwr/proto/* &&
echo "- clang-format: done" &&
echo "- clang-format: start"
clang-format --Werror --dry-run src/proto/flwr/proto/*
echo "- clang-format: done"

echo "- isort: start" &&
python -m isort --check-only --skip src/py/flwr/proto src/py/flwr &&
echo "- isort: done" &&
echo "- isort: start"
python -m isort --check-only --skip src/py/flwr/proto src/py/flwr
echo "- isort: done"

echo "- black: start" &&
python -m black --exclude "src\/py\/flwr\/proto" --check src/py/flwr &&
echo "- black: done" &&
echo "- black: start"
python -m black --exclude "src\/py\/flwr\/proto" --check src/py/flwr
echo "- black: done"

echo "- init_py_check: start" &&
python -m flwr_tool.init_py_check src/py/flwr src/py/flwr_tool &&
echo "- init_py_check: done" &&
echo "- init_py_check: start"
python -m flwr_tool.init_py_check src/py/flwr src/py/flwr_tool
echo "- init_py_check: done"

echo "- docformatter: start" &&
python -m docformatter -c -r src/py/flwr -e src/py/flwr/proto &&
echo "- docformatter: done" &&
echo "- docformatter: start"
python -m docformatter -c -r src/py/flwr -e src/py/flwr/proto
echo "- docformatter: done"

echo "- ruff: start" &&
python -m ruff check src/py/flwr &&
echo "- ruff: done" &&
echo "- ruff: start"
python -m ruff check src/py/flwr
echo "- ruff: done"

echo "- mypy: start" &&
python -m mypy src/py &&
echo "- mypy: done" &&
echo "- mypy: start"
python -m mypy src/py
echo "- mypy: done"

echo "- pylint: start" &&
python -m pylint --ignore=src/py/flwr/proto src/py/flwr &&
echo "- pylint: done" &&
echo "- pylint: start"
python -m pylint --ignore=src/py/flwr/proto src/py/flwr
echo "- pylint: done"

echo "- flake8: start" &&
python -m flake8 src/py/flwr &&
echo "- flake8: done" &&
echo "- flake8: start"
python -m flake8 src/py/flwr
echo "- flake8: done"

echo "- pytest: start" &&
python -m pytest --cov=src/py/flwr &&
echo "- pytest: done" &&
echo "- pytest: start"
python -m pytest --cov=src/py/flwr
echo "- pytest: done"

echo "- All Python checks passed"

echo "- Start Markdown checks"

echo "- mdformat: start" &&
python -m mdformat --check --number doc/source/tutorial examples &&
echo "- mdformat: done" &&
echo "- mdformat: start"
python -m mdformat --check --number doc/source/tutorial examples
echo "- mdformat: done"

echo "- All Markdown checks passed"
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
# "color-brand-content": "#292F36",
# "color-admonition-background": "#F2B705",
# },
"announcement": 'Flower Summit 2023 <a href="https://flower.dev/conf/flower-summit-2023/">register now</a>',
}

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down
2 changes: 1 addition & 1 deletion doc/source/contributing-baselines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ We are adopting `Hydra <https://hydra.cc/>`_ as the default mechanism to manage
Usability
---------

Flower is known and loved for its usability. Therefore, make sure that your baseline or experiment can be executed with a single command such as :code:`conda run -m <your-baseline>.main` or :code:`python main.py` (when sourced into your environment). We provide you with a `template-baseline <https://github.com/adap/flower/tree/sor_template/baselines/flwr_baselines>`_ to use as guidance when contributing your baseline. Having all baselines follow a homogenous structure helps users to tryout many baselines without the overheads of having to understand each individual codebase. Similarly, by using Hydra throughout, users will immediately know how to parameterise your experiments directly from the command line.
Flower is known and loved for its usability. Therefore, make sure that your baseline or experiment can be executed with a single command such as :code:`conda run -m <your-baseline>.main` or :code:`python main.py` (when sourced into your environment). We provide you with a `template-baseline <https://github.com/adap/flower/tree/main/baselines/baseline_template>`_ to use as guidance when contributing your baseline. Having all baselines follow a homogenous structure helps users to tryout many baselines without the overheads of having to understand each individual codebase. Similarly, by using Hydra throughout, users will immediately know how to parameterise your experiments directly from the command line.

We look forward to your contribution!
8 changes: 4 additions & 4 deletions examples/advanced_pytorch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ authors = [
]

[tool.poetry.dependencies]
python = "^3.7"
flwr = "^1.0.0"
torch = "^1.12.0"
torchvision = "^0.13.0"
python = ">=3.8,<3.11"
flwr = ">=1.0,<2.0"
torch = "1.13.1"
torchvision = "0.13.0"
validators = "0.18.2"
7 changes: 4 additions & 3 deletions examples/advanced_pytorch/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
flwr~=1.4.0
torch~=2.0.1
torchvision~=0.15.2
flwr>=1.0, <2.0
torch==1.13.1
torchvision==0.13.0

7 changes: 3 additions & 4 deletions examples/advanced_tensorflow/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ authors = ["The Flower Authors <hello@flower.dev>"]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"
flwr = "^1.0.0"
tensorflow-cpu = {version = "^2.9.1, !=2.11.1", markers="platform_machine == 'x86_64'"}
tensorflow-macos = {version = "^2.9.1, !=2.11.1", markers="sys_platform == 'darwin' and platform_machine == 'arm64'"}

flwr = ">=1.0,<2.0"
tensorflow-cpu = {version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "platform_machine == \"x86_64\""}
tensorflow-macos = {version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "sys_platform == \"darwin\" and platform_machine == \"arm64\""}
5 changes: 3 additions & 2 deletions examples/advanced_tensorflow/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flwr~=1.4.0
tensorflow~=2.12.0
flwr>=1.0, <2.0
tensorflow-macos>=2.9.1, != 2.11.1 ; sys_platform == "darwin" and platform_machine == "arm64"
tensorflow-cpu>=2.9.1, != 2.11.1 ; platform_machine == "x86_64"
6 changes: 3 additions & 3 deletions examples/android/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = ["The Flower Authors <hello@flower.dev>"]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"
flwr = "^1.0.0"
# flwr = { path = "../../", develop = true } # Development
tensorflow-cpu = {version = "^2.9.1, !=2.11.1", markers="platform_machine == 'x86_64'"}
tensorflow-macos = {version = "^2.9.1, !=2.11.1", markers="sys_platform == 'darwin' and platform_machine == 'arm64'"}
flwr = ">=1.0,<2.0"
tensorflow-cpu = {version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "platform_machine == \"x86_64\""}
tensorflow-macos = {version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "sys_platform == \"darwin\" and platform_machine == \"arm64\""}
4 changes: 3 additions & 1 deletion examples/android/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
numpy~=1.21.1
flwr>=1.0, <2.0
tensorflow-macos>=2.9.1, != 2.11.1 ; sys_platform == "darwin" and platform_machine == "arm64"
tensorflow-cpu>=2.9.1, != 2.11.1 ; platform_machine == "x86_64"
10 changes: 5 additions & 5 deletions examples/dp-sgd-mnist/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ authors = [
]

[tool.poetry.dependencies]
python = "^3.8"
flwr = "^1.0.0"
python = ">=3.8,<3.11"
# flwr = { path = "../../", develop = true } # Development
tensorflow-cpu = {version = "^2.9.1, !=2.11.1", markers="platform_machine == 'x86_64'"}
tensorflow-macos = {version = "^2.9.1, !=2.11.1", markers="sys_platform == 'darwin' and platform_machine == 'arm64'"}
tensorflow-privacy = {git = "https://github.com/tensorflow/privacy", rev = "aaf4c25"}
flwr = ">=1.0,<2.0"
tensorflow-cpu = {version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "platform_machine == \"x86_64\""}
tensorflow-macos = {version = ">=2.9.1,<2.11.1 || >2.11.1", markers = "sys_platform == \"darwin\" and platform_machine == \"arm64\""}
tensorflow-privacy = "0.8.10"
8 changes: 4 additions & 4 deletions examples/dp-sgd-mnist/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flwr~=1.4.0
numpy~=1.21.1
tensorflow~=2.12.0
tensorflow_privacy~=0.8.9
flwr>=1.0, <2.0
tensorflow-macos>=2.9.1, != 2.11.1 ; sys_platform == "darwin" and platform_machine == "arm64"
tensorflow-cpu>=2.9.1, != 2.11.1 ; platform_machine == "x86_64"
tensorflow-privacy==0.8.10
10 changes: 5 additions & 5 deletions examples/mt-pytorch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ description = "Multi-Tenant Federated Learning with Flower and PyTorch"
authors = ["The Flower Authors <hello@flower.dev>"]

[tool.poetry.dependencies]
python = "^3.7"
flwr = { path = "../../", develop = true, extras = ["simulation", "rest"] }
torch = "^1.12.0"
torchvision = "^0.13.0"
tqdm = "^4.63.0"
python = ">=3.8,<3.11"
flwr-nightly = {extras = ["rest", "simulation"], version = "^1.5.0.dev20230629"}
torch = "1.13.1"
torchvision = "0.13.0"
tqdm = "4.65.0"
Loading

0 comments on commit afe26c3

Please sign in to comment.