Skip to content

Commit a175685

Browse files
authored
fix deployment creation when registry model is used (Azure#40577)
* fix deployment using model from registry * update recordings * update changelog * fix code formatting * fix deployment using model from registry
1 parent 8fb5a96 commit a175685

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

sdk/ml/azure-ai-ml/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
### Bugs Fixed
55
- Fix for compute Instance, disableLocalAuth property should be depend on ssh public access enabled.
66
- Removing Git-related properties from job properties if a PAT token is detected in the repository URL.
7+
- Fix deployment creation for registry models
78

89
### Other Changes
910
- Hub and Project are officially GA'd and no longer experimental.

sdk/ml/azure-ai-ml/assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "python",
44
"TagPrefix": "python/ml/azure-ai-ml",
5-
"Tag": "python/ml/azure-ai-ml_9b9dd0f330"
5+
"Tag": "python/ml/azure-ai-ml_53a7a4a178"
66
}

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_operation_orchestrator.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def _get_environment_arm_id(self, environment: Environment, register_asset: bool
332332

333333
def _get_model_arm_id(self, model: Model, register_asset: bool = True) -> Union[str, Model]:
334334
try:
335-
self._validate_datastore_name(model.path)
335+
if not is_registry_id_for_resource(model.id):
336+
self._validate_datastore_name(model.path)
336337

337338
if register_asset:
338339
if model.id:

sdk/ml/azure-ai-ml/tests/conftest.py

+12
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,18 @@ def data_asset_registry_client(e2e_ws_scope: OperationScope, auth: ClientSecretC
473473
)
474474

475475

476+
@pytest.fixture
477+
def sdkv2_registry_client(e2e_ws_scope: OperationScope, auth: ClientSecretCredential) -> MLClient:
478+
"""return a machine learning client using default e2e testing workspace"""
479+
return MLClient(
480+
credential=auth,
481+
subscription_id=e2e_ws_scope.subscription_id,
482+
resource_group_name=e2e_ws_scope.resource_group_name,
483+
logging_enable=getenv(E2E_TEST_LOGGING_ENABLED),
484+
registry_name="sdkv2-testFeed",
485+
)
486+
487+
476488
@pytest.fixture
477489
def only_registry_client(e2e_ws_scope: OperationScope, auth: ClientSecretCredential) -> MLClient:
478490
"""return a machine learning client using default e2e testing workspace"""

sdk/ml/azure-ai-ml/tests/online_services/e2etests/test_online_deployment.py

+50-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import pytest
44
from devtools_testutils import AzureRecordedTestCase
5-
6-
from azure.ai.ml import MLClient, load_online_deployment, load_online_endpoint
5+
from pathlib import Path
6+
from azure.ai.ml import MLClient, load_online_deployment, load_online_endpoint, load_model
77
from azure.ai.ml.entities import ManagedOnlineDeployment, ManagedOnlineEndpoint, Model, CodeConfiguration, Environment
88

99

@@ -50,6 +50,54 @@ def test_online_deployment_create(
5050
finally:
5151
client.online_endpoints.begin_delete(name=endpoint.name)
5252

53+
def test_online_deployment_create_when_registry_assets(
54+
self,
55+
sdkv2_registry_client: MLClient,
56+
client: MLClient,
57+
randstr: Callable[[], str],
58+
rand_online_name: Callable[[], str],
59+
rand_online_deployment_name: Callable[[], str],
60+
) -> None:
61+
# create a model in registry
62+
model_name = randstr("test-registry-model")
63+
model = Model(name=model_name, path="./tests/test_configs/deployments/model-1/model")
64+
model = sdkv2_registry_client.models.create_or_update(model)
65+
assert model.name == model_name
66+
67+
# create a endpoint
68+
endpoint_yaml = "tests/test_configs/deployments/online/simple_online_endpoint_mir.yaml"
69+
endpoint = load_online_endpoint(endpoint_yaml)
70+
endpoint_name = rand_online_name("endpoint_name")
71+
endpoint.name = endpoint_name
72+
endpoint = client.online_endpoints.begin_create_or_update(endpoint).result()
73+
assert endpoint.name == endpoint_name
74+
75+
# create a deployment
76+
deployment_yaml = "tests/test_configs/deployments/online/online_deployment_1.yaml"
77+
deployment = load_online_deployment(deployment_yaml)
78+
deployment.endpoint_name = endpoint.name
79+
deployment.name = rand_online_deployment_name("deployment_name")
80+
deployment.model = model
81+
82+
try:
83+
client.online_deployments.begin_create_or_update(deployment).result()
84+
dep = client.online_deployments.get(name=deployment.name, endpoint_name=endpoint.name)
85+
assert dep.name == deployment.name
86+
87+
deps = client.online_deployments.list(endpoint_name=endpoint.name)
88+
assert len(list(deps)) > 0
89+
90+
endpoint.traffic = {deployment.name: 100}
91+
client.online_endpoints.begin_create_or_update(endpoint).result()
92+
endpoint_updated = client.online_endpoints.get(endpoint.name)
93+
assert endpoint_updated.traffic[deployment.name] == 100
94+
client.online_endpoints.invoke(
95+
endpoint_name=endpoint.name,
96+
request_file="tests/test_configs/deployments/model-1/sample-request.json",
97+
)
98+
finally:
99+
client.online_endpoints.begin_delete(name=endpoint.name)
100+
53101
def test_online_deployment_update(
54102
self, client: MLClient, rand_online_name: Callable[[], str], rand_online_deployment_name: Callable[[], str]
55103
) -> None:

0 commit comments

Comments
 (0)