- Rosetta User API
- Overview
- Control API
- Protocol Management
- Input and Dataset Utils
- Misc API
backend_log_to_stdout(flag: bool)
set_backend_logfile(logfile: str, task_id=None)
set_backend_logpattern(pattern: str)
set_backend_loglevel(loglevel: int)
set_backend_logpattern(pattern: str)
set_float_precision(float_precision: int, task_id=None)
set_saver_model(model_nodes: list, task_id=None)
set_restore_model(model_nodes: list, task_id=None)
get_float_precision(task_id=None)
- Operation API
- Terms and definition
- Common notes
- Computational SecureOps
SecureAdd(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureSub(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureMul(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureFloorDiv(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureDiv(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureDivide(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureTruediv(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureRealDiv(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureReciprocaldiv(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureEqual(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureGreater(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureGreaterEqual(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureLess(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureLessEqual(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureLogicalAnd(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureLogicalOr(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureLogicalXor(x, y, name=None, lh_is_const=False, rh_is_const=False)
SecureLogicalNot(x, name=None)
SecureMatMul(a, b, transpose_a=False, transpose_b=False, name=None)
SecurePow(x, y, name=None, lh_is_const=False, rh_is_const=True)
SecureExp(x, name=None)
SecureSqrt(x, name=None)
SecureRsqrt(x, name=None)
SecureLog(x, name=None)
SecureLog1p(x, name=None)
SecureHLog(x, name=None)
SecureSigmoid(x, name=None)
SecureRelu(x, name=None)
SecureReluPrime(x, name=None)
SecureAbs(x, name=None)
SecureAbsPrime(x, name=None)
SecureMax(input_tensor, axis=None, name=None)
SecureMin(input_tensor, axis=None, name=None)
SecureMean(input_tensor, axis=None, name=None)
SecureReveal(a, reveal_party=None)
- I/O SecureOps
By using Rosetta framework, users can directly perform training or inference task on all of their respective dataset without leaking any privacy to others just after adding a single code import latticex.rosetta
at the header of your existing TensorFlow programs (see our tutorial documentation for more details) in the simplest case. Besides, to make it flexible we also provide some easy-to-use APIs, which we will describe in the following context.
The APIs can mainly be classified into two types: 'Control API', which should be sufficient for most of your tasks, and 'Operation API', a set of TensorFlow-style Operators called SecureOps
. The first type provides you with the ability to control the context of backend cryptographic protocols, pre-process your datasets and so on. The second type is for advanced usage, and you can use them in the same way as the native tf.Operation
, where TensorFlow executes them with a stream of ciphertext flowing through them..
Moreover, since Rosetta v1.0.0
multi-threaded execution of multiple tasks has been adopted. The main changes are in 'Control API', as each running task is bind with a secure protocol instance, task_id
argument is added to those APIs to reference the specified task. In addition, we have carefully handled interface compatibility issues so that the code still works correctly with Rosetta v0.2.0
and newer versions.
Activate the protocol for the specific task to carry out your subsequent TensorFlow Operations.
It is highly recommended that you use this interface explicitly to choose your backend protocol before calling run
in the TensorFlow session.
Note: DO NOT call
activate
while your program is executing TensorFlow graph.
Args:
-
protocol_name
: Name of the protocol, which MUST be one of the supported protocols. If this parameter is not provided, the default protocol will be used. -
protocol_config_str
: The config JSON string that is compatible with your protocol. [deprecated sincev1.0.0
] -
task_id
: ID of the task.
Deactivate backend protocol for the specific task.
All the resources related, such as the network connections and local cache, will be released.
Args:
task_id
: ID of the task.
Note: DO NOT call
deactivate
while your program is executing TensorFlow graph.
Get list of all the backend cryptographic protocols.
You can activate one of the protocols as your backend Ops.
If you are a protocol developer, you can implement and register your own protocols in the backend, and you will see and use them here just as the native ones.
Returns:
The list of the names of the supported secure protocols.
Get the name of the default protocol that will be used if none is set.
Get the protocol name for the specific task.
Get your party id of for specific task (0, 1, 2 for party P0
, P1
, P2
respectively).
Args:
task_id
: ID of the task.
One party set its private input value to be shared among multi-parties.
Args:
-
node_id
: Node ID, Indicates which node'sinput_value
will be shared. -
input_value
: Local input values. ONLY the inputs of the node that has the same node id as thenode_id
will be processed. -
task_id
: ID of the task.
Returns:
The local shared part, ciphertext, of the real value. Note that each party will has different cipher value that returned.
Just the same as private_input while the values will be fetched from console.
Args:
-
node_id
: Node ID, indicates which node'sinput_value
will be shared. -
task_id
: ID of the task.
Returns:
The local shared part, ciphertext, of the real value. Note that each party will has different cipher value that returned.
A wrapper class for multiparty to align and 'encrypt' or 'share' its private dataset from a local CSV file or ndarray
target of numpy.
Every party's dataset should be either sample-aligned or feature-aligned already.
When instantiation, for example, if dataset_type == DatasetType.SampleAligned (default dataset_type is SampleAligned),
assuming node P0
, node P1
owns private data, P1
owns label, then all the parties do respectively:
# get private data from its own data source, set None if no private data
XX, YY = ...
X, Y = PrivateDataset(data_owner=("P0","P1"), label_owner=1).load_data(XX, YY)
Otherwise, if dataset_type == DatasetType.FeatureAligned, label_owner is useless.
For example, assuming P0
, P1
owns private data and label, then all the parties do respectively:
# get private data from its own data source, set None if no private data
XX, YY = ...
X,y = PrivateDataset(data_owner=("P0","P1"),
dataset_type=DatasetType.FeatureAligned).load_data(XX, YY)
-
load_X(self, x: str or np.ndarray or None, task_id : str="", *args, **kwargs)
Load and 'secret-shared' private ATTRIBUTE values from local dataset files or
ndarray
object ofnumpy
for task with IDtask_id
.For example, if dataset shape of P0 is N * d0, dataset shape of P1 is N * d1, and P2 has no data at all. Then the resulting 'ciphertext' local dataset returned for each party is of the shape N * (d0 + d1).
Return: The shared 'ciphertext' local dataset, and its datatype is string with format specific to your current activated protocol.
-
load_Y(self, y: str or np.ndarray or None, task_id : str="", *args, **kwargs)
Load and 'secret-shared' private LABEL values from local dataset files or
ndarray
object ofnumpy
for task with IDtask_id
.Only the input file of 'label_owner'-party will be processed. Return: The shared 'ciphertext' local label dataset, and its datatype is string with format specific to your current activated protocol.
-
load_XY(self, X: str or np.ndarray or None, y: str or np.ndarray or None, task_id : str="", *args, **kwargs)
The combination of the above two functions (
load_X
,load_Y
).
Private text line dataset, either for one or multiple file inputs.
It is used in the same way as TextLineDataset, but has one more parameter data_owner
than TextLineDataset, which represents which party holds the private data.
For example, assuming node with ID P0
owns private data, it instantiates like this:
file_x = ...
dataset_x0 = rtt.PrivateTextLineDataset(
file_x, data_owner='P0') # P0 hold the file data
For example, assuming node with ID P1
owns private data, it instantiates like this:
file_x = ...
dataset_x1 = rtt.PrivateTextLineDataset(
file_x, data_owner='P1') # P1 hold the file data
Enable or disable backend log output to stdout.
Set backend log output file path.
Args:
task_id
: ID of the task.
Set backend log file path.
Args:
task_id
: ID of the task.
Set backend log output level.
Args:
loglevel
: Log level, valid values are as follows:- 0: Trace(All log)
- 1: Debug
- 2: Audit
- 3: Info
- 4: Warn
- 5: Error
- 6: Fatal
- 7: Disable
Set backend log output pattern.
Args:
pattern
:spdlog
log pattern, Rosetta's logger implementation isspdlog
, default pattern is%Y-%m-%d %H:%M:%S.%e|%l|%v
, which indicates that the log output mode is: "year-month-day hour:minute:second.milliseconds|log level|log text|". For more detail refer to: spdlog-pattern.
Set floating point precision.
Args:
-
float_precision
: Number of floating point precision bits in fixed point representation, with default value 13. -
task_id
: ID of the task.
Specify which nodes act as model savers.
Args:
-
model_nodes
: Model saver nodes. -
task_id
: ID of the task.
Set nodes to restore model.
Args:
-
model_nodes
: Nodes to restore model. -
task_id
: ID of the task.
Get floating point precision.
Args:
task_id
: ID of the task.
Returns:
Floating point precision for task with task_id
.
The main magic component that supports these upper-level conveniences is our implementation of a new suites of privacy-preserving-enabled secure Operation
based on TensorFlow's flexible extension mechanism for introducing new operation library. To distinguish it from the native TensorFlow API Operation (hereinafter referred to directly as Ops
), we refer to these customized Operation as SecureOps
.
Here we describe how to use the various SecureOps
interfaces supported in the Rosetta
. Most of interface signature of these SecureOps
is consistent with the corresponding Ops
' in TensorFlow, and only in a few cases have we extended the native one with more MPC-related functionality (e.g., the SaveV2
operation, etc.).
If you need to build your own specific privacy protection model based on Rosetta's underlying API, or are interested in our extending our SecureOps
set, this is the right place you should start with. In addition, unit tests in the source code can also help you to understand the usage of the various SecureOps
.
We will try to represent each SecureOp
interface in an clear and easy-to-understand way as far as we can. Occasionally, we will use some cryptographic terms for concision, which you can refer to glossary document for their definition if you are not sure.
-
Unlike the input and output
Tensor
ofOps
in native TensorFlow, the parameters and return values ofSecureOps
are considered to be a shared value in a secret state, unless an explicit declaration is made that an input value is an explicit constant (see the relatedSecureOps
interface declaration below). You may not use these 'garbled' values directly. -
On data type (
dtype
) ofSecureOps
input and outputTensor
, Rosetta's Python frontend will uniformly convert them as `tf.string' in the current version. -
For binary operators such as
SecureAdd
, The currentRosetta v1.0.0
supportsTensor
s of dimension up to 5, while for unary input operators such asSecureRelu
the tensor shape is unrestricted (note:Rosetta v0.2.0
does not supportTensor
s of dimension more than 2).
Returns x + y
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE: broadcasting is supported for this SecureOp.
Returns x - y
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE: broadcasting is supported for this SecureOp.
Returns x * y
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE: Broadcasting is supported for this SecureOp.
Integral floor division of x
by y
in shared status element-wise, rounding toward the most negative integer. For example, 6 / 4 = 1 and (-6) / 4 = -2.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE: broadcasting is supported for this SecureOp.
Alias for SecureFloorDiv
. Please refer to SecureFloorDiv
. we recommend you to use SecureFloorDiv
as you can.
Computes Python style division of x
by y
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
- broadcasting is supported for this SecureOp.
- due to its intrinsic algorithm complexity in MPC style to meet the security guarantee, this SecureOp is comparatively much more time-consuming. So you may aviod to use this SecureOp as possible as you can.
- this SecureOp is just the same as
SecureRealDiv
andSecureTrueDiv
.
Alias for SecureDivide
. Please refer to SecureDivide
.
Alias for SecureDivide
. Please refer to SecureDivide
.
On the whole, we need to calculate the reciprocal of the denominator to achieve division, and then calculate the reciprocal of the denominator times the numerator to get the quotient.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
: flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
The denominator can not be too large(smaller than 10000 at best), otherwise the process will be overflow or influence the precision.
Normally,the precision of output can get close to 1e-4.
This SecureOp is just the same as
SecureRealDiv
andSecureTrueDiv
, but in fact, the reciprocaldiv algorithm is 5 times faster than theSecureTrueDiv
.
Returns the truth value of (x == y)
element-wise, as 0.0
for false and 1.0
for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
-
broadcasting is supported for this SecureOp.
-
The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (x > y)
element-wise, as 0.0
for false and 1.0
for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
broadcasting is supported for this SecureOp. The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (x >= y)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
broadcasting is supported for this SecureOp. The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause of your source code directly.
Returns the truth value of (x < y)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
Broadcasting is supported for this SecureOp.
The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (x <= y)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
Broadcasting is supported for this SecureOp. The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (x & y)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
Broadcasting is supported for this SecureOp.
The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (x | y)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
Broadcasting is supported for this SecureOp.
The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (x ^ y)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow, whose values are in shared status. . Must have the same type asx
.name(optional)
: A name for the operation, the default value of it is None.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isFalse
.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
Broadcasting is supported for this SecureOp.
The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Returns the truth value of (!x)
element-wise, as 0 for false and 1 for true.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
The output values are still in the shared status, just like other
SecureOps
. So in the current version, you should not use the local outputTensor
in any following predicate clause directly.
Multiplies matrix a
by matrix b
, producing a
* b
.
Args:
-
a
: ATensor
in TensorFlow, whose values are in shared status. -
b
: ATensor
in TensorFlow, whose values are in shared status. Must be logically compatible witha
. -
name(optional)
: A name for the operation (optional). -
transpose_a(optional)
: IfTrue
,a
is transposed before multiplication. Its default value isFalse
. -
transpose_b(optional)
: IfTrue
,b
is transposed before multiplication.Its default value isFalse
.
Returns:
A Tensor
. each value in it is the inner product of the corresponding vector in a
and b
.
NOTE:
Just like other binary
SecureOps
, in the current version, only at most 2-dimension inputTensor
is supported.
Returns
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.y
: ATensor
in TensorFlow. In the current version, every value must be a constant plaintext integer, and all parties must have the same value. Besides,y
should have the same shape asx
.lh_is_const(optional)
: flag indicating whether thex
is a const number. If it is set as True, thex
will be added just as the sum of all parties' shared input pieces. The default value isFalse
.rh_is_const(optional)
:flag indicating whether they
is a const number. If it is set as True, they
will be added just as the sum of all parties' shared input pieces.The default value isTrue
. In the current version, onlyTrue
is supported. In the future version, we will support it to beFalse
name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
Computes e^x of x
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
The current accuracy of the operator is 0.1 ~ 0.01, we will optimize it in the next version.
Computes x^(0.5) of x
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
Computes 1/(x^(0.5)) of x
element-wise by using Newton Raphson method.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
The initial value of the Newton Raphson method is computed according to
Algorithm 5
andAlgorithm 7
in the paperFalcon: Honest-Majority Maliciously Secure Framework for Private Deep Learning
.
Computes natural logarithm of x
element-wise. This is optimized version for x
.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
The inner implementation of this
SecureLog
is optimized for efficiency by polynomial interpolation. for$x \in [0.0001, 10]$ , which are often used in machine learning tasks. And its average absolute error is less than 0.01. The detailed segmental polynomials we use is: $$ln(x)=\begin{cases} 85873.96716x^3 -8360.491679x^2 + 284.0022382x -6.805568387& x \in (0.0001, 0.05) \ 3.404663323 * x^3 -8.668159044x^2 + 8.253302766x -3.0312942 & x \in [0.05, 1.2) \ -0.022636005x^2+0.463403306*x-0.147409486 & x \in [1.2, 10.0) \end{cases}$$
If your want to use the general and high-precision mathematical natural logarithm, you should use
SecureHLog
.
Computes natural logarithm of x+1
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE: The inner implementation of this SecureLog1p
is based on SecureLog
, you may refer to SecureLog
for more information.
Computes natural logarithm of x
element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE: This is for computing general and high-precision mathematical natural logarithm for all SecureOp
is much more time-consuming, so avoid to use this as you can.
Computes the sigmoid function, which means
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
NOTE:
The inner implementation of this
SecureSigmoid
is optimized for efficiency by using polynomial interpolation. The piecewise linear polynomials we use is as follows: $$sigmoid(x)=\begin{cases} 0 & x \in (-\infty,-4] \ 0.0484792 * x + 0.1998976 & x \in [-4, -2) \ 0.1928931 * x + 0.4761351 & x \in [-2, 0) \ 0.1928931 * x + 0.5238649 & x \in [0, 2) \ 0.0484792 * x + 0.8001024 & x \in [2,4) \ 1 & x \in [4, \infty) \end{cases}$$ .
Computes rectified linear functionality, which means max(x, 0) element-wise.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
Computes derivation of rectified linear functionality, which means
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
Computes absolute value of each value in x
.
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
Computes derivation of absolute value of each value in x
, which means
Args:
x
: ATensor
in TensorFlow, whose values are in shared status.name(optional)
: A name for the operation, the default value of it is None.
Returns:
A Tensor
. Has the same type as x
.
Computes the maximum of elements across dimensions of a tensor. Reduces input_tensor
along the dimensions given in axis
.
If axis
is None, all dimensions are reduced, and a tensor with a single element is returned.
Args:
-
input_tensor
: The tensor to reduce. -
axis(optional)
: The dimensions to reduce. IfNone
(the default), reduces all dimensions. In the current version it must be 0, 1 or None. -
name(optional)
: A name for the operation (optional).
Returns:
The reduced Tensor
with max outputs.
Note:
From v1.0.0 or newer version, Rosetta supports up to 5-demension input
Tensor
, while for v0.2.0 or older version, only 2-dimension inputTensor
is supported.
Computes the minimum of elements across dimensions of a tensor. Reduces input_tensor
along the dimensions given in axis
.
If axis
is None, all dimensions are reduced, and a tensor with a single element is returned.
Args:
-
input_tensor
: The tensor to reduce. -
axis(optional)
: The dimensions to reduce. IfNone
(the default), reduces all dimensions. In the current version it must be 0, 1 or None. -
name(optional)
: A name for the operation (optional).
Returns:
The reduced Tensor
with minimum outputs.
Note:
From v1.0.0 or newer version, Rosetta supports up to 5-demension input
Tensor
, while for v0.2.0 or older version, only 2-dimension inputTensor
is supported.
Computes the mean of elements across dimensions of a tensor.
Reduces input_tensor
along the dimensions given in axis
.
If axis
is None, all dimensions are reduced, and a tensor with a single element is returned.
Args:
input_tensor
: The tensor to reduce.axis(optional)
: The dimensions to reduce. IfNone
(the default), reduces all dimensions. In the current version it must be 0, 1 or None.name(optional)
: A name for the operation (optional).
Returns:
The reduced Tensor
with min ouputs.
Note:
From v1.0.0 or newer version, Rosetta supports up to 5-demension input
Tensor
, while for v0.2.0 or older version, only 2-dimension inputTensor
is supported.
This auxiliary SecureOp
can reveal the plaintext value of the Tensor
a
. Since the output of this interface can be plaintext, be cautious and reach a consensus among all the parties when using this in production environment.
Args:
a
: ATensor
in TensorFlow, whose values are in shared status.reveal_party(optional)
: Configure result nodes who will get the plaintext output, recommand parameter value is result nodes list. By default, it is set to None, meaning that all result nodes will get the plaintext output values.
Returns:
A tensor
, of which values can be in plaintext as configured.
This is the underlying Operation to save tensors in V2 checkpoint format. In native TensorFlow, its corresponding operation, save_v2
, which has the identical interface signature, is also wrapped by the tf.train.Saver()
interface, rather than being called directly. Unlike the native Saver
, this SecureOp
can save the plaintext tensors in files only in specific parties by configuration. In Rosetta, by default, you have no need to use this SecureOp
neither, because our Static Pass
functionality (see its definition in glossary) can help you perform the correct replacement intrinsically.
The configurational option in Rosetta v0.2.0
is the SAVER_MODE
keyword in CONFIG.json
. Its value os parsed as a 3-bit Flag for
-
$0$ : every party saved the local shared value, rather than plaintext value. This is the default action. -
$1$ : the saved plaintext file will be stored in partyP0
. -
$2$ : the saved plaintext file will be stored in partyP1
. -
$3$ : the saved plaintext file will be stored both in partyP0
andP1
. -
$4$ : the saved plaintext file will be stored in partyP2
. -
$5$ : the saved plaintext file will be stored both in partyP0
andP2
. -
$6$ : the saved plaintext file will be stored both in partyP1
andP2
. -
$7$ : the saved plaintext file will be stored in all parties, i.eP0
,P1
andP2
.
Args:
-
prefix
: ATensor
of typestring
. Must have a single element. The prefix of the V2 checkpoint to which we write the tensors. -
tensor_name
: ATensor
of typestring
. shape${N}$ . The names of the tensors to be saved. -
shape_and_slices
: ATensor
of typestring
. shape${N}$ . The slice specs of the tensors to be saved. Empty strings indicate that they are non-partitioned tensors. -
tensors
:A list ofTensor
objects, which are in shared status.$N$ tensors to save. -
name
: A name for the operation (optional).
Returns:
The created Operation.
NOTE: Every party must have the same configured value so that the system call perform the correct actions. This Configuration is important due to its output values, which may be sensitive, are in plaintext . So be cautious and reach a consensus among all the parties.
Define a private input,this represents a private
input owned by the specified player into the graph.
Args:
x
: The data from data owner, supported data types: int32, int64, float, double, string.data_owner
: The private data owner which is data node id (string type). For compatibility with older versions(earlier thanv1.0.0
),data_owner
= 0 means computation node partyP0
hold the data, data_owner = 1 means computation node partyP1
hold the data, data_owner = 2 means computation node partyP2
hold the data.name
: A name for the operation (optional).
Return value:
A Tensor
, of type string and the same shape as x
.
Note:
The load data of the return value is encrypted or shared.