def apply(self, conn: Cluster, cwd):
        mv_builder = ModelVersionBuilder(name = self.name,path = cwd) \
            .with_runtime(DockerImage.from_string(self.runtime)) \
            .with_payload(self.payload) \
            .with_signature(self.contract.to_proto())

        if self.install_command:
            mv_builder.with_install_command(self.install_command)

        if self.training_data:
            mv_builder.with_training_data(self.training_data)

        collected_meta = CollectedMetadata.collect(cwd).to_metadata()
        if self.metadata:
            collected_meta.update(self.metadata)
        mv_builder.with_metadata(collected_meta)

        if self.monitoring_configuration:
            mc = SDK_MC(self.monitoring_configuration.batch_size)
            mv_builder.with_monitoring_configuration(mc)

        logging.debug(f"Model version builder:\n{mv_builder}")

        mv = mv_builder.build(conn)
        build_log_handler = DockerLogHandler()
        logging.info("Build logs:")
        for ev in mv.build_logs():
            build_log_handler.show(ev.data)

        if self.monitoring:
            logging.info(
                f"Uploading monitoring configuration for the model {mv.name}:{mv.version}"
            )
            for mon in self.monitoring:
                name, version = mon.config.monitoring_model.split(":")
                mon_mv = SDK_MV.find(conn, name, int(version))
                sdk_conf = MetricSpecConfig(modelversion_id=mon_mv.id,
                                            threshold=mon.config.threshold,
                                            threshold_op=mon.config.operator)
                sdk_ms = MetricSpec.create(cluster=conn,
                                           name=mon.name,
                                           modelversion_id=mv.id,
                                           config=sdk_conf)
                logging.debug(
                    f"Created metric spec: {sdk_ms.name} with id {sdk_ms.id}")

        if mv.training_data:
            logging.info("Uploading training data")
            resp = mv.upload_training_data()
            logging.info(f"Training data profile is available at {resp.url}")

        return mv
Beispiel #2
0
def app_scalar(cluster: Cluster, model_version_builder: ModelVersionBuilder,
               training_data: str):
    model_version_builder.with_monitoring_configuration(
        MonitoringConfiguration(batch_size=10))
    mv: ModelVersion = model_version_builder.build(cluster)
    mv.training_data = training_data
    data_upload_response = mv.upload_training_data()
    data_upload_response.wait(sleep=5)
    mv.lock_till_released(timeout=config.lock_timeout)
    stage = ExecutionStageBuilder().with_model_variant(mv, 100).build()
    app: Application = ApplicationBuilder(f"{config.default_application_name}-{random.randint(0, 1e5)}") \
        .with_stage(stage).build(cluster)
    app.lock_while_starting(timeout=config.lock_timeout)
    time.sleep(10)
    yield app
    Application.delete(cluster, app.name)