syft.frameworks.torch.mpc.securenn¶
This is an implementation of the SecureNN paper https://eprint.iacr.org/2018/442.pdf
Note that there is a difference here in that our shares can be negative numbers while they are always positive in the paper
Module Contents¶
-
syft.frameworks.torch.mpc.securenn.p= 67¶
-
syft.frameworks.torch.mpc.securenn.Q_BITS= 62¶
-
syft.frameworks.torch.mpc.securenn.no_wrap¶
-
syft.frameworks.torch.mpc.securenn.decompose(tensor)¶ decompose a tensor into its binary representation.
-
syft.frameworks.torch.mpc.securenn.flip(x, dim)¶ Reverse the order of the elements in a tensor
-
syft.frameworks.torch.mpc.securenn._random_common_bit(*workers)¶ Return a bit chosen by a worker and sent to all workers, in the form of a MultiPointerTensor
-
syft.frameworks.torch.mpc.securenn._random_common_value(max_value, *workers)¶ Return n in [0, max_value-1] chosen by a worker and sent to all workers, in the form of a MultiPointerTensor
Return n in [0, max_value-1] chosen by a worker and sent to all workers, in the form of a MultiPointerTensor
Performs select share protocol If the bit alpha_sh is 0, x_sh is returned If the bit alpha_sh is 1, y_sh is returned
- Parameters
x_sh (AdditiveSharingTensor) – the first share to select
y_sh (AdditiveSharingTensor) – the second share to select
alpha_sh (AdditiveSharingTensor) – the bit to choose between x_sh and y_sh
- Returns
z_sh = (1 - alpha_sh) * x_sh + alpha_sh * y_sh
-
syft.frameworks.torch.mpc.securenn.private_compare(x_bit_sh, r, beta)¶ Perform privately x > r
- Parameters
x (AdditiveSharedTensor) – the private tensor
r (MultiPointerTensor) – the threshold commonly held by alice and bob
beta (MultiPointerTensor) – a boolean commonly held by alice and bob to hide the result of computation for the crypto provider
- Returns
β′ = β ⊕ (x > r).
-
syft.frameworks.torch.mpc.securenn.msb(a_sh)¶ Compute the most significant bit in a_sh, this is an implementation of the SecureNN paper https://eprint.iacr.org/2018/442.pdf
- Parameters
a_sh (AdditiveSharingTensor) – the tensor of study
- Returns
the most significant bit
Convert shares of a in field L to shares of a in field L - 1
- Parameters
a_sh (AdditiveSharingTensor) – the additive sharing tensor who owns the shares in field L to convert
- Returns
An additive sharing tensor with shares in field L-1
-
syft.frameworks.torch.mpc.securenn.relu_deriv(a_sh)¶ Compute the derivative of Relu
- Parameters
a_sh (AdditiveSharingTensor) – the private tensor on which the op applies
- Returns
0 if Dec(a_sh) < 0 1 if Dec(a_sh) > 0 encrypted in an AdditiveSharingTensor
-
syft.frameworks.torch.mpc.securenn.relu(a_sh)¶ Compute Relu
- Parameters
a_sh (AdditiveSharingTensor) – the private tensor on which the op applies
- Returns
Dec(a_sh) > 0 encrypted in an AdditiveSharingTensor
-
syft.frameworks.torch.mpc.securenn.division(x_sh, y_sh, bit_len_max=Q_BITS // 2)¶ Performs division of encrypted numbers
- Parameters
y_sh (x_sh,) – the private tensors on which the op applies
bit_len_max – the number of bits needed to represent the highest value in the tensors we may want to avoid giving this value so Q_BITS is the default value
- Returns
element-wise integer division of x_sh by y_sh
-
syft.frameworks.torch.mpc.securenn.maxpool(x_sh)¶ Compute MaxPool: returns fresh shares of the max value in the input tensor and the index of this value in the flattened tensor
- Parameters
x_sh (AdditiveSharingTensor) – the private tensor on which the op applies
- Returns
maximum value as an AdditiveSharingTensor index of this value in the flattened tensor as an AdditiveSharingTensor
-
syft.frameworks.torch.mpc.securenn.maxpool_deriv(x_sh)¶ Compute derivative of MaxPool
- Parameters
x_sh (AdditiveSharingTensor) – the private tensor on which the op applies
- Returns
an AdditiveSharingTensor of the same shape as x_sh full of zeros except for a 1 at the position of the max value
-
syft.frameworks.torch.mpc.securenn.maxpool2d(a_sh, kernel_size: int = 1, stride: int = 1, padding: int = 0)¶ Applies a 2D max pooling over an input signal composed of several input planes. This interface is similar to torch.nn.MaxPool2D. :param kernel_size: the size of the window to take a max over :param stride: the stride of the window :param padding: implicit zero padding to be added on both sides