Skip to content

Latest commit

 

History

History
151 lines (103 loc) · 9.92 KB

File metadata and controls

151 lines (103 loc) · 9.92 KB

基于差分隐私的联邦学习

本仓库收集了基于差分隐私的联邦学习的相关论文、以及相应代码。

代码

提示:本仓库的代码均为本人个人实现,如有不准确的地方请联系本人,欢迎互相讨论。 本仓库的FL代码是基于 这个仓库 实现的,希望大家都能点赞多多支持,欢迎大家提交PR完善,谢谢!

注意,为了保证每个客户端被选中的次数是固定的(为了计算机每一次消耗的隐私预算),本代码使用了Round-robin的选择客户端机制,也就是说每个client是都是被顺序选择的。

(重要提示:本代码使用的FL本地更新轮数均为1,请勿更改,一旦更改本地迭代轮数,DP中的敏感度需要重新计算,敏感度上界会是一个很大的值,每一轮消耗的隐私预算会变得很多,请使用local epoch = 1的参数设置。)

参数列表

数据集: MNIST, Cifar-10, FEMNIST, Fashion-MNIST, Shakespeare.

模型: CNN, MLP, LSTM for Shakespeare

DP机制: Laplace, Gaussian(Simple Composition), Gaussian(moments accountant)

DP参数: $\epsilon$ and $\delta$

DP裁剪: 在机器学习任务中,为了计算敏感度,通常情况下需要对梯度进行裁剪,限制梯度的一范数或者二范数的值。

运行样例

实验环境:MNIST、高斯机制(Simple合成定理、Moment Account机制)、拉普拉斯机制。

实验命令:

pip3 install -r requirements.txt
bash run.sh

绘图命令:

python3 draw.py

Gaussian (Simple Composition)

Mnist

Gaussian (Moment Account)

Mnist

Laplace

Mnist

无噪声的FL

python main.py --dataset mnist --iid --model cnn --epochs 50 --dp_mechanism no_dp

高斯机制

Simple合成定理

基于DP中的Simple Composition。

也就是说,如果某个客户端的隐私预算是 $\epsilon$ ,这个客户端被选中 $T$ 次的话,那么该客户端每次加噪使用的预算为 $\epsilon / T$

python main.py --dataset mnist --model cnn --epochs 50 --dp_mechanism Gaussian --dp_epsilon 10 --dp_delta 1e-5 --dp_clip 10

Moments Accountant

本仓库使用Tensorflow Privacy来计算基于Gaussian Mechanism的Moment Account(MA)的噪声标准差。

python main.py --dataset mnist --model cnn --dp_mechanism MA --dp_epsilon 10 --dp_delta 1e-5 --dp_clip 10 --dp_sample 0.01

以下论文可以提供更多信息。

Abadi, Martin, et al. "Deep learning with differential privacy." Proceedings of the 2016 ACM SIGSAC conference on computer and communications security. 2016.

Laplace Mechanism

基于DP中的Simple Composition。

python main.py --dataset mnist --model cnn --epochs 50 --dp_mechanism Laplace --dp_epsilon 30 --dp_clip 50

论文

附注

新版本用了Opacus进行 Per Sample Gradient Clip,限制了每一条Sample计算出的梯度的范数。

本代码设置了本地训练轮数为1,并且batch size为客户端本地的数据集大小,由于Opacus库的训练会保存所有样本的梯度,因此训练时gpu显存占用非常大。 解决此问题可以通过指定 --serial--serial_bs 参数。

这两个参数会从物理上指定一个虚拟的batch size,相应的训练时间会变长,但是逻辑上不会影响训练和DP噪声的添加,这么做的主要原因是为了不违背DP噪声添加的理论。

Dev分支目前还在完善中,里面实现了包括MA、F-DP、以及Shuffle等新的DPFL算法,欢迎感兴趣的朋友提出宝贵意见!

引用

考虑引用以下文章:

[1] W. Yang et al., "Gain Without Pain: Offsetting DP-Injected Noises Stealthily in Cross-Device Federated Learning," in IEEE Internet of Things Journal, vol. 9, no. 22, pp. 22147-22157, 15 Nov.15, 2022, doi: 10.1109/JIOT.2021.3102030.

[2] M. Hu et al., "AutoFL: A Bayesian Game Approach for Autonomous Client Participation in Federated Edge Learning," in IEEE Transactions on Mobile Computing, doi: 10.1109/TMC.2022.3227014.

[3] Y. Zhou et al., "Optimizing the Numbers of Queries and Replies in Convex Federated Learning with Differential Privacy," in IEEE Transactions on Dependable and Secure Computing, doi: 10.1109/TDSC.2023.3234599.

[4] Y. Zhou, et al.,"Exploring the Practicality of Differentially Private Federated Learning: A Local Iteration Tuning Approach" in IEEE Transactions on Dependable and Secure Computing, doi: 10.1109/TDSC.2023.3325889.

[5] Y. Yang, M. Hu, Y. Zhou, X. Liu and D. Wu, "CSRA: Robust Incentive Mechanism Design for Differentially Private Federated Learning," in IEEE Transactions on Information Forensics and Security, doi: 10.1109/TIFS.2023.3329441.