syft.serde.msgpack.torch_serde

This file exists to provide one common place for all serialisation and simplify_ and _detail for all tensors (Torch and Numpy).

Module Contents

syft.serde.msgpack.torch_serde._serialize_tensor(worker: AbstractWorker, tensor) → bin

Serialize the tensor using as default Torch serialization strategy This function can be overridden to provide different tensor serialization strategies

Args

(torch.Tensor): an input tensor to be serialized

Returns

A serialized version of the input tensor

syft.serde.msgpack.torch_serde._deserialize_tensor(worker: AbstractWorker, serializer: str, tensor_bin) → torch.Tensor

Deserialize the input tensor passed as parameter into a Torch tensor. serializer parameter selects different deserialization strategies

Args

worker: Worker serializer: Strategy used for tensor deserialization (e.g.: torch, numpy, all) tensor_bin: A simplified representation of a tensor

Returns

a Torch tensor

syft.serde.msgpack.torch_serde.simplified_tensor_serializer(worker: AbstractWorker, tensor: torch.Tensor) → tuple

Strategy to serialize a tensor to native python types. If tensor requires to calculate gradients, it will be detached.

syft.serde.msgpack.torch_serde.simplified_tensor_deserializer(worker: AbstractWorker, tensor_tuple: tuple) → torch.Tensor

“Strategy to deserialize a simplified tensor into a Torch tensor

syft.serde.msgpack.torch_serde._simplify_torch_tensor(worker: AbstractWorker, tensor: torch.Tensor) → bin

This function converts a torch tensor into a serliaized torch tensor using pickle. We choose to use this because PyTorch has a custom and very fast PyTorch pickler.

Parameters

tensor (torch.Tensor) – an input tensor to be serialized

Returns

serialized tuple of torch tensor. The first value is the id of the tensor and the second is the binary for the PyTorch object. The third is the chain of abstractions, and the fourth (optinally) is the chain of graident tensors (nested tuple)

Return type

tuple

syft.serde.msgpack.torch_serde._detail_torch_tensor(worker: AbstractWorker, tensor_tuple: tuple) → torch.Tensor

This function converts a serialized torch tensor into a torch tensor using pickle.

Parameters

tensor_tuple (bin) – serialized obj of torch tensor. It’s a tuple where the first value is the ID, the second vlaue is the binary for the PyTorch object, the third value is the chain of tensor abstractions, and the fourth object is the chain of gradients (.grad.grad, etc.)

Returns

a torch tensor that was serialized

Return type

torch.Tensor

syft.serde.msgpack.torch_serde._simplify_torch_parameter(worker: AbstractWorker, param: torch.nn.Parameter) → bin

This function converts a torch Parameter into a serialized torch Parameter

Parameters

param (torch.nn.Parameter) – an input Parameter to be serialized

Returns

serialized tuple of torch Parameter. The first value is the id of the Parameter and the second is the binary for the PyTorch tensor data attribute and last is the requires_grad attr.

Return type

tuple

syft.serde.msgpack.torch_serde._detail_torch_parameter(worker: AbstractWorker, param_tuple: tuple) → torch.nn.Parameter

This function converts a serialized torch Parameter into a torch Parameter.

Parameters

param_tuple (tuple) – serialized obj of torch tensor. It’s a tuple where the first value is the ID and the second value is the binary for the PyTorch data attribute et and third value is the requires_grad attr.

Returns

a torch Parameter that was serialized

Return type

torch.Parameter

syft.serde.msgpack.torch_serde._simplify_torch_device(worker: AbstractWorker, device: torch.device) → Tuple
syft.serde.msgpack.torch_serde._detail_torch_device(worker: AbstractWorker, device_type: tuple) → torch.device
syft.serde.msgpack.torch_serde._simplify_script_module(worker: AbstractWorker, obj: torch.jit.ScriptModule) → Tuple

Strategy to serialize a script module using Torch.jit

syft.serde.msgpack.torch_serde._detail_script_module(worker: AbstractWorker, script_module_bin: Tuple) → torch.jit.ScriptModule

“Strategy to deserialize a binary input using Torch load

syft.serde.msgpack.torch_serde._simplify_torch_size(worker: AbstractWorker, size: torch.Size) → Tuple[int]
syft.serde.msgpack.torch_serde._detail_torch_size(worker: AbstractWorker, size: Tuple[int]) → torch.Size
syft.serde.msgpack.torch_serde._simplify_torch_mem_format(worker: AbstractWorker, mem_format: torch.memory_format) → int
syft.serde.msgpack.torch_serde._detail_torch_mem_format(worker: AbstractWorker, mem_format: int) → torch.memory_format
syft.serde.msgpack.torch_serde.MAP_TORCH_SIMPLIFIERS_AND_DETAILERS