0
# Azure AI ML
1
2
Microsoft Azure Machine Learning Client Library for Python providing comprehensive SDK for ML workflows including job execution, pipeline components, model deployment, and AutoML capabilities. The SDK v2 introduces a unified object model that ensures consistency across different ML operations, supports local and cloud-based execution, provides built-in telemetry and monitoring, and integrates seamlessly with Azure Identity for authentication.
3
4
## Package Information
5
6
- **Package Name**: azure-ai-ml
7
- **Language**: Python
8
- **Installation**: `pip install azure-ai-ml`
9
10
## Core Imports
11
12
```python
13
from azure.ai.ml import MLClient
14
```
15
16
Common imports for working with Azure ML:
17
18
```python
19
from azure.ai.ml import MLClient, command, spark, Input, Output
20
from azure.ai.ml import (
21
MpiDistribution,
22
PyTorchDistribution,
23
TensorFlowDistribution,
24
RayDistribution
25
)
26
from azure.ai.ml.entities import (
27
CommandJob,
28
SparkJob,
29
Model,
30
Environment,
31
Data,
32
Component,
33
Workspace,
34
BatchEndpoint,
35
OnlineEndpoint
36
)
37
```
38
39
## Basic Usage
40
41
```python
42
from azure.ai.ml import MLClient
43
from azure.identity import DefaultAzureCredential
44
45
# Create ML client
46
ml_client = MLClient(
47
credential=DefaultAzureCredential(),
48
subscription_id="your-subscription-id",
49
resource_group_name="your-resource-group",
50
workspace_name="your-workspace"
51
)
52
53
# Submit a simple command job
54
from azure.ai.ml import command
55
from azure.ai.ml.entities import Environment
56
57
job = command(
58
code="./src",
59
command="python train.py --learning_rate ${{inputs.learning_rate}}",
60
inputs={"learning_rate": 0.01},
61
environment=Environment(
62
image="mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest"
63
),
64
compute="cpu-cluster"
65
)
66
67
submitted_job = ml_client.jobs.create_or_update(job)
68
print(f"Job submitted: {submitted_job.name}")
69
```
70
71
## Architecture
72
73
The Azure AI ML SDK is built around a unified object model with several key components:
74
75
- **MLClient**: Central client for all Azure ML operations, organizing functionality into operation groups
76
- **Entities**: Data classes representing Azure ML resources (jobs, models, endpoints, compute, etc.)
77
- **Operations**: Classes containing logic to interact with backend services for different resource types
78
- **Builders**: Functions like `command()`, `spark()` for creating job configurations
79
- **Assets**: Reusable resources like data, models, environments, and components
80
- **AutoML**: Automated machine learning capabilities for tabular, image, and NLP tasks
81
82
The SDK supports both imperative programming through direct API calls and declarative approaches through YAML-based configurations, enabling flexible workflows for different use cases.
83
84
## Capabilities
85
86
### Client and Authentication
87
88
Main client class for Azure Machine Learning operations with authentication and workspace management capabilities.
89
90
```python { .api }
91
class MLClient:
92
def __init__(
93
self,
94
credential,
95
subscription_id: str = None,
96
resource_group_name: str = None,
97
workspace_name: str = None,
98
**kwargs
99
): ...
100
```
101
102
[Client and Authentication](./client-auth.md)
103
104
### Job Management
105
106
Comprehensive job execution capabilities including command jobs, pipeline jobs, Spark jobs, sweep jobs for hyperparameter tuning, and AutoML jobs for automated machine learning.
107
108
```python { .api }
109
def command(
110
*,
111
code: str = None,
112
command: str,
113
inputs: dict = None,
114
outputs: dict = None,
115
environment: Environment = None,
116
compute: str = None,
117
**kwargs
118
) -> CommandJob: ...
119
120
def spark(
121
*,
122
code: str,
123
entry: SparkJobEntry,
124
compute: str,
125
inputs: dict = None,
126
outputs: dict = None,
127
**kwargs
128
) -> SparkJob: ...
129
130
class CommandJob:
131
def __init__(
132
self,
133
*,
134
command: str,
135
code: str = None,
136
inputs: dict = None,
137
outputs: dict = None,
138
environment: Environment = None,
139
compute: str = None,
140
**kwargs
141
): ...
142
```
143
144
[Job Management](./job-management.md)
145
146
### Model Deployment
147
148
Online and batch deployment capabilities for model inference with comprehensive endpoint and deployment management.
149
150
```python { .api }
151
class OnlineEndpoint:
152
def __init__(
153
self,
154
*,
155
name: str,
156
auth_mode: str = "key",
157
description: str = None,
158
tags: dict = None,
159
**kwargs
160
): ...
161
162
class ManagedOnlineDeployment:
163
def __init__(
164
self,
165
*,
166
name: str,
167
endpoint_name: str,
168
model: Model,
169
environment: Environment = None,
170
code_configuration: CodeConfiguration = None,
171
instance_type: str = "Standard_DS3_v2",
172
instance_count: int = 1,
173
**kwargs
174
): ...
175
```
176
177
[Model Deployment](./model-deployment.md)
178
179
### Asset Management
180
181
Comprehensive asset management for models, data, environments, and components with versioning and lineage tracking.
182
183
```python { .api }
184
class Model:
185
def __init__(
186
self,
187
*,
188
name: str,
189
path: str = None,
190
version: str = None,
191
description: str = None,
192
tags: dict = None,
193
**kwargs
194
): ...
195
196
class Data:
197
def __init__(
198
self,
199
*,
200
name: str,
201
path: str = None,
202
version: str = None,
203
type: str = "uri_folder",
204
description: str = None,
205
**kwargs
206
): ...
207
```
208
209
[Asset Management](./asset-management.md)
210
211
### Compute Management
212
213
Compute resource management including Azure ML compute clusters, compute instances, and attached compute resources.
214
215
```python { .api }
216
class AmlCompute:
217
def __init__(
218
self,
219
*,
220
name: str,
221
type: str = "amlcompute",
222
size: str,
223
min_instances: int = 0,
224
max_instances: int = 1,
225
idle_time_before_scale_down: int = 1800,
226
**kwargs
227
): ...
228
229
class ComputeInstance:
230
def __init__(
231
self,
232
*,
233
name: str,
234
size: str,
235
**kwargs
236
): ...
237
```
238
239
[Compute Management](./compute-management.md)
240
241
### AutoML
242
243
Automated machine learning capabilities for tabular data (classification, regression, forecasting), computer vision tasks (image classification, object detection), and natural language processing.
244
245
```python { .api }
246
def classification(
247
*,
248
target_column_name: str,
249
training_data: Data,
250
validation_data: Data = None,
251
test_data: Data = None,
252
primary_metric: str = "accuracy",
253
**kwargs
254
) -> ClassificationJob: ...
255
256
def regression(
257
*,
258
target_column_name: str,
259
training_data: Data,
260
validation_data: Data = None,
261
test_data: Data = None,
262
primary_metric: str = "normalized_root_mean_squared_error",
263
**kwargs
264
) -> RegressionJob: ...
265
266
def forecasting(
267
*,
268
target_column_name: str,
269
time_column_name: str,
270
training_data: Data,
271
validation_data: Data = None,
272
test_data: Data = None,
273
primary_metric: str = "normalized_root_mean_squared_error",
274
**kwargs
275
) -> ForecastingJob: ...
276
277
def image_classification(
278
*,
279
target_column_name: str,
280
training_data: Data,
281
validation_data: Data = None,
282
primary_metric: str = "accuracy",
283
**kwargs
284
) -> ImageClassificationJob: ...
285
286
def text_classification(
287
*,
288
target_column_name: str,
289
training_data: Data,
290
validation_data: Data = None,
291
primary_metric: str = "accuracy",
292
**kwargs
293
) -> TextClassificationJob: ...
294
```
295
296
[AutoML](./automl.md)
297
298
### Hyperparameter Tuning
299
300
Advanced hyperparameter optimization with various search spaces, sampling algorithms, and early termination policies.
301
302
```python { .api }
303
class Choice:
304
def __init__(self, values: list): ...
305
306
class Uniform:
307
def __init__(self, min_value: float, max_value: float): ...
308
309
class SweepJob:
310
def __init__(
311
self,
312
*,
313
trial: CommandJob,
314
search_space: dict,
315
objective: Objective,
316
sampling_algorithm: SamplingAlgorithm = None,
317
**kwargs
318
): ...
319
```
320
321
[Hyperparameter Tuning](./hyperparameter-tuning.md)
322
323
### Workspace and Registry Management
324
325
Workspace operations, registry management, and workspace connections for external services.
326
327
```python { .api }
328
class Workspace:
329
def __init__(
330
self,
331
*,
332
name: str,
333
description: str = None,
334
tags: dict = None,
335
location: str = None,
336
**kwargs
337
): ...
338
339
class Registry:
340
def __init__(
341
self,
342
*,
343
name: str,
344
location: str,
345
**kwargs
346
): ...
347
```
348
349
Note: Workspace management, pipelines/components, data management, feature store, and monitoring capabilities are also available through the MLClient operation groups. Refer to the API reference notes for complete details.
350
351
## Types
352
353
```python { .api }
354
class Input:
355
def __init__(
356
self,
357
*,
358
type: str,
359
path: str = None,
360
mode: str = None,
361
**kwargs
362
): ...
363
364
class Output:
365
def __init__(
366
self,
367
*,
368
type: str,
369
path: str = None,
370
mode: str = None,
371
**kwargs
372
): ...
373
374
class SystemData:
375
created_at: str
376
created_by: str
377
created_by_type: str
378
last_modified_at: str
379
last_modified_by: str
380
last_modified_by_type: str
381
```