FederatedScope는 학계와 산업 모두에서 다양한 연합 학습 작업에 편리한 사용법과 유연한 사용자 정의를 제공하는 포괄적 인 Federated 학습 플랫폼입니다. 이벤트 중심의 아키텍처를 기반으로 FederatedScope는 풍부한 기능 컬렉션을 통합하여 Federated Learning의 급성장 요구를 충족시키고 학습을 안전하고 효과적으로 홍보하기위한 사용하기 쉬운 플랫폼을 구축하는 것을 목표로합니다.
세부 튜토리얼은 당사 웹 사이트 인 FederatedScope.io에 제공됩니다
FederatedScope Playground 또는 Google Colab을 통해 FederatedScope를 사용해 볼 수 있습니다.
| 코드 구조 | 빠른 시작 | 고급 | 문서 | 간행물 | 기고 |
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를 설치하려면 다음 두 설치 방법 (Docker 또는 Conda를 통해)을 선택할 수 있습니다.
git clone https://github.com/alibaba/FederatedScope.git
cd FederatedScopeDocker 이미지를 만들고 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
그래프 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백엔드가 횃불 인 경우, 토치를 미리 설치하십시오 (토치가 시작). 예를 들어 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.sh FL 작업을 실행하려면 사용자가 데이터 세트를 준비해야합니다. 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' 를 설정하여 이미지 분류 작업을 위해 Vanilla Fedavg를 실행하여 FederatedScope로 표준 FL 작업을 실행하는 방법을 보여줍니다. 사용자는 cfg.federated.total_round_num , cfg.dataloader.batch_size 및 cfg.train.optimizer.lr 과 같은 교육 구성을 사용자 정의하고 다음과 같이 표준 FL 작업을 실행할 수 있습니다.
# 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 설정 해야하는 반면 클라이언트의 경우 FL 코스에 가입하려면 server_host 및 server_port 듣기 위해 client_host 및 client_port 설정해야합니다).분산 모드로 실행하기위한 합성 예제를 준비합니다.
# 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- 재임명, Federated-HPO, Personalized FL, Federated Graph Learning, FL-NLP, FL-Attacker, FL-Incentive-Mechanisis, FL-FAIRNESS 등을 참조하십시오.
FederatedScope의 클래스 및 방법은 사용자가 API 참조를 생성 할 수 있도록 잘 문서화되었습니다.
cd doc
pip install -r requirements.txt
make html메모:
doc/requirements.txt 는 Sphinx의 API 문서화에만 해당되며 GitHub Action .github/workflows/sphinx.yml 에 의해 자동으로 생성 될 수 있습니다. (제목에 DOC 이면 풀 요청에 의해 트리거됩니다.)우리는 API 참조를 웹 사이트에 넣습니다.
또한 실행 가능한 스크립트 및 사용자 정의 가능한 구성에 대한 문서를 제공합니다.
FederatedScope는 Apache License 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 Channel에 가입하거나 Dingding Group (다음 QR 코드를 스캔)에서 토론에 오신 것을 환영합니다.