Models in Azure Machine Learning
Managing and Tracking Models
Models are the core artifact of any machine learning project. In Azure Machine Learning, you can register, track, and manage your trained models, making them easily accessible for deployment and inference.
A registered model is a reference to a model file (e.g., .pkl, .h5, .onnx) stored in the Azure Machine Learning datastore or in cloud storage like Azure Blob Storage.
Key Features:
- Registration: Register models with descriptive names, versions, and tags.
- Versioning: Automatically manage different versions of the same model.
- Tracking: Link models to the experiments and runs that produced them.
- Metadata: Store custom metadata for easy searching and filtering.
- Deployment: Seamlessly deploy registered models as endpoints for real-time or batch inference.
Registering a Model
You can register models using the Azure Machine Learning SDK for Python or the Azure CLI.
Using the Python SDK:
This example shows how to register a scikit-learn model:
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Model
from azure.identity import DefaultAzureCredential
# Authenticate and get a handle to the workspace
ml_client = MLClient(
DefaultAzureCredential(),
subscription_id="YOUR_SUBSCRIPTION_ID",
resource_group_name="YOUR_RESOURCE_GROUP",
workspace_name="YOUR_WORKSPACE_NAME"
)
# Define the model
my_model = Model(
path="azureml://datastores/workspaceblobstore/paths/sklearn-model/model.pkl", # Path to your model file
name="sklearn-classification",
description="A scikit-learn model for classification tasks.",
tags={"area": "classification", "framework": "scikit-learn"},
properties={"model_type": "Logistic Regression"}
)
# Register the model
registered_model = ml_client.models.create_or_update(my_model)
print(f"Model registered: {registered_model.name} version {registered_model.version}")
Using the Azure CLI:
First, ensure your model files are in a local directory or uploaded to a datastore.
az ml model create --file model-config.yml
Where model-config.yml could look like:
name: tensorflow-image-recognition
version: 1
path: azureml://datastores/workspaceblobstore/paths/tf_model/
description: "A TensorFlow model for image recognition."
tags:
area: computer-vision
framework: tensorflow
properties:
model_type: CNN
Model Registry and Management
The model registry is a central hub for all your registered models. You can browse, search, and filter models based on their name, version, tags, and other metadata.
Exploring Registered Models:
Use the Azure ML Studio UI or the SDK to view your models:
- Navigate to the Models section in your Azure ML workspace.
- Filter by tags, name, or creation date.
- View detailed information, including associated runs, metrics, and lineage.
Model Lineage:
Understand the origin of your models. Each registered model entry includes a link to the experiment run that generated it, along with its inputs and outputs.
Common Model Frameworks Supported
Azure Machine Learning supports a wide range of popular machine learning frameworks. You can register models trained with:
Scikit-learn
Registering models trained with libraries like TensorFlow, PyTorch, XGBoost, and more.
TensorFlow
Save and deploy complex deep learning models.
PyTorch
Effortlessly integrate PyTorch models into your ML workflows.
ONNX (Open Neural Network Exchange)
Leverage ONNX Runtime for efficient model inference across different frameworks.