syft.generic.object¶
Module Contents¶
-
class
syft.generic.object.AbstractObject(id: int = None, owner: sy.workers.AbstractWorker = None, tags: List[str] = None, description: str = None, child=None)¶ Bases:
abc.ABCThis is a generic object abstraction.
-
is_wrapper= False¶
-
__str__(self)¶
-
__repr__(self)¶
-
describe(self, description: str)¶
-
tag(self, *_tags: str)¶
-
serialize(self)¶ Serializes the tensor on which it’s called.
This is the high level convenience function for serializing torch tensors. It includes three steps, Simplify, Serialize, and Compress as described in serde.py. By default serde is compressing using LZ4
- Returns
The serialized form of the tensor. For example:
x = torch.Tensor([1,2,3,4,5]) x.serialize() # returns a serialized object
-
ser(self, *args, **kwargs)¶
-
get(self)¶ Just a pass through. This is most commonly used when calling .get() on a Syft tensor which has a child which is a pointer, an additive shared tensor, a multi-pointer, etc.
-
mid_get(self)¶ This method calls .get() on a child pointer and correctly registers the results
-
get_class_attributes(self)¶ Return all elements which defines an instance of a certain class. By default there is nothing so we return an empty dict, but for example for fixed precision tensor, the fractional precision is very important.
-
classmethod
on_function_call(cls, *args)¶ Override this to perform a specific action for each call of a torch function with arguments containing syft tensors of the class doing the overloading
-
classmethod
handle_func_command(cls, command)¶ Receive an instruction for a function to be applied on a Syft Tensor, Replace in the args all the LogTensors with their child attribute, forward the command instruction to the handle_function_command of the type of the child attributes, get the response and replace a Syft Tensor on top of all tensors found in the response.
- Parameters
command – instruction of a function command: (command name,
self>, arguments[, kwargs]) (<no) –
- Returns
the response of the function command
-
classmethod
rgetattr(cls, obj, attr, *args)¶ Get an attribute recursively.
This is a core piece of functionality for the PySyft tensor chain.
- Parameters
obj – the object holding the attribute
attr – nested attribute
args – optional arguments to provide
- Returns
the attribute obj.attr
Example
>>> rgetattr(obj, 'attr1.attr2.attr3') [Out] obj.attr1.attr2.attr3
-
-
syft.generic.object.initialize_object(hook, obj, owner=None, reinitialize=True, id=None, init_args=tuple(), init_kwargs={})¶ Initializes the tensor.
- Parameters
hook – A reference to TorchHook class.
obj – An object to keep track of id, owner and whether it is a native tensor or a wrapper over pytorch.
reinitialize – A boolean parameter (default True) to indicate whether to re-execute __init__.
owner – The owner of the tensor being initialised, leave it blank to if you have already provided a reference to TorchHook class.
id – The id of tensor, a random id will be generated if there is no id specified.
-
syft.generic.object._apply_args(hook, obj_to_register, owner=None, id=None)¶