Exemple #1
0
 def __init__(
         self,
         servername: str,
         host: str = '',
         http_port: int = 8080,
         grpc_port: int = 8081,
         workers: int = 1,
         ws_size: int = 16 *
         1024 *
         1024,
         ssl_key=None,
         ssl_cert=None,
         timeout=300):
     self.server_name = servername
     self.app = None
     self.host = host or get_host_ip()
     self.http_port = http_port or 80
     self.grpc_port = grpc_port
     self.workers = workers
     self.keyfile = ssl_key
     self.certfile = ssl_cert
     self.ws_size = int(ws_size)
     self.timeout = int(timeout)
     protocal = "https" if self.certfile else "http"
     self.url = f"{protocal}://{self.host}:{self.http_port}"
Exemple #2
0
    def __init__(self, estimator=None):
        """
        Initial a big model service for JointInference
        :param estimator: Customize estimator
        """

        super(BigModelService, self).__init__(estimator=estimator)
        self.local_ip = self.get_parameters("BIG_MODEL_BIND_IP", get_host_ip())
        self.port = int(self.get_parameters("BIG_MODEL_BIND_PORT", "5000"))
Exemple #3
0
    def __init__(self, estimator=None, hard_example_mining: dict = None):
        super(JointInference, self).__init__(estimator=estimator)
        self.job_kind = K8sResourceKind.JOINT_INFERENCE_SERVICE.value
        self.local_ip = get_host_ip()
        self.remote_ip = self.get_parameters("BIG_MODEL_IP", self.local_ip)
        self.port = int(self.get_parameters("BIG_MODEL_PORT", "5000"))

        report_msg = {
            "name": self.worker_name,
            "namespace": self.config.namespace,
            "ownerName": self.job_name,
            "ownerKind": self.job_kind,
            "kind": "inference",
            "results": []
        }
        period_interval = int(self.get_parameters("LC_PERIOD", "30"))
        self.lc_reporter = LCReporter(lc_server=self.config.lc_server,
                                      message=report_msg,
                                      period_interval=period_interval)
        self.lc_reporter.setDaemon(True)
        self.lc_reporter.start()

        if callable(self.estimator):
            self.estimator = self.estimator()
        if not os.path.exists(self.model_path):
            raise FileExistsError(f"{self.model_path} miss")
        else:
            self.estimator.load(self.model_path)
        self.cloud = ModelClient(service_name=self.job_name,
                                 host=self.remote_ip,
                                 port=self.port)
        self.hard_example_mining_algorithm = None
        if not hard_example_mining:
            hard_example_mining = self.get_hem_algorithm_from_config()
        if hard_example_mining:
            hem = hard_example_mining.get("method", "IBT")
            hem_parameters = hard_example_mining.get("param", {})
            self.hard_example_mining_algorithm = ClassFactory.get_cls(
                ClassType.HEM, hem)(**hem_parameters)
Exemple #4
0
 def __init__(
         self,
         aggregation: str,
         host: str = None,
         http_port: int = None,
         exit_round: int = 1,
         participants_count: int = 1,
         ws_size: int = 10 * 1024 * 1024):
     if not host:
         host = Context.get_parameters("AGG_BIND_IP", get_host_ip())
     if not http_port:
         http_port = int(Context.get_parameters("AGG_BIND_PORT", 7363))
     super(
         AggregationServer,
         self).__init__(
         servername=aggregation,
         host=host,
         http_port=http_port,
         ws_size=ws_size)
     self.aggregation = aggregation
     self.participants_count = participants_count
     self.exit_round = max(int(exit_round), 1)
     self.app = FastAPI(
         routes=[
             APIRoute(
                 f"/{aggregation}",
                 self.client_info,
                 response_class=JSONResponse,
             ),
             WebSocketRoute(
                 f"/{aggregation}",
                 BroadcastWs
             )
         ],
     )
     self.app.shutdown = False