12345678910111213141516171819202122232425262728293031323334353637383940 |
- def setup_persistent_compute_target(workspace, cluster_name, vm_size,
- max_nodes):
- """
- Set up a persistent compute target on AzureML.
- A persistent compute target runs noticeably faster than a
- regular compute target for subsequent runs. The benefit
- is that AzureML manages turning the compute on/off as needed for
- each job so the user does not need to do this.
- Args:
- workspace (str): Centralized location on Azure to work with
- all the
- artifacts used by AzureML service
- cluster_name (str): the Azure cluster for this run. It can
- already exist or it will be created.
- vm_size (str): Azure VM size, like STANDARD_D3_V2
- max_nodes (int): Number of VMs, max_nodes=4 will
- autoscale up to 4 VMs
- Returns:
- cpu_cluster : cluster reference
- """
- # setting vmsize and num nodes creates a persistent AzureML
- # compute resource
- logger.debug("setup: cluster_name {}".format(cluster_name))
- # https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-set-up-training-targets
- try:
- cpu_cluster = ComputeTarget(workspace=workspace, name=cluster_name)
- logger.debug('setup: Found existing cluster, use it.')
- except ComputeTargetException:
- logger.debug('setup: create cluster')
- compute_config = AmlCompute.provisioning_configuration(
- vm_size=vm_size,
- max_nodes=max_nodes)
- cpu_cluster = ComputeTarget.create(workspace,
- cluster_name,
- compute_config)
- cpu_cluster.wait_for_completion(show_output=True)
- return cpu_cluster
|