diff --git a/chapter_federated_learning/privacy_encryption_algorithm.md b/chapter_federated_learning/privacy_encryption_algorithm.md index 1229bea..7b403df 100644 --- a/chapter_federated_learning/privacy_encryption_algorithm.md +++ b/chapter_federated_learning/privacy_encryption_algorithm.md @@ -49,4 +49,87 @@ $$ 从而FL-Server聚合结果$\overline{x}$为: -上面的过程只是介绍了聚合算法的主要思想,基于MPC的聚合方案是精度无损的,代价是通讯轮次的增加。 \ No newline at end of file +上面的过程只是介绍了聚合算法的主要思想,基于MPC的聚合方案是精度无损的,代价是通讯轮次的增加。 + +### 基于LDP-SignDS算法的安全聚合 + +对于先前的基于维度加噪的LDP算法,在隐私预算一定时,添加到每个维度的噪声规模基本上与模型参数的数量成正比。因此,对于高维模型,可能需要非常多的参与方来减轻噪音对模型收敛的影响。为了解决上述“维度依赖”问题,MindSpore Federated Learning进一步提供了基于维度选择的**Sign-based Dimension Selection (SignDS)** :cite:`jiang2022signds`算法,进一步提升模型可用性。这里,我们考虑客户端仅上传本地模型更新(即本地模型和全局模型权重差值)的场景。SignDS算法的主要思想是,对于每一条真实的本地更新$\Delta\in\mathbb{R}^{d}$,用户端首先选择一小部分更新最明显的维度构建topk集合$S_k$,并以此选择一个维度集合$J$返回给服务器。服务器根据维度集合$J$构建一条对应的稀疏更新$\Delta^\prime$,并聚合所有稀疏更新进用于更新全局模型。由于本地模型更新与本地数据信息相关联,直接选取真实的最大更新维度可能导致隐私泄露。对此,SignDS算法在两方面实现了隐私保证。一方面,算法使用了一种基于指数机制(Exponential Mechanism, EM :cite:`mcsherry2007mechanism`)的维度选择算法**EM-MDS**,使得所选维度集满足严格的$\epsilon$-LDP保证;另一方面,在构建稀疏更新时,对所选维度分配一个常量值而不直接使用实际更新值,以保证稀疏更新和本地数据不再直接关联。由于维度选择满足$\epsilon$-LDP,且分配给所选维度的更新值与本地数据无关,根据差分隐私的传递性 :cite:`dwork2014algorithmic`,所构建的稀疏更新同样满足$\epsilon$-LDP保证。**相较于之前基于维度加噪的LDP算法,SignDS算法可以显著提升高维模型的训练精度。同时,由于客户端只需上传一小部分的维度值而不是所有的模型权重,因此联邦学习的上行通信量也被大大降低。** + +下面,我们分别对topk集合$S_k$的构建和EM-MDS维度选择算法进行详细介绍。 + +首先,由于实际更新值有正负,直接给所有选定的维度分配相同的常量值可能会明显改变模型更新方向,影响模型收敛。为了解决这个问题,SignDS提出了一种基于符号的topk集合构建策略。具体来讲,算法引入了一个额外的符号变量$s\in\\{-1,1\\}$。该变量由客户端以等概率随机采样,用于确定本地更新$\Delta$的topk集合$S_k$。如果$s=1$,我们将$\Delta$按**真实更新值**排序,并将**最大**的$k$个更新维度记为$S_k$。我们进一步从$S_k$中随机选择一部分维度,并将$s=1$作为这些维度的更新值用以构建稀疏更新。直觉上,$S_k$中维度的更新值很可能大于零。因此,将$s=1$分配给选定的维度不会导致模型更新方向的太大差异,从而减轻了对模型精度的影响。类似的,当$s=-1$时,我们选取**最小**的$k$个更新维度记为$S_k$,并将$s=-1$分配给所选维度。 + +下面,我们进一步介绍用于维度选择的EM-MDS算法。简单来说,EM-MDS算法的目的是从输出维度域$\mathcal{J}$中以一定概率$\mathcal{P}$随机选择一个维度集合$J\in\mathcal{J}$,不同维度集合对应的概率不同。我们假设$J$总共包含$h$个维度,其中有$\nu$个维度属于topk集合(即$|S_k \cap J|=\nu$,且$\nu\in[0,h]$),另外$h-\nu$个维度属于非topk集合。直观上,$\nu$越大,$J$中包含的topk维度越多,模型收敛越好。因此,我们希望给$\nu$较大的维度集合分配更高的概率。基于这个想法,我们将评分函数定义为: + +$$ +u(S_{k}, J) = 𝟙(|S_k\cap J| \geq \nu_{th}) = 𝟙(\nu \geq \nu_{th}) +$$ +:eqlabel:`score_function` + +$u(S_{k}, J)$用来衡量输出维度集合$J$中包含的topk维度的数量是否超过某一阈值$\nu_{th}$($\nu_{th}\in[1,h]$),超过则为1,否则为0。进一步,$u(S_{k}, J)$的敏感度可计算为: + +$$ +\phi = \max_{J\in\mathcal{J}} ||u(S_{k}, J) - u(S^\prime_{k}, J)||= 1 - 0 = 1 +$$ +:eqlabel:`sensitivity` + +注意 :eqref:`sensitivity`对于任意一对不同的topk集合$S_k$和$S_k^\prime$均成立。 + +根据以上定义,EM-MDS算法描述如下: + +*给定真实本地更新$\Delta\in\mathbb{R}^{d}$的topk集合$S_k$和隐私预算$\epsilon$,输出维度集合$J\in\mathcal{J}$的采样概率为:* + +$$ + \mathcal{P}=\frac{\mathrm{exp}(\frac{\epsilon}{\phi}\cdot u(S_{k}, J))}{\sum_{J^\prime\in\mathcal{J}}\mathrm{exp}(\frac{\epsilon}{\phi}\cdot u(S_{k}, J^\prime))} + = + \frac{\mathrm{exp}(\epsilon\cdot 𝟙(\nu \geq \nu_{th}))}{\sum_{\tau=0}^{\tau=h}\omega_{\tau}\cdot \mathrm{exp}(\epsilon\cdot 𝟙(\tau\geq\nu_{th}))} + = + \frac{\mathrm{exp}(\epsilon\cdot 𝟙(\nu \geq \nu_{th}))}{\sum_{\tau=0}^{\tau=\nu_{th}-1}\omega_{\tau} + \sum_{\tau=\nu_{th}}^{\tau=h}\omega_{\tau}\cdot \mathrm{exp}(\epsilon)} +$$ +:eqlabel:`emmds` + +*其中,$\nu$是$J$中包含的topk维度数量,$\nu_{th}$是评分函数的阈值,$J^\prime$是任意一输出维度集合,$\omega_{\tau}=\binom{k}{\tau}\binom{d-k}{h-\tau}$是所有包含$\tau$个topk维度的集合数。* + +我们进一步提供了EM-MDS算法的隐私证明: + +*对于每个客户端,给定随机采样的符号值$x$,任意两个本地更新$\Delta$,$\Delta^\prime$的topk集合记为$S_k$和$S_k^\prime$,对于任意输出维度集合$J\in\mathcal{J}$,令$\nu=|S_k \cap J|$, $\nu^\prime=|S_k^\prime \cap J|$为$J$与两组topk维度集的交集数量。根据 :eqref:`emmds`,以下不等式成立:* + +$$ + \frac{\mathrm{Pr}\[J|\Delta\]}{\mathrm{Pr}\[J|\Delta^\prime\]} = \frac{\mathrm{Pr}\[J|S_{k}\]}{\mathrm{Pr}\[J|S^\prime_{k}\]} = \frac{\frac{\mathrm{exp}(\frac{\epsilon}{\phi}\cdot u(S_{k}, J))}{\sum_{J^\prime\in\mathcal{J}}\mathrm{exp}(\frac{\epsilon}{\phi}\cdot u(S_{k}, J^\prime))}}{\frac{\mathrm{exp}(\frac{\epsilon}{\phi}\cdot u(S^\prime_{k}, J))}{\sum_{J^\prime\in\mathcal{J}}\mathrm{exp}(\frac{\epsilon}{\phi}\cdot u(S^\prime_{k}, J^\prime))}} + = \frac{\frac{\mathrm{exp}(\epsilon\cdot 𝟙(\nu \geq \nu_{th}))}{\sum_{\tau=0}^{\tau=h}\omega_{\tau}\cdot \mathrm{exp}(\epsilon\cdot 𝟙(\tau\geq\nu_{th}))}}{\frac{ + \mathrm{exp}(\epsilon\cdot 𝟙(\nu^\prime \geq \nu_{th}))}{\sum_{\tau=0}^{\tau=h}\omega_{\tau}\cdot \mathrm{exp}(\epsilon\cdot 𝟙(\tau\geq\nu_{th}))}} \\ + = \frac{\mathrm{exp}(\epsilon\cdot 𝟙(\nu \geq \nu_{th}))}{ + \mathrm{exp}(\epsilon\cdot 𝟙(\nu^\prime \geq \nu_{th}))} + \leq \frac{\mathrm{exp}(\epsilon\cdot 1)}{\mathrm{exp}(\epsilon\cdot 0)} = \mathrm{exp}(\epsilon) +$$ + +*证明EM-MDS算法满足$\epsilon$-LDP保证。* + +值得注意的是,计算 :eqref:`emmds`需要先确定topk维度数的阈值$\nu_{th}$。为此,我们首先推导在给定阈值$\nu_{th}$时,任意一组输出维度集合$J$包含的topk维度的概率分布和期望: + +$$ +\mathrm{Pr}(\nu=\tau|\nu_{th})= + \begin{cases} + \omega_{\tau} / \Omega \quad \quad \quad \quad \quad \mathrm{ } &if \quad \tau\in\[0,\nu_{th}\) \\ + \omega_{\tau}\cdot\mathrm{exp}(\epsilon) / \Omega \quad \quad &if \quad \tau\in\[\nu_{th},h\] + \end{cases} +$$ +:eqlabel:`discrete-prob` + +$$ + \mathbb{E}\[\nu|\nu_{th}\] = \sum_{\tau=0}^{\tau=h}\tau\cdot \mathrm{Pr}(\nu=\tau|\nu_{th}) +$$ +:eqlabel:`expectation` + +这里,$\Omega$为 :eqref:`emmds`中$\mathcal{P}$的分母部分。直觉上,$\mathbb{E}\[\nu|\nu_{th}\]$越高,随机采样的$J$集合中包含的topk维度的概率就越大,从而模型效用就越好。因此,我们将$\mathbb{E}\[\nu|\nu_{th}\]$最高时的阈值确定为目标阈值$\nu_{th}^{\*}$,即: + +$$ + \nu_{th}^{\*} = \underset{\nu_{th}\in\[1, h\]}{\operatorname{argmax}} \mathbb{E}\[\nu|\nu_{th}\] +$$ +:eqlabel:`threshold` + +最后,我们在 :numref:`signds_workflow`中描述了SignDS算法的详细流程。给定本地模型更新$\Delta$,我们首先随机采样一个符号值$s$并构建topk集合$S_k$。接下来,我们根据 :eqref:`threshold`确定阈值$\nu_{th}^{\*}$并遵循 :eqref:`emmds`定义的概率选择输出集合$J$。考虑到输出域$\mathcal{J}$包含$\binom{d}{k}$个可能的维度集合,以一定概率直接从$\mathcal{J}$中随机采样一个组合需要很大的计算成本和空间成本。因此,我们采用了逆采样算法以提升计算效率。具体来说,我们首先从标准均匀分布中采样一个随机值$\beta\sim U(0,1)$,并根据 :eqref:`discrete-prob`中$p(\nu=\tau|\nu_{th})$的累计概率分布$CDF_{\tau}$确定输出维度集合中包含的topk维度数$\nu$。最后,我们从topk集合$S_k$中随机选取$\nu$个维度,从非topk集合中随机采样$h-\nu$个维度,以构建最终的输出维度集合$J$。 + +![SignDS工作流程](../img/ch10/ch10-federated-learning-signds.PNG) +:width:`800px` +:label:`signds_workflow` diff --git a/img/ch10/ch10-federated-learning-signds.PNG b/img/ch10/ch10-federated-learning-signds.PNG new file mode 100644 index 0000000..58668a4 Binary files /dev/null and b/img/ch10/ch10-federated-learning-signds.PNG differ diff --git a/mlsys.bib b/mlsys.bib index 787516a..e522ab9 100644 --- a/mlsys.bib +++ b/mlsys.bib @@ -835,4 +835,31 @@ series = {PPoPP '21} doi = "10.18653/v1/2021.naacl-industry.15", pages = "113--120", abstract = "Transformer and its variants have achieved great success in natural language processing. Since Transformer models are huge in size, serving these models is a challenge for real industrial applications. In this paper, we propose , a highly efficient inference library for models in the Transformer family. includes a series of GPU optimization techniques to both streamline the computation of Transformer layers and reduce memory footprint. supports models trained using PyTorch and Tensorflow. Experimental results on standard machine translation benchmarks show that achieves up to 14x speedup compared with TensorFlow and 1.4x speedup compared with , a concurrent CUDA implementation. The code will be released publicly after the review.", -} \ No newline at end of file +} + +@article{jiang2022signds, + title={SignDS-FL: Local Differentially Private Federated Learning with Sign-based Dimension Selection}, + author={Jiang, Xue and Zhou, Xuebing and Grossklags, Jens}, + journal={ACM Transactions on Intelligent Systems and Technology (TIST)}, + year={2022}, + publisher = {Association for Computing Machinery}, + address = {New York, USA} +} + +@article{dwork2014algorithmic, + title={The algorithmic foundations of differential privacy}, + author={Dwork, Cynthia and Roth, Aaron}, + journal={Foundations and Trends in Theoretical Computer Science}, + volume={9}, + number={3--4}, + pages={211--407}, + year={2014}, +} + +@inproceedings{mcsherry2007mechanism, + title={Mechanism design via differential privacy}, + author={McSherry, Frank and Talwar, Kunal}, + booktitle={IEEE Symposium on Foundations of Computer Science}, + pages={94--103}, + year={2007}, +}