0
# Asset Management
1
2
Comprehensive asset management capabilities for models, data, environments, and components with versioning, lineage tracking, and metadata management in Azure Machine Learning.
3
4
## Capabilities
5
6
### Models
7
8
Model asset management with versioning, metadata, and deployment support.
9
10
```python { .api }
11
class Model:
12
def __init__(
13
self,
14
*,
15
name: str,
16
path: str = None,
17
version: str = None,
18
type: str = "custom_model",
19
description: str = None,
20
tags: dict = None,
21
properties: dict = None,
22
flavors: dict = None,
23
**kwargs
24
):
25
"""
26
Model asset for storing and versioning ML models.
27
28
Parameters:
29
- name: Model name
30
- path: Path to model files (local path or cloud URI)
31
- version: Model version (auto-generated if not specified)
32
- type: Model type ("custom_model", "mlflow_model", "triton_model")
33
- description: Model description
34
- tags: Dictionary of tags for organization
35
- properties: Custom properties
36
- flavors: Model flavors (MLflow models)
37
"""
38
```
39
40
#### Usage Example
41
42
```python
43
from azure.ai.ml.entities import Model
44
45
# Register a model from local files
46
model = Model(
47
name="my-model",
48
path="./model",
49
type="custom_model",
50
description="My trained model",
51
tags={"framework": "scikit-learn", "algorithm": "random_forest"}
52
)
53
54
registered_model = ml_client.models.create_or_update(model)
55
print(f"Model registered: {registered_model.name}:{registered_model.version}")
56
57
# Reference an existing model
58
existing_model = Model(name="my-model", version="1")
59
```
60
61
### Data Assets
62
63
Data asset management for datasets with versioning and lineage tracking.
64
65
```python { .api }
66
class Data:
67
def __init__(
68
self,
69
*,
70
name: str,
71
path: str = None,
72
version: str = None,
73
type: str = "uri_folder",
74
description: str = None,
75
tags: dict = None,
76
properties: dict = None,
77
**kwargs
78
):
79
"""
80
Data asset for storing and versioning datasets.
81
82
Parameters:
83
- name: Data asset name
84
- path: Path to data (local path, cloud URI, or datastore path)
85
- version: Data version (auto-generated if not specified)
86
- type: Data type ("uri_file", "uri_folder", "mltable")
87
- description: Data description
88
- tags: Dictionary of tags
89
- properties: Custom properties
90
"""
91
```
92
93
#### Usage Example
94
95
```python
96
from azure.ai.ml.entities import Data
97
98
# Register data from local folder
99
data = Data(
100
name="training-data",
101
path="./data/train",
102
type="uri_folder",
103
description="Training dataset for my model",
104
tags={"source": "synthetic", "size": "1GB"}
105
)
106
107
registered_data = ml_client.data.create_or_update(data)
108
109
# Register data from cloud storage
110
cloud_data = Data(
111
name="validation-data",
112
path="https://mystorageaccount.blob.core.windows.net/data/validation/",
113
type="uri_folder",
114
description="Validation dataset"
115
)
116
117
# Create MLTable data asset
118
mltable_data = Data(
119
name="processed-data",
120
path="./data/processed",
121
type="mltable",
122
description="Processed data with MLTable specification"
123
)
124
```
125
126
### Environments
127
128
Environment management for consistent runtime configurations.
129
130
```python { .api }
131
class Environment:
132
def __init__(
133
self,
134
*,
135
name: str = None,
136
version: str = None,
137
image: str = None,
138
conda_file: str = None,
139
docker_file: str = None,
140
build: BuildContext = None,
141
inference_config: dict = None,
142
description: str = None,
143
tags: dict = None,
144
**kwargs
145
):
146
"""
147
Environment for consistent runtime configurations.
148
149
Parameters:
150
- name: Environment name
151
- version: Environment version
152
- image: Base Docker image
153
- conda_file: Path to conda environment file
154
- docker_file: Path to Dockerfile
155
- build: Build context for custom images
156
- inference_config: Inference-specific configuration
157
- description: Environment description
158
- tags: Dictionary of tags
159
"""
160
161
class BuildContext:
162
def __init__(
163
self,
164
*,
165
path: str,
166
dockerfile_path: str = "Dockerfile"
167
):
168
"""
169
Build context for creating custom environment images.
170
171
Parameters:
172
- path: Path to build context directory
173
- dockerfile_path: Path to Dockerfile within context
174
"""
175
```
176
177
#### Usage Example
178
179
```python
180
from azure.ai.ml.entities import Environment, BuildContext
181
182
# Environment with pre-built image
183
env = Environment(
184
name="sklearn-env",
185
image="mcr.microsoft.com/azureml/sklearn-1.0-ubuntu20.04-py38-cpu-inference:latest",
186
description="Scikit-learn environment"
187
)
188
189
# Environment with conda file
190
conda_env = Environment(
191
name="custom-env",
192
image="mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest",
193
conda_file="./environment.yml",
194
description="Custom conda environment"
195
)
196
197
# Environment with custom Docker build
198
custom_env = Environment(
199
name="custom-docker-env",
200
build=BuildContext(path="./docker", dockerfile_path="Dockerfile"),
201
description="Custom Docker environment"
202
)
203
204
registered_env = ml_client.environments.create_or_update(env)
205
```
206
207
### Components
208
209
Reusable components for building ML pipelines.
210
211
```python { .api }
212
class Component:
213
def __init__(
214
self,
215
*,
216
name: str,
217
version: str = None,
218
display_name: str = None,
219
description: str = None,
220
tags: dict = None,
221
**kwargs
222
):
223
"""
224
Base component class for pipeline building blocks.
225
226
Parameters:
227
- name: Component name
228
- version: Component version
229
- display_name: Display name for UI
230
- description: Component description
231
- tags: Dictionary of tags
232
"""
233
234
class CommandComponent(Component):
235
def __init__(
236
self,
237
*,
238
name: str,
239
command: str,
240
code: str = None,
241
environment: Environment,
242
inputs: dict = None,
243
outputs: dict = None,
244
**kwargs
245
):
246
"""
247
Command component for executing arbitrary commands.
248
249
Parameters:
250
- name: Component name
251
- command: Command to execute
252
- code: Source code path
253
- environment: Runtime environment
254
- inputs: Component input schema
255
- outputs: Component output schema
256
"""
257
258
class ParallelComponent(Component):
259
def __init__(
260
self,
261
*,
262
name: str,
263
task: ParallelTask,
264
environment: Environment,
265
inputs: dict = None,
266
outputs: dict = None,
267
**kwargs
268
):
269
"""
270
Parallel component for batch processing tasks.
271
272
Parameters:
273
- name: Component name
274
- task: Parallel task configuration
275
- environment: Runtime environment
276
- inputs: Component input schema
277
- outputs: Component output schema
278
"""
279
280
class SparkComponent(Component):
281
def __init__(
282
self,
283
*,
284
name: str,
285
code: str,
286
entry: SparkJobEntry,
287
**kwargs
288
):
289
"""
290
Spark component for big data processing.
291
292
Parameters:
293
- name: Component name
294
- code: Spark application code
295
- entry: Spark entry point configuration
296
"""
297
```
298
299
#### Usage Example
300
301
```python
302
from azure.ai.ml.entities import CommandComponent, Environment
303
304
# Create a training component
305
train_component = CommandComponent(
306
name="train-model",
307
display_name="Train Model",
308
description="Training component for ML model",
309
command="python train.py --input_data ${{inputs.data}} --model_output ${{outputs.model}}",
310
code="./src",
311
environment=Environment(
312
image="mcr.microsoft.com/azureml/sklearn-1.0-ubuntu20.04-py38-cpu-inference:latest"
313
),
314
inputs={
315
"data": {"type": "uri_folder", "description": "Training data"}
316
},
317
outputs={
318
"model": {"type": "uri_folder", "description": "Trained model"}
319
}
320
)
321
322
registered_component = ml_client.components.create_or_update(train_component)
323
```
324
325
### Asset Operations
326
327
Common operations available for all asset types through the MLClient.
328
329
```python { .api }
330
class ModelOperations:
331
def create_or_update(self, model: Model) -> Model: ...
332
def get(self, name: str, version: str = None) -> Model: ...
333
def list(self, name: str = None) -> list: ...
334
def delete(self, name: str, version: str) -> None: ...
335
def download(self, name: str, version: str, download_path: str) -> str: ...
336
337
class DataOperations:
338
def create_or_update(self, data: Data) -> Data: ...
339
def get(self, name: str, version: str = None) -> Data: ...
340
def list(self, name: str = None) -> list: ...
341
def delete(self, name: str, version: str) -> None: ...
342
343
class EnvironmentOperations:
344
def create_or_update(self, environment: Environment) -> Environment: ...
345
def get(self, name: str, version: str = None) -> Environment: ...
346
def list(self, name: str = None) -> list: ...
347
def delete(self, name: str, version: str) -> None: ...
348
349
class ComponentOperations:
350
def create_or_update(self, component: Component) -> Component: ...
351
def get(self, name: str, version: str = None) -> Component: ...
352
def list(self, name: str = None) -> list: ...
353
def delete(self, name: str, version: str) -> None: ...
354
```
355
356
#### Usage Example
357
358
```python
359
# List all models
360
models = ml_client.models.list()
361
for model in models:
362
print(f"{model.name}:{model.version}")
363
364
# Get specific model version
365
model = ml_client.models.get("my-model", version="1")
366
367
# Download model files
368
download_path = ml_client.models.download("my-model", version="1", download_path="./downloads")
369
370
# List data assets
371
data_assets = ml_client.data.list(name="training-data")
372
373
# Get latest version of data
374
latest_data = ml_client.data.get("training-data") # Gets latest version
375
```
376
377
### Workspace Asset References
378
379
Reference assets across workspaces and registries.
380
381
```python { .api }
382
class WorkspaceAssetReference:
383
def __init__(
384
self,
385
*,
386
name: str,
387
version: str = None,
388
**kwargs
389
):
390
"""
391
Reference to an asset in the current workspace.
392
393
Parameters:
394
- name: Asset name
395
- version: Asset version (latest if not specified)
396
"""
397
```
398
399
### Intellectual Property Protection
400
401
Intellectual property settings for protecting sensitive assets.
402
403
```python { .api }
404
class IntellectualProperty:
405
def __init__(
406
self,
407
*,
408
publisher: str,
409
protection_level: str = "all"
410
):
411
"""
412
Intellectual property protection configuration.
413
414
Parameters:
415
- publisher: Publisher name
416
- protection_level: Protection level ("all", "none")
417
"""
418
```
419
420
#### Usage Example
421
422
```python
423
from azure.ai.ml.entities import Model, IntellectualProperty
424
425
# Model with IP protection
426
protected_model = Model(
427
name="proprietary-model",
428
path="./model",
429
description="Proprietary model with IP protection",
430
intellectual_property=IntellectualProperty(
431
publisher="My Company",
432
protection_level="all"
433
)
434
)
435
436
ml_client.models.create_or_update(protected_model)
437
```