コード例 #1
0
ファイル: __init__.py プロジェクト: yuejiesong1900/hivemind
    def __init__(self,
                 dht: Optional[DHT],
                 expert_backends: Dict[str, ExpertBackend],
                 listen_on: Endpoint = "0.0.0.0:*",
                 num_connection_handlers: int = 1,
                 update_period: int = 30,
                 start=False,
                 checkpoint_dir=None,
                 **kwargs):
        super().__init__()
        self.dht, self.experts, self.update_period = dht, expert_backends, update_period
        if get_port(listen_on) is None:
            listen_on = replace_port(listen_on, new_port=find_open_port())
        self.listen_on, self.port = listen_on, get_port(listen_on)

        self.conn_handlers = [
            ConnectionHandler(listen_on, self.experts)
            for _ in range(num_connection_handlers)
        ]
        if checkpoint_dir is not None:
            self.checkpoint_saver = CheckpointSaver(expert_backends,
                                                    checkpoint_dir,
                                                    update_period)
        else:
            self.checkpoint_saver = None
        self.runtime = Runtime(self.experts, **kwargs)

        if start:
            self.run_in_background(await_ready=True)
コード例 #2
0
 def __init__(self, experts, dht: DHT, endpoint: Endpoint, update_period: int = 5):
     super().__init__()
     assert get_port(endpoint) is not None
     self.endpoint = endpoint
     self.experts = experts
     self.dht = dht
     self.update_period = update_period
     self.stop = threading.Event()