FederatedScope เป็นแพลตฟอร์มการเรียนรู้แบบสหพันธรัฐที่ครอบคลุมซึ่งให้การใช้งานที่สะดวกและการปรับแต่งที่ยืดหยุ่นสำหรับงานการเรียนรู้ที่หลากหลายในสถาบันการศึกษาและอุตสาหกรรม จากสถาปัตยกรรมที่ขับเคลื่อนด้วยเหตุการณ์ FederatedScope ได้รวมคอลเลกชันที่หลากหลายของฟังก์ชันการทำงานเพื่อตอบสนองความต้องการที่เพิ่มขึ้นจากการเรียนรู้จากสหพันธรัฐและมีจุดมุ่งหมายเพื่อสร้างแพลตฟอร์มที่ใช้งานง่ายสำหรับการส่งเสริมการเรียนรู้อย่างปลอดภัยและมีประสิทธิภาพ
มีการสอนโดยละเอียดในเว็บไซต์ของเรา: federatedscope.io
คุณสามารถลอง FederatedScope ผ่านสนามเด็กเล่น FederatedScope หรือ Google Colab
- โครงสร้างรหัส | เริ่มต้นอย่างรวดเร็ว | ขั้นสูง | เอกสาร สิ่งพิมพ์ บริจาค |
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
เราให้ตัวอย่างแบบ end-to-end สำหรับผู้ใช้ในการเริ่มต้นใช้งานหลักสูตร FL มาตรฐานด้วย FederatedScope
ก่อนอื่นผู้ใช้จำเป็นต้องโคลนซอร์สโค้ดและติดตั้งแพ็คเกจที่ต้องการ (เราขอแนะนำเวอร์ชัน Python> = 3.9) คุณสามารถเลือกระหว่างวิธีการติดตั้งสองวิธีต่อไปนี้ (ผ่าน Docker หรือ Conda) เพื่อติดตั้ง FederatedScope
git clone https://github.com/alibaba/FederatedScope.git
cd FederatedScopeคุณสามารถสร้างอิมเมจนักเทียบท่าและทำงานด้วย 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
หมายเหตุ: คุณสามารถเลือกใช้ Cuda 10 และ Torch 1.8 ผ่านการเปลี่ยน torch1.10 เป็น torch1.8 ภาพนักเทียบท่าจะขึ้นอยู่กับ 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-forgeสำหรับผู้ใช้ที่มีชิป Apple M1:
conda install pytorch torchvision torchaudio -c pytorch
# Downgrade torchvision to avoid segmentation fault
python -m pip install torchvision==0.11.3 ในที่สุดหลังจากติดตั้งแบ็กเอนด์คุณสามารถติดตั้ง FederatedScope จาก source :
# 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 ผู้ใช้ควรเตรียมชุดข้อมูล Datazoo ที่ให้ไว้ใน FederatedScope สามารถช่วยในการดาวน์โหลดและประมวลผลชุดข้อมูลสาธารณะที่ใช้กันอย่างแพร่หลายโดยอัตโนมัติสำหรับแอปพลิเคชัน FL ต่างๆรวมถึง CV, NLP, การเรียนรู้กราฟ, คำแนะนำ ฯลฯ ผู้ใช้สามารถระบุ cfg.data.type = DATASET_NAME ในการกำหนดค่าโดยตรง ตัวอย่างเช่น,
cfg.data.type = ' femnist 'ในการใช้ชุดข้อมูลที่กำหนดเองคุณต้องเตรียมชุดข้อมูลตามรูปแบบที่แน่นอนและลงทะเบียน โปรดดูชุดข้อมูลที่กำหนดเองสำหรับรายละเอียดเพิ่มเติม
จากนั้นผู้ใช้ควรระบุสถาปัตยกรรมแบบจำลองที่จะได้รับการฝึกฝนในหลักสูตร FL FederatedScope จัดเตรียมแบบจำลอง ZOO ที่มีการใช้งานสถาปัตยกรรมแบบจำลองที่นำมาใช้อย่างกว้างขวางสำหรับแอปพลิเคชัน FL ต่างๆ ผู้ใช้สามารถตั้งค่า cfg.model.type = MODEL_NAME เพื่อใช้สถาปัตยกรรมโมเดลเฉพาะในงาน FL ตัวอย่างเช่น,
cfg.model.type = 'convnet2'FederatedScope ช่วยให้ผู้ใช้สามารถใช้โมเดลที่กำหนดเองผ่านการลงทะเบียน โปรดดูโมเดลที่กำหนดเองสำหรับรายละเอียดเพิ่มเติมเกี่ยวกับวิธีการปรับแต่งสถาปัตยกรรมแบบจำลอง
โปรดทราบว่า FederatedScope จัดเตรียมอินเทอร์เฟซแบบครบวงจรสำหรับทั้งโหมดสแตนด์อโลนและโหมดกระจายและอนุญาตให้ผู้ใช้เปลี่ยนผ่านการกำหนดค่า
โหมดสแตนด์อโลนใน FederatedScope หมายถึงการจำลองผู้เข้าร่วมหลายคน (เซิร์ฟเวอร์และลูกค้า) ในอุปกรณ์เดียวในขณะที่ข้อมูลของผู้เข้าร่วมถูกแยกออกจากกันและแบบจำลองของพวกเขาอาจถูกแชร์ผ่านข้อความผ่าน
ที่นี่เราแสดงให้เห็นถึงวิธีการเรียกใช้งาน FL มาตรฐานกับ FederatedScope ด้วยการตั้งค่า cfg.data.type = 'FEMNIST' และ cfg.model.type = 'ConvNet2' เพื่อเรียกใช้วานิลลา Fedavg สำหรับงานการจำแนกรูปภาพ ผู้ใช้สามารถปรับแต่งการกำหนดค่าการฝึกอบรมเช่น cfg.federated.total_round_num , cfg.dataloader.batch_size และ cfg.train.optimizer.lr ในการกำหนดค่า (ไฟล์. yaml)
# 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 client_host โปรดทราบว่าสำหรับเซิร์ฟเวอร์คุณต้องตั้ง client_port server_host และ server_port สำหรับการฟังข้อความในขณะที่สำหรับ server_host server_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 เพื่อเพลิดเพลินกับการเดินทางของการเรียนรู้จากสหพันธรัฐ!
วัสดุของหัวข้อที่เกี่ยวข้องได้รับการปรับปรุงอย่างต่อเนื่องโปรดดูที่ FL-Recommendation, Federated-HPO, FL แบบส่วนบุคคล, การเรียนรู้กราฟแบบรวม, FL-NLP, FL-Attacker, กลไกการวัดระดับกลาง, FL-Fairness และอื่น ๆ
คลาสและวิธีการของ FederatedScope ได้รับการบันทึกไว้อย่างดีเพื่อให้ผู้ใช้สามารถสร้างการอ้างอิง API โดย:
cd doc
pip install -r requirements.txt
make htmlบันทึก:
doc/requirements.txt มีไว้สำหรับเอกสารของ API โดย Sphinx ซึ่งสามารถสร้างขึ้นได้โดยอัตโนมัติโดยการกระทำของ GitHub .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 ของเราหรือกลุ่ม Dingding (โปรดสแกนรหัส QR ต่อไปนี้) สำหรับการสนทนา