Skip to content

Commit 22394a4

Browse files
authored
Merge pull request #111972 from sdgilley/sdg-cost-mgmt
control costs
2 parents 66225da + ddbedc2 commit 22394a4

File tree

5 files changed

+145
-4
lines changed

5 files changed

+145
-4
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
title: Plan and manage costs
3+
titleSuffix: Azure Machine Learning
4+
description: Plan and manage costs for Azure Machine Learning with cost analysis in Azure portal. When you build machine learning models, learn further cost-saving tips to lower your cost.
5+
author: sdgilley
6+
ms.author: sgilley
7+
ms.custom: subject-cost-optimization
8+
ms.reviewer: nigup
9+
ms.service: machine-learning
10+
ms.subservice: core
11+
ms.topic: conceptual
12+
ms.date: 04/22/2020
13+
---
14+
15+
# Plan and manage costs for Azure Machine Learning
16+
17+
This article describes how to plan and manage costs for Azure Machine Learning. First, you use the Azure pricing calculator to help plan for costs before you add any resources. Next, as you add the Azure resources, review the estimated costs. Finally, use cost-saving tips as you train your model with managed Azure Machine Learning compute clusters.
18+
19+
After you've started using Azure Machine Learning resources, use the cost management features to set budgets and monitor costs. Also review the forecasted costs and identify spending trends to identify areas where you might want to act.
20+
21+
Understand that the costs for Azure Machine Learning are only a portion of the monthly costs in your Azure bill. If you are using other Azure services, you're billed for all the Azure services and resources used in your Azure subscription, including the third-party services. This article explains how to plan for and manage costs for Azure Machine Learning. After you're familiar with managing costs for Azure Machine Learning, apply similar methods to manage costs for all the Azure services used in your subscription.
22+
23+
When you train your machine learning models, use managed Azure Machine Learning compute clusters to take advantage of more cost-saving tips:
24+
25+
* Configure your training clusters for autoscaling
26+
* Set quotas on your subscription and workspaces
27+
* Set termination policies on your training run
28+
* Use low-priority virtual machines (VM)
29+
* Use an Azure Reserved VM Instance
30+
31+
## Prerequisites
32+
33+
Cost analysis supports different kinds of Azure account types. To view the full list of supported account types, see [Understand Cost Management data](../cost-management-billing/costs/understand-cost-mgt-data.md). To view cost data, you need at least read access for your Azure account.
34+
35+
For information about assigning access to Azure Cost Management data, see [Assign access to data](../cost-management-billing/costs/assign-access-acm-data.md).
36+
37+
## Estimate costs
38+
39+
Use the [Azure pricing calculator](https://azure.microsoft.com/pricing/calculator/) to estimate costs before you create the resources in an Azure Machine Learning account. On the left, select **AI + Machine Learning**, then select **Azure Machine Learning** to begin.
40+
41+
The following screenshot shows the cost estimation by using the calculator:
42+
43+
:::image type="content" source="media/concept-plan-manage-cost/capacity-calculator-cost-estimate.png" alt-text="Cost estimate in Azure calculator":::
44+
45+
As you add new resources to your workspace, return to this calculator and add the same resource here to update your cost estimates.
46+
47+
While the Enterprise edition is in preview, there is no ML surcharge. When the Enterprise edition becomes generally available, it will have a machine learning surcharge (for training and inferencing). For more details, [Azure Machine Learning pricing](https://azure.microsoft.com/pricing/details/machine-learning/).
48+
49+
## Get cost alerts
50+
51+
Create [budgets](../cost-management/tutorial-acm-create-budgets.md) to manage costs and create [alerts](../cost-management/cost-mgt-alerts-monitor-usage-spending.md) that automatically notify stakeholders of spending anomalies and overspending risks. Alerts are based on spending compared to budget and cost thresholds. Budgets and alerts are created for Azure subscriptions and resource groups, so they're useful as part of an overall cost monitoring strategy. However, budgets and alerts may have limited functionality to manage individual Azure service costs because they're designed to track costs at a higher level.
52+
53+
## Monitor costs
54+
55+
As you use resources with Azure Machine Learning, you incur costs. Azure resource usage unit costs vary by time intervals (seconds, minutes, hours, and days) or by request unit usage. As soon as usage of Azure Machine Learning starts, costs are incurred. View these costs in the [cost analysis](../cost-management/quick-acm-cost-analysis.md) pane in the Azure portal.
56+
57+
View costs in graphs and tables for different time intervals. Some examples are by day, current, prior month, and year. Also view costs against budgets and forecasted costs. Switching to longer views over time helps you identify spending trends and see where overspending might have occurred. If you've created budgets, see where they exceeded.
58+
59+
You won't see a separate service area for Machine Learning. Instead you'll see the various resources you've added to your Machine Learning workspaces.
60+
61+
## Use AmlCompute
62+
63+
With constantly changing data, you need fast and streamlined model training and retraining to maintain accurate models. However, continuous training comes at a cost, especially for deep learning models on GPUs.
64+
65+
Azure Machine Learning users can use the managed Azure Machine Learning compute cluster, also called AmlCompute. AmlCompute supports a variety of GPU and CPU options. The AmlCompute is internally hosted on behalf of your subscription by Azure Machine Learning, but provides the same enterprise grade security, compliance and governance at Azure IaaS cloud scale.
66+
67+
Because these compute pools are inside of Azure's IaaS infrastructure, you can deploy, scale, and manage your training with the same security and compliance requirements as the rest of your infrastructure. These deployments occur in your subscription and obey your governance rules. Learn more about [Azure Machine Learning Compute](how-to-set-up-training-targets.md#amlcompute).
68+
69+
## Configure training clusters for autoscaling
70+
71+
Autoscaling clusters based on the requirements of your workload helps reduce your costs so you only use what you need.
72+
AmlCompute clusters are designed to autoscale dynamically based on the requirements of your workload. The cluster can be scaled up to the maximum number of nodes provisioned and within the quota designated for the subscription. As each run completes, the cluster will release nodes and autoscale to your designated minimum node count.
73+
74+
In addition to setting the minimum and maximum number of nodes, tweak the amount of time the node is idle before scale down. By default, idle time before scale down is set to 120 seconds.
75+
76+
+ If you perform less iterative experimentation, reduce this time to save costs.
77+
+ If you perform highly iterative dev/test experimentation, you might need to increase this so you aren't paying for constant scaling up and down after each change to your training script or environment.
78+
79+
AmlCompute clusters can be configured for your changing workload requirements in Azure portal, using the [AmlCompute SDK class](https://docs.microsoft.com/python/api/azureml-core/azureml.core.compute.amlcompute.amlcompute?view=azure-ml-py), [AmlCompute CLI](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/computetarget/create?view=azure-cli-latest#ext-azure-cli-ml-az-ml-computetarget-create-amlcompute), with the [REST APIs](https://github.com/Azure/azure-rest-api-specs/tree/master/specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable).
80+
81+
```azure cli
82+
az ml computetarget create amlcompute --name testcluster --vm-size Standard_NC6 --min-nodes 0 --max-nodes 5 --idle-seconds-before-scaledown 300
83+
```
84+
85+
## Set quotas on resources
86+
87+
Much like other Azure compute resources, AmlCompute comes with an inherent [quota (or limit) configuration](how-to-manage-quotas.md#azure-machine-learning-compute). This quota is by VM family (for example, Dv2 series, NCv3 series) and varies by region for each subscription. Subscriptions start with small defaults to get you going, but use this setting to control the amount of Amlcompute resources available to be spun up in your subscription.
88+
89+
Also configure [workspace level quota by VM family](/how-to-manage-quotas.md#workspace-level-quota), for each workspace within a subscription. This allows you to have more granular control on the costs that each workspace might potentially incur and restrict certain VM families.
90+
91+
To set quotas at the workspace level, start in the [Azure portal](https://portal.azure.com). Select any workspace in your subscription, and select **Usages + quotas** in the left pane. Then select the **Configure quotas** tab to view the quotas. You need privileges at the subscription scope to set this quota, since it's a setting that affects multiple workspaces.
92+
93+
## Set run auto-termination policies
94+
95+
Configure your training runs to limit their duration or to terminate them early in case of certain conditions especially when you are using Azure Machine Learning's built-in Hyperparameter Tuning or Automated Machine Learning capabilities.
96+
97+
Here are a few options that you have:
98+
* Define a parameter called `max_run_duration_seconds` in your RunConfiguration to control the maximum duration a run can extend to on the compute you choose (either local or remote cloud compute).
99+
* For [hyperparameter tuning](how-to-tune-hyperparameters.md#early-termination), define an early termination policy from a Bandit policy, a Median stopping policy or a Truncation selection policy. In addition, also use parameters such as `max_total_runs` or `max_duration_minutes` to further control the various hyperparameter sweeps.
100+
* For [automated machine learning](how-to-configure-auto-train.md#exit), set similar termination policies using the `enable_early_stopping` flag. Also use properties such as `iteration_timeout_minutes` and `experiment_timeout_minutes` to control the maximum duration of a run or for the entire experiment.
101+
102+
## Use low-priority VMs
103+
104+
Azure allows you to use excess unutilized capacity as Low-Priority VMs across virtual machine scale sets, Batch, and the Machine Learning service. These allocations are pre-emptible but come at a reduced price compared to dedicated VMs. In general, we recommend using Low-Priority VMs for Batch workloads or where interruptions are recoverable either through resubmits (for Batch Inferencing) or through restarts (for deep learning training with checkpointing).
105+
106+
Low-Priority VMs have a single quota separate from the dedicated quota value, which is by VM family. Learn [more about AmlCompute quotas](how-to-manage-quotas.md).
107+
108+
Set the priority of your VM in any of these ways:
109+
110+
* In the studio, choose **Low Priority** when you create a VM.
111+
112+
* With the Python SDK, set the `vm_priority` attribute in your provisioning configuration.
113+
114+
```python
115+
compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_D2_V2',
116+
vm_priority='lowpriority',
117+
max_nodes=4)
118+
```
119+
120+
* Using the CLI, set the `vm-priority`:
121+
122+
```azurecli-interactive
123+
az ml computetarget create amlcompute --name lowpriocluster --vm-size Standard_NC6 --max-nodes 5 --vm-priority lowpriority
124+
```
125+
126+
Low-Priority VMs don't work for compute instances, since they need to support interactive notebook experiences.
127+
128+
## Use reserved instances
129+
130+
Azure Reserved VM Instance provides another way to get huge savings on compute resources by committing to one-year or three-year terms. These discounts range up to 72% of the pay-as-you-go prices and are applied directly to your monthly Azure bill.
131+
132+
Azure Machine Learning Compute supports reserved instances inherently. So if you have purchased a one-year or three-year reserved instance we will automatically apply that reserved instance discount against the managed compute that is used within Azure Machine Learning without requiring any additional setup from your end.
133+
134+
135+
## Next steps
136+
137+
* Learn more about managing costs with [cost analysis](../cost-management-billing/costs/quick-acm-cost-analysis.md).
138+
* Learn more about [Azure Machine Learning compute](how-to-set-up-training-targets.md#amlcompute).

articles/machine-learning/how-to-configure-auto-train.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ run = experiment.submit(automl_config, show_output=True)
321321
>Dependencies are first installed on a new machine. It may take up to 10 minutes before output is shown.
322322
>Setting `show_output` to `True` results in output being shown on the console.
323323
324-
### Exit Criteria
324+
### <a name="exit"></a> Exit criteria
325+
325326
There are a few options you can define to end your experiment.
326327
1. No Criteria: If you do not define any exit parameters the experiment will continue until no further progress is made on your primary metric.
327328
1. Exit after a length of time: Using `experiment_timeout_minutes` in your settings allows you to define how long in minutes should an experiment continue in run.

articles/machine-learning/how-to-tune-hyperparameters.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ The training script calculates the `val_accuracy` and logs it as "accuracy", whi
181181

182182
<a name='specify-early-termination-policy'/>
183183

184-
## Specify early termination policy
184+
## <a name="early-termination"></a> Specify early termination policy
185185

186186
Terminate poorly performing runs automatically with an early termination policy. Termination reduces wastage of resources and instead uses these resources for exploring other parameter configurations.
187187

@@ -316,7 +316,7 @@ hyperdrive_run = experiment.submit(hyperdrive_run_config)
316316

317317
Often, finding the best hyperparameter values for your model can be an iterative process, needing multiple tuning runs that learn from previous hyperparameter tuning runs. Reusing knowledge from these previous runs will accelerate the hyperparameter tuning process, thereby reducing the cost of tuning the model and will potentially improve the primary metric of the resulting model. When warm starting a hyperparameter tuning experiment with Bayesian sampling, trials from the previous run will be used as prior knowledge to intelligently pick new samples, to improve the primary metric. Additionally, when using Random or Grid sampling, any early termination decisions will leverage metrics from the previous runs to determine poorly performing training runs.
318318

319-
Azure Machine Learning allows you to warm start your hyperparameter tuning run by leveraging knowledge from up to 5 previously completed / cancelled hyperparameter tuning parent runs. You can specify the list of parent runs you want to warm start from using this snippet:
319+
Azure Machine Learning allows you to warm start your hyperparameter tuning run by leveraging knowledge from up to 5 previously completed / canceled hyperparameter tuning parent runs. You can specify the list of parent runs you want to warm start from using this snippet:
320320

321321
```Python
322322
from azureml.train.hyperdrive import HyperDriveRun
@@ -326,7 +326,7 @@ warmstart_parent_2 = HyperDriveRun(experiment, "warmstart_parent_run_ID_2")
326326
warmstart_parents_to_resume_from = [warmstart_parent_1, warmstart_parent_2]
327327
```
328328

329-
Additionally, there may be occasions when individual training runs of a hyperparameter tuning experiment are cancelled due to budget constraints or fail due to other reasons. It is now possible to resume such individual training runs from the last checkpoint (assuming your training script handles checkpoints). Resuming an individual training run will use the same hyperparameter configuration and mount the outputs folder used for that run. The training script should accept the `resume-from` argument, which contains the checkpoint or model files from which to resume the training run. You can resume individual training runs using the following snippet:
329+
Additionally, there may be occasions when individual training runs of a hyperparameter tuning experiment are canceled due to budget constraints or fail due to other reasons. It is now possible to resume such individual training runs from the last checkpoint (assuming your training script handles checkpoints). Resuming an individual training run will use the same hyperparameter configuration and mount the outputs folder used for that run. The training script should accept the `resume-from` argument, which contains the checkpoint or model files from which to resume the training run. You can resume individual training runs using the following snippet:
330330

331331
```Python
332332
from azureml.core.run import Run
134 KB
Loading

articles/machine-learning/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
href: /azure/open-datasets/samples?context=azure/machine-learning/service/context/ml-context
9292
- name: Concepts
9393
items:
94+
- name: Plan and manage costs
95+
href: concept-plan-manage-cost.md
9496
- name: Workspace
9597
href: concept-workspace.md
9698
- name: Environments

0 commit comments

Comments
 (0)