def detail(worker: AbstractWorker, ptr_tuble: tuple) -> "PointerDataset": obj_id, id_at_location, worker_id, tags, description, garbage_collect_data = ptr_tuble obj_id = sy.serde.msgpack.serde._detail(worker, obj_id) id_at_location = sy.serde.msgpack.serde._detail(worker, id_at_location) worker_id = sy.serde.msgpack.serde._detail(worker, worker_id) tags = sy.serde.msgpack.serde._detail(worker, tags) description = sy.serde.msgpack.serde._detail(worker, description) # If the pointer received is pointing at the current worker, we load the dataset instead if worker_id == worker.id: dataset = worker.get_obj(id_at_location) return dataset # Else we keep the same Pointer else: location = sy.hook.local_worker.get_worker(worker_id) ptr = PointerDataset( location=location, id_at_location=id_at_location, owner=worker, tags=tags, description=description, garbage_collect_data=garbage_collect_data, id=obj_id, ) return ptr
def detail(worker: AbstractWorker, tensor_tuple: tuple) -> "PointerPlan": # TODO: fix comment for this and simplifier obj_id, id_at_location, worker_id, garbage_collect_data = tensor_tuple obj_id = sy.serde.msgpack.serde._detail(worker, obj_id) id_at_location = sy.serde.msgpack.serde._detail(worker, id_at_location) worker_id = sy.serde.msgpack.serde._detail(worker, worker_id) # If the pointer received is pointing at the current worker, we load the tensor instead if worker_id == worker.id: plan = worker.get_obj(id_at_location) return plan # Else we keep the same Pointer else: location = sy.hook.local_worker.get_worker(worker_id) ptr = PointerPlan( location=location, id_at_location=id_at_location, owner=worker, garbage_collect_data=garbage_collect_data, id=obj_id, ) return ptr
def detail(worker: AbstractWorker, tensor_tuple: tuple) -> "PointerTensor": """ This function reconstructs a PointerTensor given it's attributes in form of a dictionary. We use the spread operator to pass the dict data as arguments to the init method of PointerTensor Args: worker: the worker doing the deserialization tensor_tuple: a tuple holding the attributes of the PointerTensor Returns: PointerTensor: a PointerTensor Examples: ptr = detail(data) """ # TODO: fix comment for this and simplifier obj_id, id_at_location, worker_id, point_to_attr, shape, garbage_collect_data = tensor_tuple if isinstance(worker_id, bytes): worker_id = worker_id.decode() if shape is not None: shape = syft.hook.create_shape(syft.serde._detail(worker, shape)) # If the pointer received is pointing at the current worker, we load the tensor instead if worker_id == worker.id: tensor = worker.get_obj(id_at_location) if point_to_attr is not None and tensor is not None: point_to_attrs = point_to_attr.decode("utf-8").split(".") for attr in point_to_attrs: if len(attr) > 0: tensor = getattr(tensor, attr) if tensor is not None: if not tensor.is_wrapper and not isinstance(tensor, FrameworkTensor): # if the tensor is a wrapper then it doesn't need to be wrapped # i the tensor isn't a wrapper, BUT it's just a plain torch tensor, # then it doesn't need to be wrapped. # if the tensor is not a wrapper BUT it's also not a torch tensor, # then it needs to be wrapped or else it won't be able to be used # by other interfaces tensor = tensor.wrap() return tensor # Else we keep the same Pointer else: location = syft.hook.local_worker.get_worker(worker_id) ptr = PointerTensor( location=location, id_at_location=id_at_location, owner=worker, id=obj_id, shape=shape, garbage_collect_data=garbage_collect_data, ) return ptr
def detail(worker: AbstractWorker, protocol_tuple: tuple) -> "Protocol": """This function reconstructs a Protocol object given its attributes in the form of a tuple. Args: worker: the worker doing the deserialization protocol_tuple: a tuple holding the attributes of the Protocol Returns: protocol: a Protocol object """ id, tags, description, plans_reference, workers_resolved = map( lambda o: sy.serde._detail(worker, o), protocol_tuple ) plans = [] for owner_id, plan_id in plans_reference: if workers_resolved: plan_owner = worker.get_worker(owner_id, fail_hard=True) plan_pointer = worker.request_search(plan_id, location=plan_owner)[0] worker.register_obj(plan_pointer) plans.append((plan_owner, plan_pointer)) else: try: plan_owner = worker.get_worker(owner_id, fail_hard=True) plan_pointer = worker.request_search(plan_id, location=plan_owner)[0] plan = plan_pointer.get() except WorkerNotFoundException: plan = worker.get_obj(plan_id) plans.append((worker.id, plan)) protocol = sy.Protocol(plans=plans, id=id, owner=worker, tags=tags, description=description) return protocol
def unbufferize(worker: AbstractWorker, protobuf_tensor: PointerTensorPB) -> "PointerTensor": # Extract the field values obj_id = syft.serde.protobuf.proto.get_protobuf_id( protobuf_tensor.object_id) obj_id_at_location = syft.serde.protobuf.proto.get_protobuf_id( protobuf_tensor.object_id_at_location) worker_id = syft.serde.protobuf.proto.get_protobuf_id( protobuf_tensor.location_id) point_to_attr = protobuf_tensor.point_to_attr shape = syft.hook.create_shape(protobuf_tensor.shape.dims) garbage_collect_data = protobuf_tensor.garbage_collect_data # If the pointer received is pointing at the current worker, we load the tensor instead if worker_id == worker.id: tensor = worker.get_obj(obj_id_at_location) if point_to_attr is not None and tensor is not None: point_to_attrs = point_to_attr.split(".") for attr in point_to_attrs: if len(attr) > 0: tensor = getattr(tensor, attr) if tensor is not None: if not tensor.is_wrapper and not isinstance( tensor, FrameworkTensor): # if the tensor is a wrapper then it doesn't need to be wrapped # if the tensor isn't a wrapper, BUT it's just a plain torch tensor, # then it doesn't need to be wrapped. # if the tensor is not a wrapper BUT it's also not a torch tensor, # then it needs to be wrapped or else it won't be able to be used # by other interfaces tensor = tensor.wrap() return tensor # Else we keep the same Pointer else: location = syft.hook.local_worker.get_worker(worker_id) ptr = PointerTensor( location=location, id_at_location=obj_id_at_location, owner=worker, id=obj_id, shape=shape, garbage_collect_data=garbage_collect_data, ) return ptr