Category Catalog: "In-depth Understanding of Federated Learning" General Catalog
Assume that the data provider for federated learning is AAA andBBB , the third party isCCC , then the steps of vertical federated learning are as follows:
- Encrypted sample alignment is performed at the system level, and non-crossing users will not be exposed at the enterprise perception level.
- Align samples for model encryption training:
- CC by third partyC toAAA andBBB sends the public key to encrypt the data that needs to be transmitted;
- A A A andBBB respectively calculates the intermediate results of features related to itself and encrypts the interaction.
- A AA andBBB calculates their respective encrypted gradients and adds masks and sends them toCC.C , while owning the class standard side, calculate the encrypted loss and send it toCCC
- C C C decrypts the gradient and loss and passes it back toAAA andBBB
- A AA andBBB remove the mask and update the model
We take ridge regression as an example to illustrate the training process of longitudinal federated learning. Suppose there is a data set { xi A } ( i ∈ DA ) \{x_i^A\}(i\in D_A){ xiA}(i∈DA) 和数据集 { x i B , y i B } ( i ∈ D B ) \{x_i^B, y_i^B\}(i\in D_B) { xiB,yiB}(i∈DB) , whereBBB is the data owner with the class label. We take linear regression as an example to illustrate the training process of vertical federated learning:
- A A A andBBB initialize the model parametersΘ A \Theta_AThA和Θ B \Theta_BThBFor example: min Θ A , Θ B ∑ i ( Θ A xi A + Θ B xi B − yi ) 2 + λ 2 ( ∣ ∣ Θ A ∣ ∣ 2 + ∣ ∣ Θ B ∣ ∣ 2 ) \ min_{\Theta_A, \Theta_B}\sum_i(\Theta_Ax_i^A+\Theta_Bx_i^B-y_i)^2+\frac{\lambda}{2}(||\Theta_A||^2+||\Theta_B|| ^2)ThA, ThBmini∑( ThAxiA+ThBxiB−yi)2+2l(∣∣ΘA∣∣2+∣∣ΘB∣∣2)
- 令 u i A = Θ A x i A u_i^A=\Theta_Ax_i^A uiA=ThAxiAsumui B = Θ B xi B u_i^B=\Theta_Bx_i^BuiB=ThBxiB, then the original objective function is homomorphically encrypted ( [ [ ⋅ ] ] [[\cdot]][[⋅]]表示同态加密)可表示为: [ [ L ] ] = [ [ ∑ i ( u i A + u i B − y i ) 2 + λ 2 ( ∣ ∣ Θ A ∣ ∣ 2 + ∣ ∣ Θ B ∣ ∣ 2 ) ] ] = [ [ ∑ i ( u i A ) 2 + λ 2 ∣ ∣ Θ A ∣ ∣ 2 ] ] + [ [ ∑ i ( ( u i B − y i ) 2 ) + λ 2 ∣ ∣ Θ B ∣ ∣ 2 ] ] + 2 ∑ i ( [ [ u i A ] ] ( u i B − y i ) ) \begin{aligned}[[L]] &= [[\sum_i(u_i^A+u_i^B-y_i)^2+\frac{\lambda}{2}(||\Theta_A||^2+||\Theta_B||^2)]]\\&=[[\sum_i(u_i^A)^2+\frac{\lambda}{2}||\Theta_A||^2]]+[[\sum_i((u_i^B-y_i)^2)+\frac{\lambda}{2}||\Theta_B||^2]]+2\sum_i([[u_i^A]](u_i^B-y_i))\end{aligned} [[L]]=[[i∑(uiA+uiB−yi)2+2l(∣∣ΘA∣∣2+∣∣ΘB∣∣2)]]=[[i∑(uiA)2+2l∣∣ΘA∣∣2]]+[[i∑((uiB−yi)2)+2l∣∣ΘB∣∣2]]+2i∑([[uiA]](uiB−yi))
- 我们令: [ [ L A ] ] = [ [ ∑ i ( u i A ) 2 + λ 2 ∣ ∣ Θ A ∣ ∣ 2 ] ] [ [ L B ] ] = [ [ ∑ i ( ( u i B − y i ) 2 ) + λ 2 ∣ ∣ Θ B ∣ ∣ 2 ] ] [ [ L A B = 2 ∑ i ( [ [ u i A ] ] ( u i B − y i ) ) ] ] [ [ d i ] ] = [ [ u i A ] ] + [ [ u i B − y i ] ] \begin{aligned}[[L_A]]&=[[\sum_i(u_i^A)^2+\frac{\lambda}{2}||\Theta_A||^2]] \\ [[L_B]]&=[[\sum_i((u_i^B-y_i)^2)+\frac{\lambda}{2}||\Theta_B||^2]] \\ [[L_{AB}&=2\sum_i([[u_i^A]](u_i^B-y_i))]] \\ [[d_i]]&=[[u_i^A]]+[[u_i^B-y_i]]\end{aligned} [[LA]][[LB]][[LAB[[di]]=[[i∑(uiA)2+2l∣∣ΘA∣∣2]]=[[i∑((uiB−yi)2)+2l∣∣ΘB∣∣2]]=2i∑([[uiA]](uiB−yi))]]=[[uiA]]+[[uiB−yi]]则[ [ L ] ] = [ [ LA ] ] + [ [ LB ] ] + [ [ LAB ] ] [[L]]=[[L_A]]+[[L_B]]+[[L_{AB}]][[L]]=[[LA]]+[[LB]]+[[LAB]]
- 计算梯度: [ [ ∂ L ∂ Θ A ] ] = ∑ i [ [ d i ] ] x i A + [ [ λ Θ A ] ] [ [ ∂ L ∂ Θ B ] ] = ∑ i [ [ d i ] ] x i B + [ [ λ Θ B ] ] \begin{aligned}[[\frac{\partial L}{\partial\Theta_A}]]&=\sum_i[[d_i]]x_i^A+[[\lambda\Theta_A]]\\ [[\frac{\partial L}{\partial\Theta_B}]]&=\sum_i[[d_i]]x_i^B+[[\lambda\Theta_B]]\end{aligned} [[∂ΘA∂L]][[∂ΘB∂L]]=i∑[[di]]xiA+[[ λ ThA]]=i∑[[di]]xiB+[[ λ ThB]]
The data provider is AAA andBBB and the third party areCCC. The training steps of vertical federated learning are as follows:
\qquad\quad | The data provider is AAA | The data provider is BBB | The third party is CCC |
---|---|---|---|
Step 1 11 | Initialization parameter Θ A \Theta_AThA | Initialization parameter Θ B \Theta_BThB | Create an encryption key pair and send the public key to the data provider as AAA andBBB |
Step 2 22 | Calculation [ [ u IA ] ] [[u_I^A]][[uIA]] Sum[ [ LA ] ] [[L_A]][[LA]] and sent to data providerBBB | Calculation [ [ u IB ] ] [[u_I^B]][[uIB]]、 [ [ d i ] ] [[d_i]] [[di]] and[ [ L ] ] [[L]][[ L ]] and[ [ di ] ] [[d_i]][[di]] Sent to data providerAAA , will[[L]][[L]][[ L ]] Send to third partyCCC | |
Step 3 33 | Initialization mask RA R_ARA,计算 [ [ ∂ L ∂ Θ A ] ] + [ [ R A ] ] [[\frac{\partial L}{\partial\Theta_A}]]+[[R_A]] [[∂ΘA∂L]]+[[RA]] and send it to the third partyCCC | Initialization mask RB R_BRB,计算 [ [ ∂ L ∂ Θ B ] ] + [ [ R B ] ] [[\frac{\partial L}{\partial\Theta_B}]]+[[R_B]] [[∂ΘB∂L]]+[[RB]] and send it to the third partyCCC | Decrypt LLL并发送 ∂ L ∂ Θ A + R A \frac{\partial L}{\partial\Theta_A} + R_A ∂ΘA∂L+RATo data provider AAA,发送 ∂ L ∂ Θ B + R A \frac{\partial L}{\partial\Theta_B} + R_A ∂ΘB∂L+RATo data provider BBB |
Step 4 44 | Update parameters Θ A \Theta_AThA | Update parameters Θ B \Theta_BThB |
During the whole process, the participants do not know the data and characteristics of the other party, and after the training, the participants only get the model parameters of their own side, that is, the half model. Since each participant can only obtain the model parameters related to itself, prediction requires collaboration between both parties:
- Third party CCC sends the user ID to be predicted to the data providerAAA andBBB
- Data provider AAA andBBB minute calculationu A u^AuA和u B u^BuB and perform homomorphic encryption to obtain[ [ u A ] ] [[u^A]][[uA ]]Sum[ [ u B ] ] [[u^B]][[uB]]
- Data provider AAA andBBB homomorphically encrypted[ [ u A ] ] [[u^A]][[uA ]]Sum[ [ u B ] ] [[u^B]][[uB ]]sent to third partyCCC
- Third party CCC calculates the predicted value after homomorphic encryption[ [ y ] ] = [ [ u A ] ] + [ [ u B ] ] [[y]]=[[u^A]]+[[u^B]][[y]]=[[uA]]+[[uB ]]and then decrypt to get the predicted valueyyy
References:
[1] Yang Qiang, Liu Yang, Cheng Yong, Kang Yan, Chen Tianjian, Yu Han. Federated Learning [M]. Electronic Industry Press, 2020 [2] WeBank, FedAI. Federated Learning White Paper V2.0
. Tencent Research Institute, etc., 2021