|
1 | 1 | from pathlib import Path |
2 | 2 |
|
3 | 3 | import pytest |
4 | | -from devtools_testutils import AzureRecordedTestCase |
5 | | -from test_utilities.utils import _PYTEST_TIMEOUT_METHOD, assert_job_cancel |
| 4 | +from azure.core.exceptions import ResourceNotFoundError |
6 | 5 |
|
7 | 6 | from azure.ai.ml import Input, MLClient, load_component, load_model |
8 | 7 | from azure.ai.ml.constants import AssetTypes |
9 | 8 | from azure.ai.ml.dsl import pipeline |
10 | | -from azure.core.exceptions import HttpResponseError, ResourceNotFoundError |
11 | | - |
| 9 | +from devtools_testutils import AzureRecordedTestCase, is_live |
| 10 | +from test_utilities.utils import _PYTEST_TIMEOUT_METHOD, assert_job_cancel |
12 | 11 | from .._util import _DSL_TIMEOUT_SECOND |
13 | 12 |
|
14 | 13 |
|
| 14 | +def assert_pipeline_job_cancel(client: MLClient, score_func, pipeline_model_input, pipeline_test_data): |
| 15 | + @pipeline |
| 16 | + def score_pipeline(model_input, test_data): |
| 17 | + score = score_func(model_input=model_input, test_data=test_data) # noqa: F841 |
| 18 | + score_duplicate = score_func(model_input=model_input, test_data=test_data) # noqa: F841 |
| 19 | + |
| 20 | + pipeline_job = score_pipeline(model_input=pipeline_model_input, test_data=pipeline_test_data) |
| 21 | + pipeline_job.settings.default_compute = "cpu-cluster" |
| 22 | + assert_job_cancel(pipeline_job, client) |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.skipif(condition=not is_live(), reason="registry test, may fail in playback mode") |
15 | 26 | @pytest.mark.usefixtures("enable_pipeline_private_preview_features", "recorded_test") |
16 | 27 | @pytest.mark.timeout(timeout=_DSL_TIMEOUT_SECOND, method=_PYTEST_TIMEOUT_METHOD) |
17 | 28 | @pytest.mark.e2etest |
18 | 29 | @pytest.mark.pipeline_test |
19 | 30 | class TestDSLPipelineOnRegistry(AzureRecordedTestCase): |
20 | | - @pytest.mark.skip(reason="not able to re-record") |
21 | | - def test_pipeline_job_create_with_registered_component_on_registry( |
22 | | - self, |
23 | | - registry_client: MLClient, |
24 | | - ) -> None: |
| 31 | + test_data = Input( |
| 32 | + type=AssetTypes.URI_FILE, |
| 33 | + path="./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv" |
| 34 | + ) |
| 35 | + |
| 36 | + def test_pipeline_job_create_with_registered_component_on_registry(self, pipelines_registry_client: MLClient): |
25 | 37 | local_component = load_component("./tests/test_configs/components/basic_component_code_local_path.yml") |
26 | 38 | try: |
27 | | - created_component = registry_client.components.get(local_component.name, version=local_component.version) |
28 | | - except HttpResponseError: |
29 | | - created_component = registry_client.components.create_or_update(local_component) |
| 39 | + created_component = pipelines_registry_client.components.get( |
| 40 | + local_component.name, version=local_component.version |
| 41 | + ) |
| 42 | + except ResourceNotFoundError: |
| 43 | + created_component = pipelines_registry_client.components.create_or_update(local_component) |
30 | 44 |
|
31 | | - @pipeline() |
| 45 | + @pipeline |
32 | 46 | def sample_pipeline(): |
33 | | - node = created_component() |
34 | | - node.compute = "cpu-cluster" |
| 47 | + created_component() |
35 | 48 |
|
36 | 49 | pipeline_job = sample_pipeline() |
37 | | - assert registry_client.jobs.validate(pipeline_job).passed |
38 | | - # TODO: add test for pipeline job create with registered component on registry after support is ready on canary |
39 | | - |
40 | | - @pytest.mark.skip(reason="request body still exits when re-record and will raise error " |
41 | | - "'Unable to find a record for the request' in playback mode") |
42 | | - def test_pipeline_with_local_component_and_registry_model_as_input(self, registry_client: MLClient, client: MLClient): |
43 | | - # get dataset |
44 | | - test_data = Input( |
45 | | - type=AssetTypes.URI_FILE, |
46 | | - path="./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv" |
47 | | - ) |
| 50 | + pipeline_job.settings.default_compute = "cpu-cluster" |
| 51 | + assert pipelines_registry_client.jobs.validate(pipeline_job).passed |
48 | 52 |
|
| 53 | + # this test will break in playback mode, so include it in live test only |
| 54 | + def test_pipeline_with_local_component_and_registry_model_as_input(self, client: MLClient): |
49 | 55 | # load_component |
50 | 56 | score_func = load_component("./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/score.yml") |
51 | 57 |
|
52 | 58 | pipeline_score_model = Input( |
53 | | - type='mlflow_model', |
54 | | - path='azureml://registries/testFeed/models/iris_model/versions/1' |
| 59 | + type="custom_model", path="azureml://registries/sdk-test/models/iris_model/versions/1" |
55 | 60 | ) |
56 | 61 |
|
57 | | - @pipeline() |
58 | | - def score_pipeline_with_registry_model(model_input, test_data): |
59 | | - score = score_func(model_input=model_input, test_data=test_data) |
60 | | - score_duplicate = score_func(model_input=pipeline_score_model, test_data=test_data) |
61 | | - |
62 | | - pipeline_job = score_pipeline_with_registry_model( |
63 | | - model_input=pipeline_score_model, |
64 | | - test_data=test_data |
65 | | - ) |
66 | | - pipeline_job.settings.default_compute = "cpu-cluster" |
67 | | - assert_job_cancel(pipeline_job, client) |
| 62 | + assert_pipeline_job_cancel(client, score_func, pipeline_score_model, self.test_data) |
68 | 63 |
|
69 | | - @pytest.mark.skip(reason="request body still exits when re-record and will raise error " |
70 | | - "'Unable to find a record for the request' in playback mode") |
71 | 64 | def test_pipeline_with_local_component_and_registry_model_as_input_with_model_input( |
72 | | - self, |
73 | | - registry_client: MLClient, |
74 | | - client: MLClient): |
75 | | - # get dataset |
76 | | - test_data = Input( |
77 | | - type=AssetTypes.URI_FILE, |
78 | | - path="./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv" |
79 | | - ) |
80 | | - |
| 65 | + self, client: MLClient, pipelines_registry_client: MLClient |
| 66 | + ): |
81 | 67 | # load_component |
82 | 68 | score_func = load_component("./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/score.yml") |
83 | 69 |
|
84 | 70 | model_path = Path("./tests/test_configs/model/model_iris.yml") |
85 | 71 | model_entity = load_model(model_path) |
86 | 72 | try: |
87 | | - pipeline_score_model = registry_client.models.get(name=model_entity.name, version=model_entity.version) |
| 73 | + pipeline_score_model = pipelines_registry_client.models.get( |
| 74 | + name=model_entity.name, version=model_entity.version |
| 75 | + ) |
88 | 76 | except ResourceNotFoundError: |
89 | | - model_entity = registry_client.models.create_or_update(model_entity) |
90 | | - pipeline_score_model = registry_client.models.get(name=model_entity.name, version=model_entity.version) |
| 77 | + model_entity = pipelines_registry_client.models.create_or_update(model_entity) |
| 78 | + pipeline_score_model = pipelines_registry_client.models.get( |
| 79 | + name=model_entity.name, version=model_entity.version |
| 80 | + ) |
91 | 81 |
|
92 | | - @pipeline() |
93 | | - def score_pipeline_with_registry_model(model_input, test_data): |
94 | | - score = score_func(model_input=model_input, test_data=test_data) |
95 | | - score_duplicate = score_func(model_input=pipeline_score_model, test_data=test_data) |
96 | | - |
97 | | - pipeline_job = score_pipeline_with_registry_model( |
98 | | - model_input=pipeline_score_model, test_data=test_data |
99 | | - ) |
100 | | - pipeline_job.settings.default_compute = "cpu-cluster" |
101 | | - assert_job_cancel(pipeline_job, client) |
102 | | - |
103 | | - @pytest.mark.skip(reason="request body still exits when re-record and will raise error " |
104 | | - "'Unable to find a record for the request' in playback mode") |
105 | | - def test_pipeline_with_registry_component_and_model_as_input(self, registry_client: MLClient, client: MLClient): |
106 | | - # get dataset |
107 | | - test_data = Input( |
108 | | - type=AssetTypes.URI_FILE, |
109 | | - path="./tests/test_configs/pipeline_jobs/job_with_registry_model_as_input/data/sample1.csv" |
110 | | - ) |
| 82 | + assert_pipeline_job_cancel(client, score_func, pipeline_score_model, self.test_data) |
111 | 83 |
|
| 84 | + def test_pipeline_with_registry_component_and_model_as_input( |
| 85 | + self, client: MLClient, pipelines_registry_client: MLClient |
| 86 | + ): |
112 | 87 | # load_component |
113 | | - score_component_name = "v2_dsl_score_component" |
114 | | - component_version = "0.0.8" |
115 | | - score_func = registry_client.components.get( |
| 88 | + score_component_name, component_version = "score_component", "2" |
| 89 | + score_func = pipelines_registry_client.components.get( |
116 | 90 | name=score_component_name, version=component_version |
117 | 91 | ) |
118 | 92 |
|
119 | 93 | pipeline_score_model = Input( |
120 | | - type='mlflow_model', |
121 | | - path='azureml://registries/testFeed/models/iris_model/versions/1' |
| 94 | + type="mlflow_model", path="azureml://registries/sdk-test/models/iris_model/versions/1" |
122 | 95 | ) |
123 | 96 |
|
124 | | - @pipeline() |
125 | | - def score_pipeline_with_registry_model(model_input, test_data): |
126 | | - score = score_func(model_input=model_input, test_data=test_data) |
127 | | - score_duplicate = score_func(model_input=pipeline_score_model, test_data=test_data) |
128 | | - |
129 | | - pipeline_job = score_pipeline_with_registry_model( |
130 | | - model_input=pipeline_score_model, |
131 | | - test_data=test_data |
132 | | - ) |
133 | | - pipeline_job.settings.default_compute = "cpu-cluster" |
134 | | - assert_job_cancel(pipeline_job, client) |
| 97 | + assert_pipeline_job_cancel(client, score_func, pipeline_score_model, self.test_data) |
0 commit comments