Skip to content

Commit 557850a

Browse files
authored
[ml] Update miscellaneous ref docs (Azure#31057)
* Update job operations docstrings * Update MLClient docstring * Rename auth samples file and update README * Update docstrings and add examples for mlclient, load functions, asset, model, input/output * Update CodeConfiguration, DistributionType docstrings * Update docstrings and add examples and exclude samples from interrogate * Update workspace info * Add comment to pyproject.toml interrogate section * Update docstrings and increase interrogate threshold to 75% * Update docstrings and add examples * Update docstrings and add examples * Address formatting issues * Address formatting issues * Update docstrings and add examples * Address formatting issues * Fix paths to examples to relative and add note to samples README * Update docstrings per comments * Make another pass to get missed formatting issues and address comments * Remove :class: tip from admonition * Address docstring- formatting warnings from azure-pylint-guidelines-checker
1 parent 1b7f597 commit 557850a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2790
-1854
lines changed

sdk/ml/azure-ai-ml/.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ repos:
1010
hooks:
1111
- id: interrogate
1212
types_or: [python]
13-
exclude: ^(sdk/ml/azure-ai-ml/tests/|sdk/ml/azure-ai-ml/scripts/|sdk/ml/azure-ai-ml/azure/ai/ml/_restclient|sdk/ml/azure-ai-ml/setup.py)
13+
args: [--ignore-init-method, --ignore-private, --ignore-semiprivate, --ignore-magic]
14+
exclude: ^(sdk/ml/azure-ai-ml/tests/|sdk/ml/azure-ai-ml/samples/|sdk/ml/azure-ai-ml/scripts/|sdk/ml/azure-ai-ml/azure/ai/ml/_restclient|sdk/ml/azure-ai-ml/setup.py)
1415
# exclude defined here because exclude in pyproject.toml is not being respected
1516
- repo: https://github.com/streetsidesoftware/cspell-cli
1617
rev: v6.31.0

sdk/ml/azure-ai-ml/azure/ai/ml/_ml_client.py

Lines changed: 136 additions & 123 deletions
Large diffs are not rendered by default.

sdk/ml/azure-ai-ml/azure/ai/ml/constants/_assets.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# ---------------------------------------------------------
44
from enum import Enum
55

6-
from azure.ai.ml._utils._experimental import experimental
76
from azure.core import CaseInsensitiveEnumMeta
87

8+
from azure.ai.ml._utils._experimental import experimental
9+
910

1011
@experimental
1112
class IPProtectionLevel(str, Enum, metaclass=CaseInsensitiveEnumMeta):
13+
"Intellectual property protection level."
1214
ALL = "all"
1315
NONE = "none"

sdk/ml/azure-ai-ml/azure/ai/ml/constants/_job/automl.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
from enum import Enum
55

66
# pylint: disable=unused-import
7-
from azure.ai.ml._restclient.v2023_04_01_preview.models import (
8-
NlpLearningRateScheduler,
9-
TrainingMode,
10-
)
7+
from azure.ai.ml._restclient.v2023_04_01_preview.models import NlpLearningRateScheduler, TrainingMode
118
from azure.ai.ml._utils._experimental import experimental
129

1310

@@ -95,7 +92,8 @@ class ImageInstanceSegmentationModelNames(Enum):
9592

9693

9794
class NlpModels(Enum):
98-
# Model names for NLP tasks.
95+
"""Model names that are supported for NLP (Natural Language Processing) tasks."""
96+
9997
BERT_BASE_CASED = "bert-base-cased"
10098
BERT_BASE_UNCASED = "bert-base-uncased"
10199
BERT_BASE_MULTILINGUAL_CASED = "bert-base-multilingual-cased"

sdk/ml/azure-ai-ml/azure/ai/ml/constants/_registry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010

1111
class StorageAccountType(str, Enum, metaclass=CaseInsensitiveEnumMeta):
12+
"""Storage account types."""
13+
1214
STANDARD_LRS = "Standard_LRS".lower()
1315
STANDARD_GRS = "Standard_GRS".lower()
1416
STANDARD_RAGRS = "Standard_RAGRS".lower()
@@ -21,6 +23,8 @@ class StorageAccountType(str, Enum, metaclass=CaseInsensitiveEnumMeta):
2123

2224
# When will other values be allowed?
2325
class AcrAccountSku(str, Enum, metaclass=CaseInsensitiveEnumMeta):
26+
"""Azure Container Registry SKUs."""
27+
2428
PREMIUM = "Premium".lower()
2529

2630

sdk/ml/azure-ai-ml/azure/ai/ml/dsl/_pipeline_decorator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def pipeline(
8383
:type kwargs: dict
8484
8585
.. admonition:: Example:
86-
:class: tip
86+
8787
.. literalinclude:: ../../../../samples/ml_samples_pipeline_job_configurations.py
8888
:start-after: [START configure_pipeline]
8989
:end-before: [END configure_pipeline]

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/_artifacts/_package/model_package.py

Lines changed: 62 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,38 @@
66

77
from os import PathLike
88
from pathlib import Path
9-
from typing import IO, AnyStr, List, Dict, Optional, Union
10-
11-
12-
from azure.ai.ml._restclient.v2023_02_01_preview.models import (
13-
PackageRequest,
14-
PackageResponse,
15-
ModelPackageInput as RestModelPackageInput,
16-
PackageInputPathId as RestPackageInputPathId,
17-
PackageInputPathVersion as RestPackageInputPathVersion,
18-
PackageInputPathUrl as RestPackageInputPathUrl,
19-
CodeConfiguration,
20-
)
21-
22-
from azure.ai.ml.entities._resource import Resource
9+
from typing import IO, AnyStr, Dict, List, Optional, Union
10+
11+
from azure.ai.ml._restclient.v2023_02_01_preview.models import CodeConfiguration
12+
from azure.ai.ml._restclient.v2023_02_01_preview.models import ModelPackageInput as RestModelPackageInput
13+
from azure.ai.ml._restclient.v2023_02_01_preview.models import PackageInputPathId as RestPackageInputPathId
14+
from azure.ai.ml._restclient.v2023_02_01_preview.models import PackageInputPathUrl as RestPackageInputPathUrl
15+
from azure.ai.ml._restclient.v2023_02_01_preview.models import PackageInputPathVersion as RestPackageInputPathVersion
16+
from azure.ai.ml._restclient.v2023_02_01_preview.models import PackageRequest, PackageResponse
2317
from azure.ai.ml._schema.assets.package.model_package import ModelPackageSchema
24-
from azure.ai.ml.entities._util import load_from_dict
25-
from azure.ai.ml.constants._common import (
26-
BASE_PATH_CONTEXT_KEY,
27-
PARAMS_OVERRIDE_KEY,
28-
)
29-
from azure.ai.ml._utils.utils import snake_to_pascal, dump_yaml_to_file
3018
from azure.ai.ml._utils._experimental import experimental
31-
from .model_configuration import ModelConfiguration
32-
from .inferencing_server import AzureMLOnlineInferencingServer, AzureMLBatchInferencingServer
19+
from azure.ai.ml._utils.utils import dump_yaml_to_file, snake_to_pascal
20+
from azure.ai.ml.constants._common import BASE_PATH_CONTEXT_KEY, PARAMS_OVERRIDE_KEY
21+
from azure.ai.ml.entities._resource import Resource
22+
from azure.ai.ml.entities._util import load_from_dict
23+
3324
from .base_environment_source import BaseEnvironment
25+
from .inferencing_server import AzureMLBatchInferencingServer, AzureMLOnlineInferencingServer
26+
from .model_configuration import ModelConfiguration
3427

3528

3629
@experimental
3730
class PackageInputPathId:
31+
"""Package input path specified with a resource ID.
3832
39-
"""Package input path specified with a resource id.
40-
41-
:param input_path_type: The type of the input path. Possible values include: "Url", "PathId", "PathVersion".
42-
:type input_path_type: str
43-
:param resource_id: The resource id of the input path. e.g. azureml://subscriptions/<>/resourceGroups/
44-
<>/providers/Microsoft.MachineLearningServices/workspaces/<>/data/<>/versions/<>
45-
:type resource_id: str
33+
:param input_path_type: The type of the input path. Accepted values are "Url", "PathId", and "PathVersion".
34+
:type input_path_type: Optional[str]
35+
:param resource_id: The resource ID of the input path. e.g. "azureml://subscriptions/<>/resourceGroups/
36+
<>/providers/Microsoft.MachineLearningServices/workspaces/<>/data/<>/versions/<>".
37+
:type resource_id: Optional[str]
4638
"""
4739

48-
def __init__(self, *, input_path_type: Optional[str] = None, resource_id: Optional[str] = None):
40+
def __init__(self, *, input_path_type: Optional[str] = None, resource_id: Optional[str] = None) -> None:
4941
self.input_path_type = input_path_type
5042
self.resource_id = resource_id
5143

@@ -67,12 +59,12 @@ def _from_rest_object(cls, package_input_path_id_rest_object: RestPackageInputPa
6759
class PackageInputPathVersion:
6860
"""Package input path specified with a resource name and version.
6961
70-
:param input_path_type: The type of the input path. Possible values include: "Url", "PathId", "PathVersion".
71-
:type input_path_type: str
62+
:param input_path_type: The type of the input path. Accepted values are "Url", "PathId", and "PathVersion".
63+
:type input_path_type: Optional[str]
7264
:param resource_name: The resource name of the input path.
73-
:type resource_name: str
65+
:type resource_name: Optional[str]
7466
:param resource_version: The resource version of the input path.
75-
:type resource_version: str
67+
:type resource_version: Optional[str]
7668
"""
7769

7870
def __init__(
@@ -81,7 +73,7 @@ def __init__(
8173
input_path_type: Optional[str] = None,
8274
resource_name: Optional[str] = None,
8375
resource_version: Optional[str] = None,
84-
):
76+
) -> None:
8577
self.input_path_type = input_path_type
8678
self.resource_name = resource_name
8779
self.resource_version = resource_version
@@ -108,14 +100,14 @@ def _from_rest_object(
108100
class PackageInputPathUrl:
109101
"""Package input path specified with a url.
110102
111-
:param input_path_type: The type of the input path. Possible values include: "Url", "PathId", "PathVersion".
112-
:type input_path_type: str
113-
:param url: The url of the input path. e.g. azureml://subscriptions/<>/resourceGroups/
114-
<>/providers/Microsoft.MachineLearningServices/workspaces/data/<>/versions/<>
115-
:type url: str
103+
:param input_path_type: The type of the input path. Accepted values are "Url", "PathId", and "PathVersion".
104+
:type input_path_type: Optional[str]
105+
:param url: The url of the input path. e.g. "azureml://subscriptions/<>/resourceGroups/
106+
<>/providers/Microsoft.MachineLearningServices/workspaces/data/<>/versions/<>".
107+
:type url: Optional[str]
116108
"""
117109

118-
def __init__(self, *, input_path_type: Optional[str] = None, url: Optional[str] = None):
110+
def __init__(self, *, input_path_type: Optional[str] = None, url: Optional[str] = None) -> None:
119111
self.input_path_type = input_path_type
120112
self.url = url
121113

@@ -138,14 +130,14 @@ class ModelPackageInput:
138130
"""Model package input.
139131
140132
:param type: The type of the input.
141-
:type type: str
133+
:type type: Optional[str]
142134
:param path: The path of the input.
143-
:type path: azure.ai.ml.entities.PackageInputPathId
144-
or azure.ai.ml.entities.PackageInputPathUrl or azure.ai.ml.entities.PackageInputPathVersion
145-
:param mode: The mode of the input.
146-
:type mode: str
147-
:param mount_path: The mount path of the input.
148-
:type mount_path: str
135+
:type path: Optional[Union[~azure.ai.ml.entities.PackageInputPathId, ~azure.ai.ml.entities.PackageInputPathUrl,
136+
~azure.ai.ml.entities.PackageInputPathVersion]]
137+
:param mode: The input mode.
138+
:type mode: Optional[str]
139+
:param mount_path: The mount path for the input.
140+
:type mount_path: Optional[str]
149141
"""
150142

151143
def __init__(
@@ -155,7 +147,7 @@ def __init__(
155147
path: Optional[Union[PackageInputPathId, PackageInputPathUrl, PackageInputPathVersion]] = None,
156148
mode: Optional[str] = None,
157149
mount_path: Optional[str] = None,
158-
):
150+
) -> None:
159151
self.type = type
160152
self.path = path
161153
self.mode = mode
@@ -183,22 +175,23 @@ def _from_rest_object(cls, model_package_input_rest_object: RestModelPackageInpu
183175
class ModelPackage(Resource, PackageRequest):
184176
"""Model package.
185177
186-
:param target_environment_name: The name of the model package.
178+
:param target_environment_name: The target environment name for the model package.
187179
:type target_environment_name: str
188180
:param inferencing_server: The inferencing server of the model package.
189-
:type inferencing_server: azure.ai.ml.entities.InferencingServer
181+
:type inferencing_server: Union[~azure.ai.ml.entities.AzureMLOnlineInferencingServer,
182+
~azure.ai.ml.entities.AzureMLBatchInferencingServer]
190183
:param base_environment_source: The base environment source of the model package.
191-
:type base_environment_source: azure.ai.ml.entities.BaseEnvironmentSource
184+
:type base_environment_source: Optional[~azure.ai.ml.entities.BaseEnvironment]
192185
:param target_environment_version: The version of the model package.
193-
:type target_environment_version: str
186+
:type target_environment_version: Optional[str]
194187
:param environment_variables: The environment variables of the model package.
195-
:type environment_variables: dict
188+
:type environment_variables: Optional[dict[str, str]]
196189
:param inputs: The inputs of the model package.
197-
:type inputs: list[azure.ai.ml.entities.ModelPackageInput]
198-
:param model_configuration: The model configuration of the model package.
199-
:type model_configuration: azure.ai.ml.entities.ModelConfiguration
190+
:type inputs: Optional[list[~azure.ai.ml.entities.ModelPackageInput]]
191+
:param model_configuration: The model configuration.
192+
:type model_configuration: Optional[~azure.ai.ml.entities.ModelConfiguration]
200193
:param tags: The tags of the model package.
201-
:type tags: dict
194+
:type tags: Optiona[dict[str, str]]
202195
"""
203196

204197
def __init__(
@@ -212,7 +205,7 @@ def __init__(
212205
inputs: Optional[List[ModelPackageInput]] = None,
213206
model_configuration: Optional[ModelConfiguration] = None,
214207
tags: Optional[Dict[str, str]] = None,
215-
):
208+
) -> None:
216209
super().__init__(
217210
name=target_environment_name,
218211
target_environment_name=target_environment_name,
@@ -246,12 +239,16 @@ def dump(
246239
dest: Union[str, PathLike, IO[AnyStr]],
247240
**kwargs, # pylint: disable=unused-argument
248241
) -> None:
249-
"""Dump the model package spec into a file in yaml format.
250-
251-
:param dest: Either
252-
* A path to a local file
253-
* A writeable file-like object
254-
:type dest: Union[str, PathLike, IO[AnyStr]]
242+
"""Dumps the job content into a file in YAML format.
243+
244+
:param dest: The local path or file stream to write the YAML content to.
245+
If dest is a file path, a new file will be created.
246+
If dest is an open file, the file will be written to directly.
247+
:type dest: Union[PathLike, str, IO[AnyStr]]
248+
:param kwargs: Additional arguments to pass to the YAML serializer.
249+
:type kwargs: Optional[dict]
250+
:raises FileExistsError: Raised if dest is a file path and the file already exists.
251+
:raises IOError: Raised if dest is an open file and the file is not writable.
255252
"""
256253
yaml_serialized = self._to_dict()
257254
dump_yaml_to_file(dest, yaml_serialized, default_flow_style=False)

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/_artifacts/model.py

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,50 @@
2222
AssetTypes,
2323
)
2424
from azure.ai.ml.entities._assets import Artifact
25+
from azure.ai.ml.entities._assets.intellectual_property import IntellectualProperty
2526
from azure.ai.ml.entities._system_data import SystemData
2627
from azure.ai.ml.entities._util import get_md5_string, load_from_dict
27-
from azure.ai.ml.entities._assets.intellectual_property import IntellectualProperty
2828

2929
from .artifact import ArtifactStorageInfo
3030

3131

3232
class Model(Artifact): # pylint: disable=too-many-instance-attributes
3333
"""Model for training and scoring.
3434
35-
:param name: Name of the resource.
36-
:type name: str
37-
:param version: Version of the resource.
38-
:type version: str
39-
:param type: The storage format for this entity. Used for NCD. Possible values include:
40-
"custom_model", "mlflow_model", "triton_model".
41-
:type type: str
42-
:param utc_time_created: Date and time when the model was created, in
43-
UTC ISO 8601 format. (e.g. '2020-10-19 17:44:02.096572')
44-
:type utc_time_created: str
45-
:param flavors: The flavors in which the model can be interpreted.
46-
e.g. {sklearn: {sklearn_version: 0.23.2}, python_function: {loader_module: office.plrmodel, python_version: 3.6}
47-
:type flavors: Dict[str, Any]
48-
:param path: A remote uri or a local path pointing at a model.
49-
Example: "azureml://subscriptions/{}/resourcegroups/{}/workspaces/{}/datastores/{}/paths/path_on_datastore/"
50-
:type path: str
51-
:param description: Description of the resource.
52-
:type description: str
53-
:param tags: Tag dictionary. Tags can be added, removed, and updated.
54-
:type tags: dict[str, str]
55-
:param properties: The asset property dictionary.
56-
:type properties: dict[str, str]
57-
:param stage: The stage of the resource.
58-
:type stage: str
35+
:param name: The name of the model. Defaults to a random GUID.
36+
:type name: Optional[str]
37+
:param version: The version of the model. Defaults to "1" if either no name or an unregistered name is provided.
38+
Otherwise, defaults to autoincrement from the last registered version of the model with that name.
39+
:type version: Optional[str]
40+
:param type: The storage format for this entity, used for NCD (Novel Class Discovery). Accepted values are
41+
"custom_model", "mlflow_model", or "triton_model". Defaults to "custom_model".
42+
:type type: Optional[str]
43+
:param utc_time_created: The date and time when the model was created, in
44+
UTC ISO 8601 format. (e.g. '2020-10-19 17:44:02.096572').
45+
:type utc_time_created: Optional[str]
46+
:param flavors: The flavors in which the model can be interpreted. Defaults to None.
47+
:type flavors: Optional[dict[str, Any]]
48+
:param path: A remote uri or a local path pointing to a model. Defaults to None.
49+
:type path: Optional[str]
50+
:param description: The description of the resource. Defaults to None
51+
:type description: Optional[str]
52+
:param tags: Tag dictionary. Tags can be added, removed, and updated. Defaults to None.
53+
:type tags: Optional[dict[str, str]]
54+
:param properties: The asset property dictionary. Defaults to None.
55+
:type properties: Optional[dict[str, str]]
56+
:param stage: The stage of the resource. Defaults to None.
57+
:type stage: Optional[str]
5958
:param kwargs: A dictionary of additional configuration parameters.
60-
:type kwargs: dict
59+
:type kwargs: Optional[dict]
60+
61+
.. admonition:: Example:
62+
63+
.. literalinclude:: ../../../../../../samples/ml_samples_misc.py
64+
:start-after: [START model_entity_create]
65+
:end-before: [END model_entity_create]
66+
:language: python
67+
:dedent: 8
68+
:caption: Creating a Model object.
6169
"""
6270

6371
def __init__(
@@ -74,7 +82,7 @@ def __init__(
7482
properties: Optional[Dict] = None,
7583
stage: Optional[str] = None,
7684
**kwargs,
77-
):
85+
) -> None:
7886
self.job_name = kwargs.pop("job_name", None)
7987
self._intellectual_property = kwargs.pop("intellectual_property", None)
8088
super().__init__(

0 commit comments

Comments
 (0)