(self, guest_components, data_loader: FTLDataLoader, epoch_idx, local_round=-1)
compute host bottom model gradients
compute host bottom model gradients
compute host bottom model gradients
def compute_backward_gradients(self, guest_components, data_loader: FTLDataLoader, epoch_idx, local_round=-1):

        """
        compute host bottom model gradients
        """

        y_overlap_2_phi_2, y_overlap_phi, mapping_comp_a = guest_components[0], guest_components[1], guest_components[2]

        ub_overlap_ex = np.expand_dims(self.overlap_ub, axis=1)

        if self.mode == 'plain':

            ub_overlap_y_overlap_2_phi_2 = np.matmul(ub_overlap_ex, y_overlap_2_phi_2)
            l1_grad_b = np.squeeze(ub_overlap_y_overlap_2_phi_2, axis=1) + y_overlap_phi
            loss_grad_b = self.alpha * l1_grad_b + mapping_comp_a

            return loss_grad_b

        if self.mode == 'encrypted':

            ub_overlap_ex = np.expand_dims(self.overlap_ub, axis=1)
            ub_overlap_y_overlap_2_phi_2 = y_overlap_2_phi_2.matmul_3d(ub_overlap_ex, multiply='right')
            ub_overlap_y_overlap_2_phi_2 = ub_overlap_y_overlap_2_phi_2.squeeze(axis=1)

            l1_grad_b = ub_overlap_y_overlap_2_phi_2 + y_overlap_phi
            en_loss_grad_b = l1_grad_b * self.alpha + mapping_comp_a

            self.decrypt_guest_data(epoch_idx, local_round=local_round)
            loss_grad_b = self.decrypt_inter_result(en_loss_grad_b, epoch_idx, local_round=local_round)

            return loss_grad_b.numpy()
def compute_backward_gradients ( self , guest_components , data_loader : FTLDataLoader , epoch_idx , local_round = - 1 ) : y_overlap_2_phi_2 , y_overlap_phi , mapping_comp_a = guest_components [ 0 ] , guest_components [ 1 ] , guest_components [ 2 ] ub_overlap_ex = np . expand_dims ( self . overlap_ub , axis = 1 ) if self . mode == 'plain' : ub_overlap_y_overlap_2_phi_2 = np . matmul ( ub_overlap_ex , y_overlap_2_phi_2 ) l1_grad_b = np . squeeze ( ub_overlap_y_overlap_2_phi_2 , axis = 1 ) + y_overlap_phi loss_grad_b = self . alpha * l1_grad_b + mapping_comp_a return loss_grad_b if self . mode == 'encrypted' : ub_overlap_ex = np . expand_dims ( self . overlap_ub , axis = 1 ) ub_overlap_y_overlap_2_phi_2 = y_overlap_2_phi_2 . matmul_3d ( ub_overlap_ex , multiply = 'right' ) ub_overlap_y_overlap_2_phi_2 = ub_overlap_y_overlap_2_phi_2 . squeeze ( axis = 1 ) l1_grad_b = ub_overlap_y_overlap_2_phi_2 + y_overlap_phi en_loss_grad_b = l1_grad_b * self . alpha + mapping_comp_a self . decrypt_guest_data ( epoch_idx , local_round = local_round ) loss_grad_b = self . decrypt_inter_result ( en_loss_grad_b , epoch_idx , local_round = local_round ) return loss_grad_b . numpy ( )