Beispiel #1
0
def servable_tensor(cluster: Cluster, tensor_model_version_builder: ModelVersionBuilder):
    mv: ModelVersion = tensor_model_version_builder.build(cluster)
    mv.lock_till_released(timeout=config.lock_timeout)
    sv: Servable = Servable.create(cluster, mv.name, mv.version)
    sv.lock_while_starting(timeout=config.lock_timeout)
    yield sv
    Servable.delete(cluster, sv.name)
Beispiel #2
0
def test_build_logs_not_empty(cluster: Cluster,
                              model_version_builder: ModelVersionBuilder):
    mv: ModelVersion = model_version_builder.build(cluster)
    mv.lock_till_released(timeout=config.lock_timeout)
    i = 0
    for _ in mv.build_logs():
        i += 1
    assert i > 0
def test_training_data_upload(cluster: Cluster,
                              model_version_builder: ModelVersionBuilder,
                              training_data: str):
    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)
    resp = cluster.request("GET", f"/monitoring/profiles/batch/{mv.id}/status")
    assert "Success" == resp.json()["kind"]
Beispiel #4
0
def app_tensor(cluster: Cluster,
               tensor_model_version_builder: ModelVersionBuilder):
    mv: ModelVersion = tensor_model_version_builder.build(cluster)
    mv.lock_till_released(timeout=config.lock_timeout)
    stage = ExecutionStageBuilder().with_model_variant(mv, 100).build()
    app = 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)
Beispiel #5
0
def test_lock_till_released_failed(cluster: Cluster, runtime: DockerImage,
                                   payload: list, signature: ModelSignature):
    current_dir = os.path.dirname(os.path.abspath(__file__))
    model_path = os.path.join(current_dir, 'resources/identity_model/')
    model_version_builder = ModelVersionBuilder(config.default_model_name, model_path) \
        .with_runtime(runtime) \
        .with_payload(payload) \
        .with_signature(signature) \
        .with_install_command("exit 1")
    mv: ModelVersion = model_version_builder.build(cluster)
    with pytest.raises(ModelVersion.ReleaseFailed):
        mv.lock_till_released(timeout=config.lock_timeout)
    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 #7
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)
def test_delete(cluster: Cluster, model_version_builder: ModelVersionBuilder,
                monitoring_mv: ModelVersion):
    new_root_mv: ModelVersion = model_version_builder.build(cluster)
    ms_config = MetricSpecConfig(monitoring_mv.id, 10, ThresholdCmpOp.NOT_EQ)
    ms1 = MetricSpec.create(cluster, "test_list_for_modelversion",
                            new_root_mv.id, ms_config)
    ms2 = MetricSpec.create(cluster, "test_list_for_modelversion",
                            new_root_mv.id, ms_config)
    MetricSpec.delete(cluster, ms2.id)
    mss = MetricSpec.find_by_modelversion(cluster, new_root_mv.id)
    try:
        assert len(mss) == 1
        assert ms1.id in [ms.id for ms in mss]
        assert ms2.id not in [ms.id for ms in mss]
    finally:
        MetricSpec.delete(cluster, ms1.id)
def test_create_high_level(cluster: Cluster,
                           model_version_builder: ModelVersionBuilder,
                           monitoring_mv: ModelVersion):
    root_mv: ModelVersion = model_version_builder.build(cluster)
    root_mv.lock_till_released(timeout=config.lock_timeout)

    metric = monitoring_mv.as_metric(10, ThresholdCmpOp.NOT_EQ)
    root_mv.assign_metrics([metric])
    try:
        assert monitoring_mv.name in [
            ms.name
            for ms in MetricSpec.find_by_modelversion(cluster, root_mv.id)
        ]
    finally:
        for ms in MetricSpec.find_by_modelversion(cluster, root_mv.id):
            MetricSpec.delete(cluster, ms.id)
Beispiel #10
0
def test_model_version_builder_build(cluster: Cluster):
    name = config.default_model_name
    current_dir = os.path.dirname(os.path.abspath(__file__))
    model_path = os.path.join(current_dir, 'resources/identity_model/')
    signature = SignatureBuilder('infer') \
        .with_input('in1', 'double', [-1, 2], ProfilingType.NONE) \
        .with_output('out1', 'double', [-1], ProfilingType.NONE).build()
    batch_size = 10
    model_version_builder = ModelVersionBuilder(name, model_path) \
        .with_runtime(config.runtime) \
        .with_payload(['./src/func_main.py']) \
        .with_signature(signature) \
        .with_metadata({"key": "value"}) \
        .with_monitoring_configuration(MonitoringConfiguration(batch_size=batch_size))
    mv: ModelVersion = model_version_builder.build(cluster)
    assert mv.status is ModelVersionStatus.Assembling
    mv.lock_till_released(timeout=config.lock_timeout)
    assert mv.status is ModelVersionStatus.Released
    assert mv.monitoring_configuration.batch_size == batch_size
Beispiel #11
0
def test_modelversion_list(cluster: Cluster,
                           model_version_builder: ModelVersionBuilder):
    mv: ModelVersion = model_version_builder.build(cluster)
    assert mv.id in [
        modelversion.id for modelversion in ModelVersion.list(cluster)
    ]
Beispiel #12
0
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
def root_mv(cluster: Cluster, model_version_builder: ModelVersionBuilder):
    mv: ModelVersion = model_version_builder.build(cluster)
    mv.lock_till_released(timeout=config.lock_timeout)
    return mv