示例#1
0
    def __init__(
        self,
        name: str = None,
        state: State = None,
        include_state: bool = False,
        is_built: bool = False,
        actions: List[ComputationAction] = None,
        placeholders: Dict[Union[str, int], PlaceHolder] = None,
        forward_func=None,
        state_tensors=None,
        # General kwargs
        id: Union[str, int] = None,
        owner: "sy.workers.BaseWorker" = None,
        tags: List[str] = None,
        description: str = None,
    ):
        owner = owner or sy.local_worker
        AbstractObject.__init__(self, id, owner, tags, description, child=None)
        ObjectStorage.__init__(self)

        # Plan instance info
        self.name = name or self.__class__.__name__
        self.owner = owner

        self.actions = actions or []

        # Keep a local reference to all placeholders, stored by id
        self.placeholders = placeholders or {}
        # Incremental value to tag all placeholders with different tags
        self.var_count = 0

        self.state = state or State(owner=owner)
        # state_tensors are provided when plans are created using func2plan
        if state_tensors is not None:
            # we want to make sure in that case that the state is empty
            assert state is None
            for tensor in state_tensors:
                placeholder = sy.PlaceHolder(
                    tags={"#state", f"#{self.var_count + 1}"},
                    id=tensor.id,
                    owner=self.owner)
                self.var_count += 1
                placeholder.instantiate(tensor)
                self.state.state_placeholders.append(placeholder)
                self.placeholders[tensor.id] = placeholder

        self.include_state = include_state
        self.is_built = is_built

        # The plan has not been sent so it has no reference to remote locations
        self.pointers = dict()

        if not hasattr(self, "forward"):
            self.forward = forward_func or None

        self.__name__ = self.__repr__(
        )  # For PyTorch jit tracing compatibility
示例#2
0
    def __init__(
        self,
        name: str = None,
        procedure: Procedure = None,
        state: State = None,
        include_state: bool = False,
        is_built: bool = False,
        # Optional kwargs if commands or state are not provided
        state_ids: List[Union[str, int]] = None,
        arg_ids: List[Union[str, int]] = None,
        result_ids: List[Union[str, int]] = None,
        readable_plan: List = None,
        blueprint=None,
        state_tensors=None,
        # General kwargs
        id: Union[str, int] = None,
        owner: "sy.workers.BaseWorker" = None,
        tags: List[str] = None,
        description: str = None,
    ):
        owner = owner or sy.local_worker
        AbstractObject.__init__(self, id, owner, tags, description, child=None)
        ObjectStorage.__init__(self)

        # Plan instance info
        self.name = name or self.__class__.__name__
        self.owner = owner

        # If we have plans in plans we need to keep track of the states for each plan
        # because we will need to serialize and send them to the remote workers
        self.nested_states = []

        # Info about the plan stored via the state and the procedure
        self.procedure = procedure or Procedure(readable_plan, arg_ids, result_ids)
        self.state = state or State(owner=owner, plan=self, state_ids=state_ids)
        if state_tensors is not None:
            for tensor in state_tensors:
                self.state.state_ids.append(tensor.id)
                self.owner.register_obj(tensor)

        self.include_state = include_state
        self.is_built = is_built
        self.input_shapes = None
        self._output_shape = None

        # The plan has not been sent
        self.pointers = dict()

        if blueprint is not None:
            self.forward = blueprint
        elif self.is_built:
            self.forward = None
示例#3
0
文件: plan.py 项目: flo257/PySyft
    def __init__(
        self,
        id: Union[str, int] = None,
        owner: "sy.workers.BaseWorker" = None,
        name: str = "",
        state_ids: List[Union[str, int]] = None,
        arg_ids: List[Union[str, int]] = None,
        result_ids: List[Union[str, int]] = None,
        readable_plan: List = None,
        blueprint=None,
        state=None,
        include_state: bool = False,
        is_built: bool = False,
        verbose: bool = False,
        *args,
        **kwargs,
    ):
        ObjectStorage.__init__(self)
        torch.nn.Module.__init__(self)

        # Plan instance info
        self.id = sy.ID_PROVIDER.pop() if id is None else id
        self.name = self.__class__.__name__ if name == "" else name
        self._owner = sy.local_worker if owner is None else owner
        self.verbose = verbose

        # Info about the plan stored
        self.plan = list()
        self.readable_plan = readable_plan if readable_plan is not None else []
        self.state = State(self)
        self.include_state = include_state
        if state is not None:
            self.state.set_(state)
        self.state_ids = state_ids if state_ids is not None else []
        self.arg_ids = arg_ids if arg_ids is not None else []
        self.result_ids = result_ids if result_ids is not None else []
        self.owner_when_built = None
        self.is_built = is_built

        # Pointing info towards a remote plan
        self.locations = []
        self.ptr_plans = {}

        self.tags = None
        self.description = None

        if blueprint is not None:
            self.forward = blueprint
        elif self.is_built:
            self.forward = None
示例#4
0
    def __init__(
        self,
        name: str = None,
        procedure: Procedure = None,
        state: State = None,
        include_state: bool = False,
        is_built: bool = False,
        # Optional kwargs if commands or state are not provided
        state_ids: List[Union[str, int]] = None,
        arg_ids: List[Union[str, int]] = None,
        result_ids: List[Union[str, int]] = None,
        readable_plan: List = None,
        blueprint=None,
        state_tensors=None,
        # General kwargs
        id: Union[str, int] = None,
        owner: "sy.workers.BaseWorker" = None,
        tags: List[str] = None,
        description: str = None,
    ):
        owner = owner or sy.local_worker
        AbstractObject.__init__(self, id, owner, tags, description, child=None)
        ObjectStorage.__init__(self)

        # Plan instance info
        self.name = name or self.__class__.__name__
        self.owner = owner

        # Info about the plan stored via the state and the procedure
        self.procedure = procedure or Procedure(readable_plan, arg_ids,
                                                result_ids)
        self.state = state or State(
            owner=owner, plan=self, state_ids=state_ids)
        if state_tensors is not None:
            for tensor in state_tensors:
                self.state.state_ids.append(tensor.id)
                self.owner.register_obj(tensor)
        self.include_state = include_state
        self.is_built = is_built

        if blueprint is not None:
            self.forward = blueprint
        elif self.is_built:
            self.forward = None