def app_builder(self, conn: Cluster, metadata: Dict[str, str]) -> ApplicationBuilder: builder = ApplicationBuilder(self.name) if self.metadata: metadata.update(self.metadata) builder.with_metadatas(metadata) if self.singular: name, version = self.singular.model.split(":") mv = ModelVersion.find(conn, name, version) builder.with_stage( ExecutionStage( signature=None, model_variants=[ ModelVariant(modelVersionId=mv.id, weight=100, deploymentConfigurationName=self.singular. deployment_config) ])) elif self.pipeline: for stage in self.pipeline: variants: List[ModelVariant] = [] for model in stage: name, version = model.model.split(":") mv = ModelVersion.find(conn, name, version) variants.append( ModelVariant(modelVersionId=mv.id, weight=model.weight, deploymentConfigurationName=model. deployment_config)) builder.with_stage( ExecutionStage(signature=None, model_variants=variants)) else: raise ValueError( "Invalid application: no 'singular' or 'pipeline' fields") return builder
def push(obj, model_version, filename, s3path): model, version = model_version.split(":") mv = ModelVersion.find(obj, model, int(version)) if filename and s3path: raise click.ClickException( "Both --filename and --s3path were provided. Need only one of them." ) if filename: click.echo("Uploading local file") res = _upload_local_file(obj, mv.id, filename) if res.ok: click.echo("Data uploaded") else: raise click.ClickException(str(res)) elif s3path: click.echo("Uploading S3 path") res = _upload_s3_file(obj, mv.id, s3path) if res.ok: click.echo("Data uploaded") else: raise click.ClickException(str(res)) else: raise click.ClickException("Neither S3 nor file was defined.") click.echo( f"Data profile for {model_version} will be available: {obj.http_address}/models/{mv.name}/{mv.version}" )
def update_application(model_name: str, model_version: int, hydrosphere_uri: str, application_name: str = "kf_lr_app"): import time from hydrosdk import Cluster from hydrosdk.modelversion import ModelVersion from hydrosdk.application import Application, ApplicationBuilder, ExecutionStageBuilder cluster = Cluster(hydrosphere_uri) mv = ModelVersion.find(cluster, model_name, model_version) try: Application.delete(cluster, application_name) time.sleep(5) except Exception as e: print( f"Got error while trying to delete an application {application_name}" ) print(e) print("Creating an Application object") app_builder = ApplicationBuilder(cluster, application_name) stage = ExecutionStageBuilder().with_model_variant(mv, 100).build() app_builder = app_builder.with_stage(stage) print(f"Uploading model to the cluster {hydrosphere_uri}") app = app_builder.build() app = app.lock_while_starting() print(app) return app
def logs(obj, model_name): (name, version) = model_name.split(':') mv = ModelVersion.find(obj, name, version) logs = mv.build_logs() for l in logs: click.echo(l.data) click.echo("End of logs")
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
def test_modelversion_find(cluster: Cluster, model_version_builder: ModelVersionBuilder): mv: ModelVersion = model_version_builder.build(cluster) mv_found: ModelVersion = ModelVersion.find(cluster, mv.name, mv.version) assert mv.id == mv_found.id