Beispiel #1
0
def rm(obj, app_name, y):
    if not y:
        click.confirm(
            f"Are you sure you want to delete the {app_name} application?",
            abort=True)
    Application.delete(obj, app_name)
    click.echo(f"Application is  deleted: {app_name}")
Beispiel #2
0
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
Beispiel #3
0
def app(cluster: Cluster, modelversion: ModelVersion,
        deployment_configuration: DeploymentConfiguration):
    stage = ExecutionStageBuilder().with_model_variant(
        modelversion, 100, deployment_configuration).build()
    app = ApplicationBuilder(f"{config.default_application_name}-{random.randint(0, 1e5)}") \
        .with_stage(stage).with_metadata("key", "value").build(cluster)
    app.lock_while_starting(timeout=config.lock_timeout)
    yield app
    Application.delete(cluster, app.name)
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 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 apply(self, conn: Cluster, cwd) -> HS_APP:
        collected_meta = CollectedMetadata.collect(cwd).to_metadata()
        builder = self.app_builder(conn, collected_meta)
        found_app = None
        try:
            found_app = HS_APP.find(conn, self.name)
        except HydrosphereException:
            logging.debug(f"Can't get an application {self.name} from cluster",
                          exc_info=True)
            pass
        if found_app:
            logging.info(
                f"Found existing application {found_app.name}. Updating it.")
            HS_APP.delete(conn, self.name)

        app = builder.build(conn)
        return app
Beispiel #7
0
def list(obj):
    apps = Application.list(obj)
    apps_view = []
    for a in apps:
        apps_view.append({'name': a.name})
    click.echo(tabulate(apps_view, headers="keys", tablefmt="github"))
Beispiel #8
0
def test_predict_python_scalar_type(app_scalar: Application, value: int):
    predictor = app_scalar.predictor(return_type=PredictorDT.DICT_NP_ARRAY)
    predictions = predictor.predict({'input': value})
    assert isinstance(predictions, dict)
    assert isinstance(predictions['output'], np.int64)
    assert predictions['output'] == value
Beispiel #9
0
def test_predict_df(app_tensor: Application, value: int):
    predictor = app_tensor.predictor(return_type=PredictorDT.DF)
    predictions = predictor.predict(pd.DataFrame({'input': [value]}))
    assert isinstance(predictions, pd.DataFrame)
    assert predictions.equals(pd.DataFrame({'output': [value]}))
Beispiel #10
0
def test_predict_nparray(app_tensor: Application, value: int):
    predictor = app_tensor.predictor(return_type=PredictorDT.DICT_NP_ARRAY)
    predictions = predictor.predict({"input": np.array([value])})
    assert isinstance(predictions, dict)
    assert isinstance(predictions['output'], np.ndarray)
    assert predictions['output'] == np.array([value])
Beispiel #11
0
def test_predict(app_tensor: Application, value: int):
    predictor = app_tensor.predictor(return_type=PredictorDT.DICT_PYTHON)
    predictions = predictor.predict({"input": [value]})
    assert isinstance(predictions, dict)
    assert isinstance(predictions['output'], list)
    assert predictions['output'] == [value]
Beispiel #12
0
def test_metadata(cluster: Cluster, app: Application):
    app_found = Application.find(cluster, app.name)
    assert app_found.metadata == {"key": "value"}
Beispiel #13
0
def test_find(cluster: Cluster, app: Application):
    app_found = Application.find(cluster, app.name)
    assert app_found.id == app.id
Beispiel #14
0
def test_list_non_empty(cluster: Cluster, app: Application):
    apps = Application.list(cluster)
    assert app.name in [item.name for item in apps]
    assert app.id in [item.id for item in apps]