-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support autoscaling metrics when deploying models #1197
Changes from 11 commits
03d7885
4bb666b
9501eb0
7a601c7
b278298
c82ba65
e14d1ae
fbceb92
0f2353e
8a28d7a
779b805
12ad857
4acd36d
1f19010
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,9 @@ | |
_TEST_ACCELERATOR_TYPE = "NVIDIA_TESLA_P100" | ||
_TEST_ACCELERATOR_COUNT = 2 | ||
|
||
_TEST_METRIC_NAME_CPU_UTILIZATION = "aiplatform.googleapis.com/prediction/online/cpu/utilization" | ||
_TEST_METRIC_NAME_GPU_UTILIZATION = "aiplatform.googleapis.com/prediction/online/accelerator/duty_cycle" | ||
|
||
_TEST_EXPLANATIONS = [gca_prediction_service.explanation.Explanation(attributions=[])] | ||
|
||
_TEST_ATTRIBUTIONS = [ | ||
|
@@ -1053,6 +1056,131 @@ def test_deploy_with_dedicated_resources(self, deploy_model_mock, sync): | |
timeout=None, | ||
) | ||
|
||
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock") | ||
@pytest.mark.parametrize("sync", [True, False]) | ||
def test_deploy_with_autoscaling_target_cpu_utilization(self, deploy_model_mock, sync): | ||
test_endpoint = models.Endpoint(_TEST_ENDPOINT_NAME) | ||
test_model = models.Model(_TEST_ID) | ||
test_model._gca_resource.supported_deployment_resources_types.append( | ||
aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES | ||
) | ||
test_endpoint.deploy( | ||
model=test_model, | ||
machine_type=_TEST_MACHINE_TYPE, | ||
service_account=_TEST_SERVICE_ACCOUNT, | ||
sync=sync, | ||
deploy_request_timeout=None, | ||
autoscaling_target_cpu_utilization=70, | ||
) | ||
|
||
if not sync: | ||
test_endpoint.wait() | ||
|
||
expected_machine_spec = gca_machine_resources.MachineSpec( | ||
machine_type=_TEST_MACHINE_TYPE, | ||
) | ||
|
||
expected_autoscaling_metric_spec = gca_machine_resources.AutoscalingMetricSpec( | ||
metric_name=_TEST_METRIC_NAME_CPU_UTILIZATION, | ||
target=70, | ||
) | ||
|
||
expected_dedicated_resources = gca_machine_resources.DedicatedResources( | ||
machine_spec=expected_machine_spec, | ||
min_replica_count=1, | ||
max_replica_count=1, | ||
) | ||
expected_dedicated_resources.autoscaling_metric_specs.extend([expected_autoscaling_metric_spec]) | ||
|
||
expected_deployed_model = gca_endpoint.DeployedModel( | ||
dedicated_resources=expected_dedicated_resources, | ||
model=test_model.resource_name, | ||
display_name=None, | ||
service_account=_TEST_SERVICE_ACCOUNT, | ||
) | ||
deploy_model_mock.assert_called_once_with( | ||
endpoint=test_endpoint.resource_name, | ||
deployed_model=expected_deployed_model, | ||
traffic_split={"0": 100}, | ||
metadata=(), | ||
timeout=None, | ||
) | ||
|
||
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock") | ||
@pytest.mark.parametrize("sync", [True, False]) | ||
def test_deploy_with_autoscaling_target_accelerator_duty_cycle(self, deploy_model_mock, sync): | ||
test_endpoint = models.Endpoint(_TEST_ENDPOINT_NAME) | ||
test_model = models.Model(_TEST_ID) | ||
test_model._gca_resource.supported_deployment_resources_types.append( | ||
aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES | ||
) | ||
test_endpoint.deploy( | ||
model=test_model, | ||
machine_type=_TEST_MACHINE_TYPE, | ||
accelerator_type=_TEST_ACCELERATOR_TYPE, | ||
accelerator_count=_TEST_ACCELERATOR_COUNT, | ||
service_account=_TEST_SERVICE_ACCOUNT, | ||
sync=sync, | ||
deploy_request_timeout=None, | ||
autoscaling_target_accelerator_duty_cycle=70 | ||
) | ||
|
||
if not sync: | ||
test_endpoint.wait() | ||
|
||
expected_machine_spec = gca_machine_resources.MachineSpec( | ||
machine_type=_TEST_MACHINE_TYPE, | ||
accelerator_type=_TEST_ACCELERATOR_TYPE, | ||
accelerator_count=_TEST_ACCELERATOR_COUNT, | ||
) | ||
|
||
expected_autoscaling_metric_spec = gca_machine_resources.AutoscalingMetricSpec( | ||
metric_name=_TEST_METRIC_NAME_GPU_UTILIZATION, | ||
target=70, | ||
) | ||
|
||
expected_dedicated_resources = gca_machine_resources.DedicatedResources( | ||
machine_spec=expected_machine_spec, | ||
min_replica_count=1, | ||
max_replica_count=1, | ||
) | ||
expected_dedicated_resources.autoscaling_metric_specs.extend([expected_autoscaling_metric_spec]) | ||
|
||
expected_deployed_model = gca_endpoint.DeployedModel( | ||
dedicated_resources=expected_dedicated_resources, | ||
model=test_model.resource_name, | ||
display_name=None, | ||
service_account=_TEST_SERVICE_ACCOUNT, | ||
) | ||
deploy_model_mock.assert_called_once_with( | ||
endpoint=test_endpoint.resource_name, | ||
deployed_model=expected_deployed_model, | ||
traffic_split={"0": 100}, | ||
metadata=(), | ||
timeout=None, | ||
) | ||
|
||
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock") | ||
@pytest.mark.parametrize("sync", [True, False]) | ||
def test_deploy_with_autoscaling_target_accelerator_duty_cycle_and_no_accelerator_type_or_count_raises( | ||
self, | ||
sync | ||
): | ||
with pytest.raises(ValueError): | ||
test_endpoint = models.Endpoint(_TEST_ENDPOINT_NAME) | ||
test_model = models.Model(_TEST_ID) | ||
test_model._gca_resource.supported_deployment_resources_types.append( | ||
aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES | ||
) | ||
test_endpoint.deploy( | ||
model=test_model, | ||
sync=sync, | ||
autoscaling_target_accelerator_duty_cycle=70, | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add the following after the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the other tests which raise errors with the deploy operation wait for the operation to complete except for one. def test_deploy_raise_error_traffic_80 Can you confirm if you need me to the wait call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this test needs the wait call. The ones that don't need it are testing invalid parameter values (negative numbers and > 100 for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 8a28d7a |
||
if not sync: | ||
test_endpoint.wait() | ||
|
||
@pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock") | ||
@pytest.mark.parametrize("sync", [True, False]) | ||
def test_deploy_with_explanations(self, deploy_model_with_explanations_mock, sync): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add "Optional" to the beginning of this docstring? Same for
autoscaling_target_accelerator_duty_cycle
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7a601c7