def test_update_with_resources(self, client, created_endpoints, experiment_run, model_for_deployment): endpoint_name = _utils.generate_default_name() endpoint = client.set_endpoint(endpoint_name) created_endpoints.append(endpoint) original_status = endpoint.get_status() original_build_ids = get_build_ids(original_status) experiment_run.log_model(model_for_deployment['model'], custom_modules=[]) experiment_run.log_requirements(['scikit-learn']) resources = '{"cpu": 0.25, "memory": "100M"}' runner = CliRunner() result = runner.invoke( cli, [ 'deployment', 'update', 'endpoint', endpoint_name, '--run-id', experiment_run.id, "-s", "direct", '--resources', resources ], ) assert not result.exception resources_dict = Resources._from_dict(json.loads( resources))._as_dict() # config is `cpu`, wire is `cpu_millis` assert endpoint.get_update_status( )['update_request']['resources'] == resources_dict
def test_create_update_body(self): endpoint = Endpoint(None, None, None, None) resources = Resources(cpu=.25, memory="512Mi") env_vars = { 'CUDA_VISIBLE_DEVICES': "1,2", "VERTA_HOST": "app.verta.ai", "GIT_TERMINAL_PROMPT": "1" } parameter_json = endpoint._create_update_body(DirectUpdateStrategy(), resources, None, env_vars) assert parameter_json == { 'env': [{ "name": 'CUDA_VISIBLE_DEVICES', 'value': '1,2' }, { 'name': 'GIT_TERMINAL_PROMPT', 'value': '1' }, { "name": 'VERTA_HOST', 'value': 'app.verta.ai' }], 'resources': { 'cpu_millis': 250, 'memory': '512Mi' }, 'strategy': 'rollout', }
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
def test_update_from_json_config_with_params(self, client, in_tempdir, created_entities, experiment_run, model_for_deployment): yaml = pytest.importorskip("yaml") experiment_run.log_model(model_for_deployment['model'], custom_modules=[]) experiment_run.log_environment(Python(['scikit-learn'])) path = verta._internal_utils._utils.generate_default_name() endpoint = client.set_endpoint(path) created_entities.append(endpoint) original_status = endpoint.get_status() original_build_ids = get_build_ids(original_status) # Creating config dict: config_dict = { "run_id": experiment_run.id, "strategy": "direct", "autoscaling": { "quantities": {"min_replicas": 1, "max_replicas": 4, "min_scale": 0.5, "max_scale": 2.0}, "metrics": [ {"metric": "cpu_utilization", "parameters": [{"name": "target", "value": "0.5"}]}, {"metric": "memory_utilization", "parameters": [{"name": "target", "value": "0.7"}]} ] }, "env_vars": {"VERTA_HOST": "app.verta.ai"}, "resources": {"cpu": 0.25, "memory": "100M"} } filepath = "config.json" with open(filepath, 'w') as f: json.dump(config_dict, f) endpoint.update_from_config(filepath) update_status = endpoint.get_update_status() # Check autoscaling: autoscaling_parameters = update_status["update_request"]["autoscaling"] autoscaling_quantities = autoscaling_parameters["quantities"] assert autoscaling_quantities == config_dict["autoscaling"]["quantities"] autoscaling_metrics = autoscaling_parameters["metrics"] assert len(autoscaling_metrics) == 2 for metric in autoscaling_metrics: assert metric["metric_id"] in [1001, 1002, 1003] if metric["metric_id"] == 1001: assert metric["parameters"][0]["value"] == "0.5" else: assert metric["parameters"][0]["value"] == "0.7" # Check env_vars: assert update_status["update_request"]["env"][0]["name"] == "VERTA_HOST" assert update_status["update_request"]["env"][0]["value"] == "app.verta.ai" # Check resources: resources_dict = Resources._from_dict(config_dict["resources"])._as_dict() # config is `cpu`, wire is `cpu_millis` assert endpoint.get_update_status()['update_request']['resources'] == resources_dict
def test_download_endpoint_manifest(client, data, strategy, in_tempdir): resources = Resources(cpu=data) # test that `resources` can actually be used client.download_endpoint_manifest( "deployment.yaml", "/production-prediction", "production-prediction", strategy=strategy, resources=resources, )
def test_memory(client, data, in_tempdir): resources = Resources(memory=data) # test that `resources` can acutally be used client.download_endpoint_manifest( "deployment.yaml", "/production-prediction", "production-prediction", strategy=DirectUpdateStrategy(), resources=resources, )
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
def test_memory_negative_type(data): with pytest.raises(TypeError): Resources(memory=data)
def test_memory_negative(data): with pytest.raises(ValueError): Resources(memory=data)
def test_cpu_milli_negative_type(data): with pytest.raises(TypeError): Resources(cpu=data)
def test_cpu_milli_negative(data): with pytest.raises(ValueError): Resources(cpu=data)
def test_cpu_milli(client, data, in_tempdir): Resources(cpu=data)
def test_cpu_milli(data): Resources(cpu=data)
def test_memory(data): Resources(memory=data)