コード例 #1
0
    def test_canary_update(self, client, created_endpoints, experiment_run,
                           model_for_deployment):
        experiment_run.log_model(model_for_deployment['model'],
                                 custom_modules=[])
        experiment_run.log_requirements(['scikit-learn'])

        path = verta._internal_utils._utils.generate_default_name()
        endpoint = client.set_endpoint(path)
        created_endpoints.append(endpoint)

        original_status = endpoint.get_status()
        original_build_ids = get_build_ids(original_status)

        strategy = CanaryUpdateStrategy(interval=1, step=0.5)

        with pytest.raises(RuntimeError) as excinfo:
            endpoint.update(experiment_run, strategy)

        assert "canary update strategy must have at least one rule" in str(
            excinfo.value)

        strategy.add_rule(MaximumAverageLatencyThresholdRule(0.8))
        updated_status = endpoint.update(experiment_run, strategy)

        # Check that a new build is added:
        new_build_ids = get_build_ids(updated_status)
        assert len(new_build_ids) - len(
            new_build_ids.intersection(original_build_ids)) > 0
コード例 #2
0
    def test_update_with_parameters(self, client, created_endpoints,
                                    experiment_run, model_for_deployment):
        experiment_run.log_model(model_for_deployment['model'],
                                 custom_modules=[])
        experiment_run.log_requirements(['scikit-learn'])

        path = verta._internal_utils._utils.generate_default_name()
        endpoint = client.set_endpoint(path)
        created_endpoints.append(endpoint)

        original_status = endpoint.get_status()
        original_build_ids = get_build_ids(original_status)

        strategy = CanaryUpdateStrategy(interval=1, step=0.5)

        strategy.add_rule(MaximumAverageLatencyThresholdRule(0.8))
        updated_status = endpoint.update(experiment_run,
                                         strategy,
                                         resources=Resources(cpu=.25,
                                                             memory="512Mi"),
                                         env_vars={
                                             'CUDA_VISIBLE_DEVICES': "1,2",
                                             "VERTA_HOST": "app.verta.ai"
                                         })

        # Check that a new build is added:
        new_build_ids = get_build_ids(updated_status)
        assert len(new_build_ids) - len(
            new_build_ids.intersection(original_build_ids)) > 0
コード例 #3
0
    def test_download_manifest(self, client, in_tempdir):
        download_to_path = "manifest.yaml"
        path = verta._internal_utils._utils.generate_default_name()
        name = verta._internal_utils._utils.generate_default_name()

        strategy = CanaryUpdateStrategy(interval=10, step=0.1)
        strategy.add_rule(MaximumAverageLatencyThresholdRule(0.1))
        resources = Resources(cpu=.1, memory="128Mi")
        autoscaling = Autoscaling(min_replicas=1,
                                  max_replicas=10,
                                  min_scale=0.1,
                                  max_scale=2)
        autoscaling.add_metric(CpuUtilizationTarget(0.75))
        env_vars = {'env1': "var1", 'env2': "var2"}

        filepath = client.download_endpoint_manifest(
            download_to_path=download_to_path,
            path=path,
            name=name,
            strategy=strategy,
            autoscaling=autoscaling,
            resources=resources,
            env_vars=env_vars,
        )

        # can be loaded as YAML
        with open(filepath, 'rb') as f:
            manifest = yaml.safe_load(f)

        assert manifest['kind'] == "Endpoint"

        # check environment variables
        containers = manifest['spec']['function']['spec']['templates'][
            'deployment']['spec']['template']['spec']['containers']
        retrieved_env_vars = {
            env_var['name']: env_var['value']
            for env_var in containers[0]['env']
        }
        assert retrieved_env_vars == env_vars