Skip to content
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

Improve code coverage for depployment entity #39403

Merged
merged 32 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
54ed56d
add unit tests for OnlineDeployment rest to entity conversion
pdhotems Jan 26, 2025
d7e472f
add unit tests for onlinedeployment entity _get_arm_resource_and_params
pdhotems Jan 27, 2025
717d95a
move unit tests online_deployment_from_rest_object to right class
pdhotems Jan 27, 2025
ac68bd0
add unit tests for get arm resource for kubenets deployment
pdhotems Jan 27, 2025
077127f
add unit tests for onlinedeployment entity set scale settings
pdhotems Jan 27, 2025
0856a9d
add unit tests for to_dict method
pdhotems Jan 27, 2025
5febfbf
code formatting
pdhotems Jan 28, 2025
0013404
change comment to run tests
pdhotems Jan 29, 2025
3aee0c6
Update assets.json
pdhotems Jan 30, 2025
071c533
Revert "Update assets.json"
pdhotems Jan 30, 2025
31f101c
disable failing tests
pdhotems Jan 30, 2025
3331689
disable failing tests
pdhotems Jan 30, 2025
84b9ed5
enable failing tests and update recordings
pdhotems Jan 30, 2025
31818fd
Merge branch 'pdhote/test-e2e-working' into pdhotems/test-cov-deploym…
pdhotems Jan 30, 2025
c5c4600
add unit tests for OnlineDeployment merge
pdhotems Jan 30, 2025
aac5763
fix unit test
pdhotems Jan 31, 2025
247da71
add unit tests for to_rest_object
pdhotems Jan 31, 2025
5b54524
update unit tests for resource settings
pdhotems Jan 31, 2025
c2164fb
update unit tests for resource settings
pdhotems Jan 31, 2025
c6326c1
add unit tests for online deployment settings
pdhotems Feb 1, 2025
e3f81a3
add unit tests for batch deployment
pdhotems Feb 1, 2025
75872ac
code formatting
pdhotems Feb 2, 2025
10609de
add unit tests batch endpoint deployment
pdhotems Feb 3, 2025
9497f89
add unit tests for batch deployment
pdhotems Feb 3, 2025
87d394a
add unit tests for batch job
pdhotems Feb 3, 2025
5b0d124
add unit tests for batch job
pdhotems Feb 3, 2025
8040afb
add unit tests for model deployment class
pdhotems Feb 3, 2025
eca3887
code formatting
pdhotems Feb 3, 2025
9c24665
remove unwanted tests
pdhotems Feb 4, 2025
70c5845
add unit tests for pipeline_component_batch_deployment.py
pdhotems Feb 4, 2025
7426e32
clean json rest response file
pdhotems Feb 4, 2025
9a1a7b2
clean json rest response file
pdhotems Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/ml/azure-ai-ml/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "python",
"TagPrefix": "python/ml/azure-ai-ml",
"Tag": "python/ml/azure-ai-ml_003b900b39"
"Tag": "python/ml/azure-ai-ml_71dd8cba32"
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _from_rest_object(cls, deployment: RestOnlineDeploymentData) -> RestOnlineDe
if deployment.properties.endpoint_compute_type == EndpointComputeType.MANAGED:
return ManagedOnlineDeployment._from_rest_object(deployment)

msg = f"Unsupported online endpoint type {deployment.properties.type}."
msg = f"Unsupported online endpoint type {deployment.properties.endpoint_compute_type}."
raise DeploymentException(
message=msg,
target=ErrorTarget.ONLINE_DEPLOYMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _from_rest_object( # pylint: disable=arguments-renamed
if settings.scale_type == "TargetUtilization":
return TargetUtilizationScaleSettings._from_rest_object(settings)

msg = f"Unsupported online scale setting type {settings.type}."
msg = f"Unsupported online scale setting type {settings.scale_type}."
raise DeploymentException(
message=msg,
target=ErrorTarget.ONLINE_DEPLOYMENT,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest

from azure.ai.ml.entities import BatchJob
from azure.ai.ml._restclient.v2020_09_01_dataplanepreview.models import BatchJobResource, BatchJob as BatchJobRest


@pytest.mark.unittest
class TestBatchJob:
def test_batch_job_to_dict(self):
batch_job = BatchJob(
id="id",
name="name",
type="type",
status="status",
)
batch_job_dict = batch_job._to_dict()
assert batch_job_dict == {
"id": "id",
"name": "name",
"type": "type",
"status": "status",
}

def test_batch_job_to_rest(self):
batch_jon_rest = BatchJobResource.deserialize(
{"id": "id", "name": "name", "type": "type", "properties": {"status": "status"}}
)
batch_job = BatchJob._from_rest_object(batch_jon_rest)
assert batch_job.id == "id"
assert batch_job.name == "name"
assert batch_job.type == "type"
assert batch_job.status == "status"

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import pytest
from azure.ai.ml.entities import ModelBatchDeployment
from azure.ai.ml.entities._load_functions import load_model_batch_deployment
from azure.ai.ml.constants._deployment import BatchDeploymentOutputAction
from azure.ai.ml._restclient.v2022_05_01.models import BatchOutputAction
from azure.ai.ml.exceptions import ValidationException


@pytest.mark.unittest
class TestModelBatchDeployment:
MODEL_BATCH_DEPLOYMNET = "./tests/test_configs/deployments/batch/model_batch_deployment.yaml"

def test_to_rest_object(self) -> None:
deployment = load_model_batch_deployment(
TestModelBatchDeployment.MODEL_BATCH_DEPLOYMNET, params_override=[{"endpoint_name": "some-en-name"}]
)
rest_deployment = deployment._to_rest_object(location="eastus")
assert rest_deployment.location == "eastus"
assert rest_deployment.properties.description == deployment.description
assert rest_deployment.properties.environment_id == deployment.environment
assert rest_deployment.properties.model.asset_id.name == "model-1"
assert rest_deployment.properties.code_configuration.code_id == deployment.code_configuration.code
assert (
rest_deployment.properties.code_configuration.scoring_script == deployment.code_configuration.scoring_script
)
assert rest_deployment.properties.output_file_name == deployment.settings.output_file_name
assert str(rest_deployment.properties.output_action) == "BatchOutputAction.APPEND_ROW"
assert rest_deployment.properties.resources.instance_count == deployment.resources.instance_count
assert rest_deployment.properties.retry_settings.max_retries == deployment.settings.retry_settings.max_retries
assert (
rest_deployment.properties.max_concurrency_per_instance == deployment.settings.max_concurrency_per_instance
)
assert rest_deployment.properties.environment_variables == deployment.settings.environment_variables
assert rest_deployment.properties.compute == deployment.compute
assert rest_deployment.properties.properties == deployment.properties
assert rest_deployment.tags == deployment.tags

def test_output_action_yaml_to_rest(self):
assert (
ModelBatchDeployment._yaml_output_action_to_rest_output_action(BatchDeploymentOutputAction.APPEND_ROW)
== BatchOutputAction.APPEND_ROW
)
assert (
ModelBatchDeployment._yaml_output_action_to_rest_output_action(BatchDeploymentOutputAction.SUMMARY_ONLY)
== BatchOutputAction.SUMMARY_ONLY
)

def test_validation_fails_if_output_file_name_and_summary_output_action(self) -> None:
deployment = load_model_batch_deployment(TestModelBatchDeployment.MODEL_BATCH_DEPLOYMNET)
deployment.settings.output_action = BatchDeploymentOutputAction.SUMMARY_ONLY
deployment.settings.output_file_name = "some_file_name"
with pytest.raises(ValidationException) as ex:
deployment._to_rest_object(location="westus")
assert "When output_action is set to summary_only, the output_file_name need not to be specified." == str(
ex.value
)

def test_to_dict(self) -> None:
deployment = load_model_batch_deployment(TestModelBatchDeployment.MODEL_BATCH_DEPLOYMNET)
deployment_dict = deployment._to_dict()
assert deployment_dict["name"] == deployment.name
assert deployment_dict["endpoint_name"] == deployment.endpoint_name
assert deployment_dict["model"]["name"] == deployment.model.name
assert deployment_dict["compute"] == "azureml:cpu-cluster"
assert deployment_dict["resources"]["instance_count"] == deployment.resources.instance_count
assert deployment_dict["settings"]["error_threshold"] == deployment.settings.error_threshold
assert deployment_dict["settings"]["output_action"] == "append_row"
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import pytest
import json
from azure.ai.ml.entities._deployment.pipeline_component_batch_deployment import (
PipelineComponentBatchDeployment,
)
from azure.ai.ml.entities import PipelineComponent
from azure.ai.ml.entities._load_functions import (
load_pipeline_component_batch_deployment,
)
from azure.ai.ml._restclient.v2024_01_01_preview.models import (
BatchDeployment as RestBatchDeployment,
IdAssetReference,
BatchPipelineComponentDeploymentConfiguration as RestBatchPipelineComponentDeploymentConfiguration,
)
from azure.ai.ml._restclient.v2024_01_01_preview.models import (
BatchDeploymentProperties as RestBatchDeploymentProperties,
)


@pytest.mark.unittest
class TestPipelineComponentBatchDeployment:
HELLO_BATCH_DEPLOYMENT = "tests/test_configs/deployments/batch/pipeline_component_batch_deployment.yml"
HELLO_BATCH_DEPLOYMENT_REST = "tests/test_configs/deployments/batch/batch_pipeline_component_rest.json"

def test_to_rest_object(self) -> None:
pipeline_component = load_pipeline_component_batch_deployment(
TestPipelineComponentBatchDeployment.HELLO_BATCH_DEPLOYMENT
)
pipeline_component_rest = pipeline_component._to_rest_object(location="eastus")
assert pipeline_component_rest.properties.deployment_configuration.settings == pipeline_component.settings
assert (
pipeline_component_rest.properties.deployment_configuration.component_id.asset_id
== pipeline_component.component
)
assert pipeline_component_rest.properties.description == pipeline_component.description
assert pipeline_component_rest.tags == pipeline_component.tags
assert pipeline_component_rest.location == "eastus"

def test_to_rest_object_for_component_obj(self) -> None:
pipeline_component = load_pipeline_component_batch_deployment(
TestPipelineComponentBatchDeployment.HELLO_BATCH_DEPLOYMENT
)

pipeline_component.component = PipelineComponent(
id=pipeline_component.component,
name="test_component",
description="component description",
tags={"tag1": "tag_value"},
)
pipeline_component_rest = pipeline_component._to_rest_object(location="eastus")

assert pipeline_component_rest.properties.deployment_configuration.settings == pipeline_component.settings
assert (
pipeline_component_rest.properties.deployment_configuration.component_id.asset_id
== pipeline_component.component.id
)
assert pipeline_component_rest.properties.deployment_configuration.tags == pipeline_component.component.tags
assert (
pipeline_component_rest.properties.deployment_configuration.description
== pipeline_component.component.description
)
assert pipeline_component_rest.properties.description == pipeline_component.description
assert pipeline_component_rest.tags == pipeline_component.tags
assert pipeline_component_rest.location == "eastus"

def test_to_dict(self) -> None:
pipeline_component = load_pipeline_component_batch_deployment(
TestPipelineComponentBatchDeployment.HELLO_BATCH_DEPLOYMENT,
params_override=[{"endpoint_name": "azureml:hello_batch2@latest"}],
)
pipeline_component_dict = pipeline_component._to_dict()
assert pipeline_component_dict["name"] == pipeline_component.name
assert pipeline_component_dict["tags"] == pipeline_component.tags
assert pipeline_component_dict["description"] == pipeline_component.description
assert pipeline_component_dict["endpoint_name"] == "azureml:hello_batch2@latest"
assert pipeline_component_dict["component"] == "azureml:hello_batch@latest"
assert pipeline_component_dict["settings"] == pipeline_component.settings

def test_from_rest_object(self) -> None:

with open(TestPipelineComponentBatchDeployment.HELLO_BATCH_DEPLOYMENT_REST, "r") as file:
pipeline_component_rest = RestBatchDeployment.from_dict(json.load(file))
pipeline_component_rest.properties.additional_properties = {
"deploymentConfiguration": {
"componentId": {"assetId": "azureml:hello_batch@latest"},
"settings": {"componentId": "azureml:hello_batch@latest"},
}
}
pipeline_component_from_rest = PipelineComponentBatchDeployment._from_rest_object(pipeline_component_rest)
assert pipeline_component_from_rest.component == "azureml:hello_batch@latest"
assert (
pipeline_component_from_rest.settings["componentId"]
== pipeline_component_rest.properties.additional_properties["deploymentConfiguration"]["componentId"][
"assetId"
]
)
assert (
pipeline_component_from_rest.component
== pipeline_component_rest.properties.additional_properties["deploymentConfiguration"]["componentId"][
"assetId"
]
)
assert pipeline_component_from_rest.endpoint_name == "achauhan-endpoint-name"
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"id": "/subscriptions/sub-id/resourceGroups/some-res-group/providers/Microsoft.MachineLearningServices/workspaces/some-ws/batchEndpoints/achauhan-endpoint-name/deployments/hello-world-1",
"name": "hello-world-1",
"type": "Microsoft.MachineLearningServices/workspaces/batchEndpoints/deployments",
"properties": {
"description": "some description",
"properties": {
"AzureAsyncOperationUri": "azure-operation"
},
"codeConfiguration": {
"codeId": "/subscriptions/sub-id/resourceGroups/some-rg/providers/Microsoft.MachineLearningServices/workspaces/some-ws/onlineEndpoints/some-endpoint/deployments/blue",
"scoringScript": "score.py"
},
"environmentId": "/subscriptions/sub-id/resourceGroups/some-rg/providers/Microsoft.MachineLearningServices/workspaces/some-ws/onlineEndpoints/some-endpoint/deployments/blue",
"environmentVariables": {},
"compute": "/subscriptions/sub-id/resourceGroups/some-rg/providers/Microsoft.MachineLearningServices/workspaces/some-ws/onlineEndpoints/some-endpoint/deployments/blue",
"errorThreshold": -1,
"retrySettings": {
"maxRetries": 3,
"timeout": "PT30S"
},
"miniBatchSize": 10,
"loggingLevel": "Info",
"model": {
"referenceType": "Id",
"assetId": "/subscriptions/sub-id/resourceGroups/some-rg/providers/Microsoft.MachineLearningServices/workspaces/some-ws/onlineEndpoints/some-endpoint/deployments/blue"
},
"maxConcurrencyPerInstance": 1,
"outputAction": "AppendRow",
"outputFileName": "predictions.csv",
"resources": {
"instanceCount": 1,
"instanceType": null,
"locations": null,
"properties": null
},
"provisioningState": "Succeeded"
},
"systemData": {
"createdAt": "2025-02-01T17:51:56.513702+00:00",
"createdBy": "some-one"
},
"tags": {
"tag1": "value1"
},
"location": "eastus",
"identity": {
"type": "SystemAssigned",
"userAssignedIdentities": {
"key": {
"principalId": "some-principalId",
"clientId": "some-clientId"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ max_concurrency_per_instance: 5
compute: "azureml:testCompute"
resources:
instance_count: 2
tags:
tag1: value1
tag2: value2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"id": "/subscriptions/sub-id/resourceGroups/some-res-group/providers/Microsoft.MachineLearningServices/workspaces/some-ws/batchEndpoints/achauhan-endpoint-name/deployments/hello-world-1",
"name":"hello-batch",
"description":"A batch pipeline component",
"properties":{
"deploymentConfiguration":{
"settings": {
"default_compute": "batch-cluster"
},
"tags": {
"tag1": "value1"
},
"componentId": "azureml:hello_batch@latest"
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$schema: https://azuremlschemas.azureedge.net/latest/pipelineComponentBatchDeployment.schema.json
name: hello-batch-dpl
endpoint_name: hello-pipeline-batch
description: "Batch deployment description"
type: pipeline
component: azureml:hello_batch@latest
settings:
default_compute: batch-cluster
tags:
tag1: value1
tag2: value2

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
name: blue
type: kubernetes
endpoint_name: mit-test-1
description: description for online deployment
model:
name: sklearn_regression_model
version: 10
path: ../model-1/model/sklearn_regression_model.pkl
code_configuration:
code: ../model-1/onlinescoring/
scoring_script: score.py
environment:
name: k8s-env
version: 3
image: mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu22.04:20230227.v1
conda_file: ../model-1/environment/conda.yml
instance_type: cpuinstance
liveness_probe:
initial_delay: 10
period: 10
timeout: 10
success_threshold: 1
failure_threshold: 1
readiness_probe:
initial_delay: 10
period: 10
timeout: 10
success_threshold: 1
failure_threshold: 1
scale_settings:
type: default
request_settings:
request_timeout_ms: 10000
max_concurrent_requests_per_instance: 2
max_queue_wait_ms: 1000
instance_count: 2
environment_variables:
env1: value1
tags:
tag1: value1
resources:
requests:
cpu: 1n
memory: 1Gi
gpu: 0n
limits:
cpu: 1n
memory: 1Gi
gpu: 0n
Loading