submit_azureml_pytest_2.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. def setup_persistent_compute_target(workspace, cluster_name, vm_size,
  2. max_nodes):
  3. """
  4. Set up a persistent compute target on AzureML.
  5. A persistent compute target runs noticeably faster than a
  6. regular compute target for subsequent runs. The benefit
  7. is that AzureML manages turning the compute on/off as needed for
  8. each job so the user does not need to do this.
  9. Args:
  10. workspace (str): Centralized location on Azure to work with
  11. all the
  12. artifacts used by AzureML service
  13. cluster_name (str): the Azure cluster for this run. It can
  14. already exist or it will be created.
  15. vm_size (str): Azure VM size, like STANDARD_D3_V2
  16. max_nodes (int): Number of VMs, max_nodes=4 will
  17. autoscale up to 4 VMs
  18. Returns:
  19. cpu_cluster : cluster reference
  20. """
  21. # setting vmsize and num nodes creates a persistent AzureML
  22. # compute resource
  23. logger.debug("setup: cluster_name {}".format(cluster_name))
  24. # https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-set-up-training-targets
  25. try:
  26. cpu_cluster = ComputeTarget(workspace=workspace, name=cluster_name)
  27. logger.debug('setup: Found existing cluster, use it.')
  28. except ComputeTargetException:
  29. logger.debug('setup: create cluster')
  30. compute_config = AmlCompute.provisioning_configuration(
  31. vm_size=vm_size,
  32. max_nodes=max_nodes)
  33. cpu_cluster = ComputeTarget.create(workspace,
  34. cluster_name,
  35. compute_config)
  36. cpu_cluster.wait_for_completion(show_output=True)
  37. return cpu_cluster