Skip to content

Commit 153e483

Browse files
authored
Re-route instance count to resource config for Model Batch Deployment (#34249)
* Re-route instance count to resource config * fix * fix * unittest model batch deployment settings
1 parent b71fea7 commit 153e483

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_deployment/model_batch_deployment.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def __init__(
9494
error_threshold=settings.error_threshold,
9595
logging_level=settings.logging_level,
9696
)
97+
if self.resources is not None:
98+
if self.resources.instance_count is None and settings.instance_count is not None:
99+
self.resources.instance_count = settings.instance_count
100+
if self.resources is None and settings.instance_count is not None:
101+
self.resources = ResourceConfiguration(instance_count=settings.instance_count)
97102

98103
# pylint: disable=arguments-differ
99104
def _to_rest_object(self, location: str) -> BatchDeploymentData: # type: ignore
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
import yaml
5+
6+
from azure.ai.ml._schema._deployment.batch.model_batch_deployment import ModelBatchDeploymentSchema
7+
from azure.ai.ml.constants._common import BASE_PATH_CONTEXT_KEY
8+
from azure.ai.ml.constants._deployment import BatchDeploymentOutputAction
9+
from azure.ai.ml.entities import BatchDeployment
10+
from azure.ai.ml.entities._util import load_from_dict
11+
12+
13+
def load_batch_deployment_entity_from_yaml(path: str, context={}) -> BatchDeployment:
14+
"""batch deployment yaml -> batch deployment entity"""
15+
with open(path, "r") as f:
16+
cfg = yaml.safe_load(f)
17+
context.update({BASE_PATH_CONTEXT_KEY: Path(path).parent})
18+
deployment = load_from_dict(ModelBatchDeploymentSchema, cfg, context)
19+
return deployment
20+
21+
22+
@pytest.mark.unittest
23+
@pytest.mark.production_experiences_test
24+
class TestModelBatchDeploymentSchema:
25+
def test_serialize_model_batch_deployment(self) -> None:
26+
test_path = "./tests/test_configs/deployments/batch/model_batch_deployment.yaml"
27+
mbd_entity = load_batch_deployment_entity_from_yaml(test_path)
28+
29+
assert mbd_entity
30+
assert mbd_entity.environment == "AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33"
31+
assert mbd_entity.compute == "cpu-cluster"
32+
assert mbd_entity.model_deployment_settings.output_action == BatchDeploymentOutputAction.APPEND_ROW
33+
assert mbd_entity.model_deployment_settings.output_file_name == "append_row.txt"
34+
assert mbd_entity.model_deployment_settings.error_threshold == 10
35+
assert mbd_entity.model_deployment_settings.mini_batch_size == 5
36+
assert mbd_entity.model_deployment_settings.max_concurrency_per_instance == 5
37+
assert mbd_entity.resources.instance_count == 2
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: blue
2+
endpoint_name: myBatchEndpoint
3+
model:
4+
name: model-1
5+
version: 5
6+
path: ../model-1/model/sklearn_regression_model.pkl
7+
code_configuration:
8+
code: ../endpoint_scoring
9+
scoring_script: ./main.py
10+
environment: azureml:AzureML-sklearn-1.0-ubuntu20.04-py38-cpu:33
11+
compute: "azureml:cpu-cluster"
12+
settings:
13+
instance_count: 2
14+
retry_settings: #optional
15+
max_retries: 3
16+
timeout: 30
17+
mini_batch_size: 5
18+
logging_level: info #optional, default is info
19+
error_threshold: 10 #optional, default is -1
20+
output_action: append_row #optional, Allowed Values: append_row, summary_only
21+
output_file_name: append_row.txt #optional
22+
max_concurrency_per_instance: 5
23+
environment_variables:
24+
AZUREML_BE: bla

0 commit comments

Comments
 (0)