FederatedScopeは、学界と産業の両方でさまざまなフェデレーション学習タスクに便利な使用と柔軟なカスタマイズを提供する包括的なフェデレーション学習プラットフォームです。イベント主導のアーキテクチャに基づいて、FederatedScopeは、機能性の豊富なコレクションを統合して、連邦学習からの急成長する需要を満たし、学習を安全かつ効果的に促進するための使いやすいプラットフォームを構築することを目指しています。
詳細なチュートリアルは、当社のWebサイトfederatedscope.ioで提供されています
FederatedScope PlaygroundまたはGoogle Colabを介してFederatedScopeを試すことができます。
|コード構造|クイックスタート| Advanced |ドキュメント|出版物|寄稿|
FederatedScope
├── federatedscope
│ ├── core
│ | ├── workers # Behaviors of participants (i.e., server and clients)
│ | ├── trainers # Details of local training
│ | ├── aggregators # Details of federated aggregation
│ | ├── configs # Customizable configurations
│ | ├── monitors # The monitor module for logging and demonstrating
│ | ├── communication.py # Implementation of communication among participants
│ | ├── fed_runner.py # The runner for building and running an FL course
│ | ├── ... ..
│ ├── cv # Federated learning in CV
│ ├── nlp # Federated learning in NLP
│ ├── gfl # Graph federated learning
│ ├── autotune # Auto-tunning for federated learning
│ ├── vertical_fl # Vertical federated learning
│ ├── contrib
│ ├── main.py
│ ├── ... ...
├── scripts # Scripts for reproducing existing algorithms
├── benchmark # We release several benchmarks for convenient and fair comparisons
├── doc # For automatic documentation
├── environment # Installation requirements and provided docker files
├── materials # Materials of related topics (e.g., paper lists)
│ ├── notebook
│ ├── paper_list
│ ├── tutorial
│ ├── ... ...
├── tests # Unittest modules for continuous integration
├── LICENSE
└── setup.py
ユーザーがFederatedScopeで標準FLコースの実行を開始するためのエンドツーエンドの例を提供します。
まず、ユーザーはソースコードをクローンして必要なパッケージをインストールする必要があります(Pythonバージョン> = 3.9をお勧めします)。 FederatedScopeをインストールするには、次の2つのインストール方法(DockerまたはCondaを介して)から選択できます。
git clone https://github.com/alibaba/FederatedScope.git
cd FederatedScopeDocker Imageを作成し、Docker Env(Cuda 11およびTorch 1.10)で実行できます。
docker build -f environment/docker_files/federatedscope-torch1.10.Dockerfile -t alibaba/federatedscope:base-env-torch1.10 .
docker run --gpus device=all --rm -it --name "fedscope" -w $(pwd) alibaba/federatedscope:base-env-torch1.10 /bin/bash
Graph FLなどのダウンストリームタスクで実行する必要がある場合は、上記のコマンドを実行するときに要件/Dockerファイル名を別のタスクに変更します。
# environment/requirements-torch1.10.txt ->
environment/requirements-torch1.10-application.txt
# environment/docker_files/federatedscope-torch1.10.Dockerfile ->
environment/docker_files/federatedscope-torch1.10-application.Dockerfile
注: torch1.10 torch1.8に変更して、CUDA 10とTorch 1.8を使用することを選択できます。 Docker画像は、Nvidia-Dockerに基づいています。ホストマシンにNVIDIAドライバーとnvidia-docker2プリインストールしてください。詳細については、こちらをご覧ください。
新しい仮想環境を使用してFederatedScopeをインストールすることをお勧めします。
conda create -n fs python=3.9
conda activate fsバックエンドがトーチの場合は、事前にトーチをインストールしてください(Torch-Get-Started)。たとえば、CUDAバージョンが11.3の場合は、次のコマンドを実行してください。
conda install -y pytorch=1.10.1 torchvision=0.11.2 torchaudio=0.10.1 torchtext=0.11.1 cudatoolkit=11.3 -c pytorch -c conda-forgeApple M1チップを使用しているユーザーの場合:
conda install pytorch torchvision torchaudio -c pytorch
# Downgrade torchvision to avoid segmentation fault
python -m pip install torchvision==0.11.3最後に、バックエンドがインストールされた後、 sourceからFederatedScopeをインストールできます。
# Editable mode
pip install -e .
# Or (developers for dev mode)
pip install -e .[dev]
pre-commit installこれで、FederatedScopeの最小バージョンを正常にインストールしました。 ( Optinal )グラフ、NLP、音声を含むアプリケーションバージョンの場合、実行します。
bash environment/extra_dependencies_torch1.10-application.shFLタスクを実行するには、ユーザーはデータセットを準備する必要があります。 FederatedScopeで提供されるDatazooは、CV、NLP、グラフ学習、推奨など、さまざまなFLアプリケーション用に広く使用されているパブリックデータセットcfg.data.type = DATASET_NAME自動的にダウンロードおよび前処理するのに役立ちます。例えば、
cfg.data.type = ' femnist 'カスタマイズされたデータセットを使用するには、特定の形式に従ってデータセットを準備して登録する必要があります。詳細については、カスタマイズされたデータセットを参照してください。
次に、ユーザーはFLコースでトレーニングされるモデルアーキテクチャを指定する必要があります。 FederatedScopeは、さまざまなFLアプリケーション向けに広く採用されているモデルアーキテクチャの実装を含むModelZooを提供します。ユーザーはcfg.model.type = MODEL_NAMEをセットアップして、FLタスクで特定のモデルアーキテクチャを適用できます。例えば、
cfg.model.type = 'convnet2'FederatedScopeを使用すると、ユーザーは登録を介してカスタマイズされたモデルを使用できます。モデルアーキテクチャのカスタマイズ方法の詳細については、カスタマイズされたモデルを参照してください。
FederatedScopeは、スタンドアロンモードと分散モードの両方に統一されたインターフェイスを提供し、ユーザーが構成を介して変更できるようにすることに注意してください。
FederatedScopeのスタンドアロンモードは、単一のデバイスで複数の参加者(サーバーとクライアント)をシミュレートすることを意味しますが、参加者のデータは互いに分離され、メッセージの合格を介してモデルが共有される可能性があります。
ここではcfg.data.type = 'FEMNIST'およびcfg.model.type = 'ConvNet2'を設定して、FederatedScopeを使用して標準FLタスクを実行する方法を示します。ユーザーは、 cfg.federated.total_round_num 、 cfg.dataloader.batch_size 、 cfg.train.optimizer.lrなどのトレーニング構成をカスタマイズできます。
# Run with default configurations
python federatedscope/main.py --cfg scripts/example_configs/femnist.yaml
# Or with custom configurations
python federatedscope/main.py --cfg scripts/example_configs/femnist.yaml federate.total_round_num 50 dataloader.batch_size 128次に、トレーニングプロセス中にいくつかの監視対象メトリックを観察できます。
INFO: Server has been set up ...
INFO: Model meta-info: <class 'federatedscope.cv.model.cnn.ConvNet2'>.
... ...
INFO: Client has been set up ...
INFO: Model meta-info: <class 'federatedscope.cv.model.cnn.ConvNet2'>.
... ...
INFO: {'Role': 'Client #5', 'Round': 0, 'Results_raw': {'train_loss': 207.6341676712036, 'train_acc': 0.02, 'train_total': 50, 'train_loss_regular': 0.0, 'train_avg_loss': 4.152683353424072}}
INFO: {'Role': 'Client #1', 'Round': 0, 'Results_raw': {'train_loss': 209.0940284729004, 'train_acc': 0.02, 'train_total': 50, 'train_loss_regular': 0.0, 'train_avg_loss': 4.1818805694580075}}
INFO: {'Role': 'Client #8', 'Round': 0, 'Results_raw': {'train_loss': 202.24929332733154, 'train_acc': 0.04, 'train_total': 50, 'train_loss_regular': 0.0, 'train_avg_loss': 4.0449858665466305}}
INFO: {'Role': 'Client #6', 'Round': 0, 'Results_raw': {'train_loss': 209.43883895874023, 'train_acc': 0.06, 'train_total': 50, 'train_loss_regular': 0.0, 'train_avg_loss': 4.1887767791748045}}
INFO: {'Role': 'Client #9', 'Round': 0, 'Results_raw': {'train_loss': 208.83140087127686, 'train_acc': 0.0, 'train_total': 50, 'train_loss_regular': 0.0, 'train_avg_loss': 4.1766280174255375}}
INFO: ----------- Starting a new training round (Round #1) -------------
... ...
INFO: Server: Training is finished! Starting evaluation.
INFO: Client #1: (Evaluation (test set) at Round #20) test_loss is 163.029045
... ...
INFO: Server: Final evaluation is finished! Starting merging results.
... ...
FederatedScopeの分散モードは、複数の手順を実行してFLコースを構築することを示します。各手順は、モデルをインスタンス化してデータをロードする参加者(サーバーまたはクライアント)として再生されます。参加者間の通信は、FederatedScopeの通信モジュールによってすでに提供されています。
分散モードで実行するには、次のことだけが必要です。
cfg.data.file_path = PATH/TO/DATAをセットアップします。cfg.federate.model = 'distributed'を変更し、 cfg.distributed.role = 'server'/'client'で各参加者の役割を指定します。cfg.distribute.server_host/client_host = xxxxおよびcfg.distribute.server_port/client_port = xxxxで有効なアドレスを設定します。 (サーバーの場合、リスニングメッセージにserver_hostとserver_port server_port client_host client_port server_hostにセットアップする必要があります。分散モードで実行するための合成例を準備します。
# For server
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_server.yaml data.file_path ' PATH/TO/DATA ' distribute.server_host x.x.x.x distribute.server_port xxxx
# For clients
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_client_1.yaml data.file_path ' PATH/TO/DATA ' distribute.server_host x.x.x.x distribute.server_port xxxx distribute.client_host x.x.x.x distribute.client_port xxxx
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_client_2.yaml data.file_path ' PATH/TO/DATA ' distribute.server_host x.x.x.x distribute.server_port xxxx distribute.client_host x.x.x.x distribute.client_port xxxx
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_client_3.yaml data.file_path ' PATH/TO/DATA ' distribute.server_host x.x.x.x distribute.server_port xxxx distribute.client_host x.x.x.x distribute.client_port xxxx生成されたおもちゃデータを使用した実行可能な例は、( scripts/run_distributed_lr.shにスクリプトを見つけることができます):で実行できます):
# Generate the toy data
python scripts/distributed_scripts/gen_data.py
# Firstly start the server that is waiting for clients to join in
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_server.yaml data.file_path toy_data/server_data distribute.server_host 127.0.0.1 distribute.server_port 50051
# Start the client #1 (with another process)
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_client_1.yaml data.file_path toy_data/client_1_data distribute.server_host 127.0.0.1 distribute.server_port 50051 distribute.client_host 127.0.0.1 distribute.client_port 50052
# Start the client #2 (with another process)
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_client_2.yaml data.file_path toy_data/client_2_data distribute.server_host 127.0.0.1 distribute.server_port 50051 distribute.client_host 127.0.0.1 distribute.client_port 50053
# Start the client #3 (with another process)
python federatedscope/main.py --cfg scripts/distributed_scripts/distributed_configs/distributed_client_3.yaml data.file_path toy_data/client_3_data distribute.server_host 127.0.0.1 distribute.server_port 50051 distribute.client_host 127.0.0.1 distribute.client_port 50054そして、あなたは結果を観察することができます(IPアドレスは「xxxx」で匿名化されます):
INFO: Server: Listen to x.x.x.x:xxxx...
INFO: Server has been set up ...
Model meta-info: <class 'federatedscope.core.lr.LogisticRegression'>.
... ...
INFO: Client: Listen to x.x.x.x:xxxx...
INFO: Client (address x.x.x.x:xxxx) has been set up ...
Client (address x.x.x.x:xxxx) is assigned with #1.
INFO: Model meta-info: <class 'federatedscope.core.lr.LogisticRegression'>.
... ...
{'Role': 'Client #2', 'Round': 0, 'Results_raw': {'train_avg_loss': 5.215108394622803, 'train_loss': 333.7669372558594, 'train_total': 64}}
{'Role': 'Client #1', 'Round': 0, 'Results_raw': {'train_total': 64, 'train_loss': 290.9668884277344, 'train_avg_loss': 4.54635763168335}}
----------- Starting a new training round (Round #1) -------------
... ...
INFO: Server: Training is finished! Starting evaluation.
INFO: Client #1: (Evaluation (test set) at Round #20) test_loss is 30.387419
... ...
INFO: Server: Final evaluation is finished! Starting merging results.
... ...
包括的なFLプラットフォームとして、FederatedScopeは、さまざまなFLアプリケーションとフロンティア研究の要件をサポートするための基本的な実装を提供します。
その他のサポートはもうすぐです! FederatedScopeを利用してFederated Learningの旅を楽しむ方法についての詳細を提供するチュートリアルを用意しました!
関連するトピックの資料は絶えず更新されています。FL-Commendation、Federated-HPO、パーソナライズされたFL、FL-NLP、FL-attacker、FL-Incentive-Mechanism、FL-Fairnessなどを参照してください。
FederatedScopeのクラスと方法は、ユーザーがAPI参照を生成できるように、十分に文書化されています。
cd doc
pip install -r requirements.txt
make html注記:
doc/requirements.txtは、SphinxによるAPIのドキュメント専用です。これは、github actions .github/workflows/sphinx.ymlによって自動的に生成できます。 (タイトルのDOCの場合、プルリクエストによるトリガー。)API参照をWebサイトに配置します。
また、実行可能なスクリプトとカスタマイズ可能な構成のドキュメントを提供します。
FederatedScopeはApacheライセンス2.0でリリースされます。
あなたの研究や開発に役立つFederatedScopeを見つけた場合は、次の論文を引用してください。
@article{federatedscope,
title = {FederatedScope: A Flexible Federated Learning Platform for Heterogeneity},
author = {Xie, Yuexiang and Wang, Zhen and Gao, Dawei and Chen, Daoyuan and Yao, Liuyi and Kuang, Weirui and Li, Yaliang and Ding, Bolin and Zhou, Jingren},
journal={Proceedings of the VLDB Endowment},
volume={16},
number={5},
pages={1059--1072},
year={2023}
}
より多くの出版物が出版物にあります。
FederatedScopeへの貢献には大いに感謝します! FederatedScopeの開発者バージョンに、公式バージョンと比較してコミットチェックを実行する追加の事前コミットフックを提供します。
# Install the developer version
pip install -e .[dev]
pre-commit install
# Or switch to the developer version from the official version
pip install pre-commit
pre-commit install
pre-commit run --all-files詳細については、FederatedScopeに貢献することを参照できます。
ディスカッションのために、Slackチャンネルまたはディンディンググループ(次のQRコードをスキャンしてください)に参加してください。