Example #1
0
    def deser(msg_obj, worker, acquire):

        if 'owner' not in msg_obj:
            raise TypeError(
                "sy._LocalTensor can't deserialize a non-valid sy._LocalTensor. "
                "Do you wan to call sy.FloatTensor.deser() instead?")
        if msg_obj['owner'] == worker.id:
            logging.warning('_LocalTensor sent to itself')
        if acquire:  # We need to register the info given
            syft_obj = sy._LocalTensor(child=None,
                                       parent=None,
                                       torch_type=msg_obj['torch_type'],
                                       owner=worker,
                                       id=msg_obj['id'],
                                       skip_register=True)
        else:  # We point at the info which generally we can't really have
            # We make sure we are not creating a duplicate pointer
            previous_pointer = worker.get_pointer_to(msg_obj['owner'],
                                                     msg_obj['id'])
            if previous_pointer is None:
                syft_obj = sy._PointerTensor(child=None,
                                             parent=None,
                                             torch_type=msg_obj['torch_type'],
                                             location=msg_obj['owner'],
                                             id_at_location=msg_obj['id'],
                                             owner=worker,
                                             id=None,
                                             skip_register=True)
            else:
                syft_obj = previous_pointer
        return syft_obj
Example #2
0
    def deser(cls, msg_obj, worker, acquire):
        """
        General method for de-serializing a Syft object. Specific tensors like _PointerTensor
        should overload this method.
        """
        if acquire:  # We need to register the info given
            syft_obj = cls(child=None,
                           parent=None,
                           torch_type=msg_obj['torch_type'],
                           owner=worker,
                           id=msg_obj['id'],
                           skip_register=True)
            if 'child' in msg_obj:
                syft_child = cls.deser_routing(msg_obj['child'], worker,
                                               acquire)
                syft_obj.child = syft_child
                syft_child.parent = syft_obj

        else:  # We point at the info which generally we can't really have
            # We make sure we are not creating a duplicate pointer
            previous_pointer = worker.get_pointer_to(msg_obj['owner'],
                                                     msg_obj['id'])
            if previous_pointer is None:
                syft_obj = sy._PointerTensor(child=None,
                                             parent=None,
                                             torch_type=msg_obj['torch_type'],
                                             location=msg_obj['owner'],
                                             id_at_location=msg_obj['id'],
                                             owner=worker,
                                             id=None,
                                             skip_register=True)
            else:
                syft_obj = previous_pointer
        return syft_obj
Example #3
0
 def deser(cls, msg_obj, worker, acquire):
     # If local, we render the object or syft object
     if msg_obj['location'] == worker.id:
         syft_obj = worker.get_obj(msg_obj['id_at_location'])
     else:
         if acquire:  # If there is data transmission, data being here Pointer
             # We acquire the tensor pointer
             previous_pointer = worker.get_pointer_to(
                 msg_obj['owner'], msg_obj['id'])
             if previous_pointer is None:
                 syft_obj = cls(child=None,
                                parent=None,
                                torch_type=msg_obj['torch_type'],
                                location=msg_obj['location'],
                                id_at_location=msg_obj['id_at_location'],
                                owner=worker,
                                id=msg_obj['id'],
                                skip_register=True)
             else:
                 syft_obj = previous_pointer
         else:  # We point at the Pointer (same part as every syft tensors)
             previous_pointer = worker.get_pointer_to(
                 msg_obj['owner'], msg_obj['id'])
             if previous_pointer is None:
                 syft_obj = sy._PointerTensor(
                     child=None,
                     parent=None,
                     torch_type=msg_obj['torch_type'],
                     location=msg_obj['owner'],
                     id_at_location=msg_obj['id'],
                     owner=worker,
                     id=None,
                     skip_register=True)
             else:
                 syft_obj = previous_pointer
     return syft_obj