def ComputeDelete(): subscription_id = request.json['subscription_id'] resource_group = request.json['resource_group'] workspace_name = request.json['workspace_name'] location = request.json['location'] Cluster_type = request.json['Cluster_type'] cluster_name = request.json['cluster_name'] ws = Workspace(subscription_id=subscription_id, resource_group=resource_group, workspace_name=workspace_name) print("Found workspace {} at location {}".format(ws.name, ws.location)) try: if Cluster_type == 'Training': aml_compute = AmlCompute(ws, cluster_name) print('Found existing AML compute context.') aml_compute.delete() else: aks_target = AksCompute(ws, cluster_name) print('Found existing AKS compute context.') aks_target.delete() print('compute deleted') return "compute deleted" except Exception as e: error_statement = str(e) print("Error statement: ", error_statement) return error_statement
def AKSCompute(): subscription_id = request.json['subscription_id'] resource_group = request.json['resource_group'] workspace_name = request.json['workspace_name'] location = request.json['location'] cluster_name = request.json['cluster_name'] vm_size = request.json['vm_size'] agent_count = request.json['agent_count'] ws = Workspace(subscription_id=subscription_id, resource_group=resource_group, workspace_name=workspace_name) print("Found workspace {} at location {}".format(ws.name, ws.location)) print('Found existing Workspace.') #aml_compute = AmlCompute(ws, cluster_name) #cluster_name = 'cpu-cluster' try: aks_target = AksCompute(ws, cluster_name) print('Found existing AKS compute context.') return "Found existing AKS compute context." except: print('need to create new Compute.') print('Creating new AKS compute context.') prov_config = AksCompute.provisioning_configuration( vm_size=vm_size, agent_count=agent_count, location=location) aks_target = ComputeTarget.create( workspace=ws, name=cluster_name, provisioning_configuration=prov_config) # Wait for the create process to complete aks_target.wait_for_completion(show_output=True) return "Compute successfully created"
def create_aks_cluster(workspace, parameters): print("::debug::Creating aks cluster configuration") aks_config = AksCompute.provisioning_configuration( agent_count=parameters.get("agent_count", None), vm_size=parameters.get("vm_size", "Standard_D3_v2"), location=parameters.get("location", None), service_cidr=parameters.get("service_cidr", None), dns_service_ip=parameters.get("dns_service_ip", None), docker_bridge_cidr=parameters.get("docker_bridge_cidr", None)) print( "::debug::Changing cluster purpose if specified settings were provided" ) if "dev" in parameters.get("cluster_purpose", "").lower() or "test" in parameters.get( "cluster_purpose", "").lower(): aks_config.cluster_purpose = AksCompute.ClusterPurpose.DEV_TEST print( "::debug::Adding VNET settings to configuration if all required settings were provided" ) if parameters.get( "vnet_resource_group_name", None) is not None and parameters.get( "vnet_name", None) is not None and parameters.get( "subnet_name", None) is not None: aks_config.vnet_resourcegroup_name = parameters.get( "vnet_resource_group_name", None) aks_config.vnet_name = parameters.get("vnet_name", None) aks_config.subnet_name = parameters.get("subnet_name", None) print( "::debug::Adding SSL settings to configuration if all required settings were provided" ) if parameters.get("ssl_cname", None) is not None and parameters.get( "ssl_cert_pem_file", None) is not None and parameters.get( "ssl_key_pem_file", None) is not None: aks_config.ssl_cname = parameters.get("ssl_cname", None) aks_config.ssl_cert_pem_file = parameters.get("ssl_cert_pem_file", None) aks_config.ssl_key_pem_file = parameters.get("ssl_key_pem_file", None) print( "::debug::Adding load balancer settings to configuration if all required settings were provided" ) if parameters.get("load_balancer_type", None) == "InternalLoadBalancer" and parameters.get( "load_balancer_subnet", None) is not None: aks_config.load_balancer_type = parameters.get("load_balancer_type", None) aks_config.load_balancer_subnet = parameters.get( "load_balancer_subnet", None) print("::debug::Creating compute target") # Default compute target name repository_name = str(os.environ.get("GITHUB_REPOSITORY")).split("/")[-1] aks_cluster = create_compute_target(workspace=workspace, name=parameters.get( "name", repository_name), config=aks_config) return aks_cluster
def get_aks(workspace: Workspace, compute_name: str): # Verify that cluster does not exist already try: aks_target = workspace.compute_targets.get(compute_name) if aks_target is not None and type(aks_target) is AksCompute: print('Found existing compute target ' + compute_name + ' so using it.') # noqa: E127 else: prov_config = AksCompute.provisioning_configuration( cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST) aks_name = compute_name print("No Azure Kubernetes Service cluster found, " "creating one now...") # Create the cluster aks_target = ComputeTarget.create( workspace=workspace, name=aks_name, provisioning_configuration=prov_config) # Wait for the create process to complete aks_target.wait_for_completion(show_output=True) return aks_target except ComputeTargetException as e: print(e) print('An error occurred trying to provision compute.') raise
def ComputeExist(): subscription_id = request.json['subscription_id'] resource_group = request.json['resource_group'] workspace_name = request.json['workspace_name'] location = request.json['location'] Cluster_type = request.json['Cluster_type'] cluster_name = request.json['cluster_name'] ws = Workspace(subscription_id=subscription_id, resource_group=resource_group, workspace_name=workspace_name) print("Found workspace {} at location {}".format(ws.name, ws.location)) print('Found existing Workspace.') #aml_compute = AmlCompute(ws, cluster_name) #cluster_name = 'cpu-cluster' try: if Cluster_type == 'Training': aml_compute = AmlCompute(ws, cluster_name) else: aks_target = AksCompute(ws, cluster_name) print('Found existing AML compute context.') return "compute exist" except: print('need to create new Compute.') return "compute not exist"
def attachAksComputeToWorkspace(ws, resource_group, cluster_name, name_for_compute_in_amls, is_dev=False): if is_dev: attach_config = AksCompute.attach_configuration(resource_group = resource_group, cluster_name = cluster_name, cluster_purpose = AksCompute.ClusterPurpose.DEV_TEST) print(attach_config) else: # Attach the cluster to your workgroup. If the cluster has less than 12 virtual CPUs, use the following instead: attach_config = AksCompute.attach_configuration(resource_group = resource_group, cluster_name = cluster_name) aks_target = ComputeTarget.attach(ws, name_for_compute_in_amls, attach_config) print("AKS Compute Attached to Workspace") return aks_target
def __create_or_get_compute(self): compute_config = self.__config['compute'] compute_list = AksCompute.list(self.__ws) compute = compute_list.find_by_property('name', compute_config['name']) if compute: return compute prov_config = AksCompute.provisioning_configuration( agent_count=compute_config['agent_count'], vm_size=compute_config['vm_size'], location=compute_config['location']) aks_name = compute_config['name'] aks_target = ComputeTarget.create( workspace=self.__ws, name=aks_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) return aks_target
def attach_cluster(): # Set the resource group that contains the AKS cluster and the cluster name resource_group = RESOURCE_GROUP cluster_name = AKS_CLUSTER_NAME # Attach the cluster to your workgroup. If the cluster has less than 12 virtual CPUs, use the following instead: attach_config = AksCompute.attach_configuration( resource_group=resource_group, cluster_name=cluster_name, cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST) ws = get_workspace() aks_target = ComputeTarget.attach(ws, AKS_NAME, attach_config) return aks_target
def create_aks(workspace, aks_cluster_name): from azureml.core.compute import AksCompute, ComputeTarget # Create an AKS cluster print("Creating AKS cluster...") # Use the default configuration (you can also provide parameters to customize this) prov_config = AksCompute.provisioning_configuration() # Create the cluster aks_target = ComputeTarget.create(workspace=workspace, name=aks_cluster_name, provisioning_configuration=prov_config) # Wait for the create process to complete aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) print("AKS cluster creation completed") return aks_target
def deploy_aks(workspace, model_azure, endpoint_name, inference_config, aks_name): aks_target = AksCompute(workspace, aks_name) aks_config = AksWebservice.deploy_configuration() aks_service = Model.deploy(workspace=workspace, name=endpoint_name, models=[model_azure], inference_config=inference_config, deployment_config=aks_config, deployment_target=aks_target, overwrite=True) aks_service.wait_for_deployment(show_output = True) print(f"Endpoint : {endpoint_name} was successfully deployed to AKS") print(f"Endpoint : {aks_service.scoring_uri} created") print('')
def create_cluster(): ws = get_workspace() # Use the default configuration (can also provide parameters to customize) prov_config = AksCompute.provisioning_configuration() aks_name = AKS_CLUSTER_NAME # Create the cluster aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) return aks_target
def createComputeCluster(workspace, region, compute_name, compute_sku, node_count, dev_cluster): ''' Create new AKS cluster, unless there is an existing AMLS compute with the same name already attached to the AMLS workspace. PARAMS: workspace : azureml.core.Workspace : Existing AMLS Workspace region : String : Azure region compute_name : String : Name of the AMLS compute to create/locate. compute_sku : String : Azure ML VM Sku node_count : int : Number of VM's to add to the cluster dev_cluster : bool : Flag indicating if this is a development cluster. A development cluster generally has fewwer vCPU's based on node count than allowed for a production deployment. RETURNS: azureml.core.compute.AksCompute ''' purpose = _getClusterPurpose(dev_cluster) aks_target = _getExistingCompute(workspace, compute_name) if aks_target == None: print("Creating new AKS compute.....") prov_config = AksCompute.provisioning_configuration( agent_count=node_count, vm_size=compute_sku, location=region, cluster_purpose=purpose) aks_target = ComputeTarget.create( workspace=workspace, name=compute_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) aks_status = aks_target.get_status() assert aks_status == 'Succeeded' return aks_target
def deploy_to_AKS(workspace, attachment_name, service_name, models, inference_config, token_auth_enabled=True, cpu_cores=1, memory_gb=1, overwrite=True): services = workspace.webservices if service_name in services and overwrite: print('found existing service named {}, delete it right now...'.format(service_name)) services[service_name].delete() # Only one type of Auth may be enabled if token_auth_enabled: # key auth auth_enabled = False print('auth type: {}'.format('token' if token_auth_enabled else 'key')) aks_target = AksCompute(workspace, attachment_name) # If deploying to a cluster configured for dev/test, ensure that it was created with enough # cores and memory to handle this deployment configuration. Note that memory is also used by # things such as dependencies and AML components. deployment_config = AksWebservice.deploy_configuration(cpu_cores=cpu_cores, memory_gb=memory_gb, token_auth_enabled=token_auth_enabled, auth_enabled=auth_enabled) service = Model.deploy(workspace, service_name, models, inference_config, deployment_config, aks_target) service.wait_for_deployment(show_output=True) print(service.state) return service
def attach_aks_clust(parameters, ws): compute_type = parameters.get("compute_type", "") resource_grp = os.environ.get("INPUT_RESOURCE_GRP", default=None) if resource_grp is None: return if compute_type == 'akscluster': compute_name = parameters.get("name", None) try: attach_config = AksCompute.attach_configuration( resource_group=resource_grp, cluster_name=compute_name) deployment_target = ComputeTarget.attach(ws, compute_name, attach_config) deployment_target.wait_for_completion(show_output=True) print( "::debug::Successfully attached the given cluster with workspace" ) return 'attached' except ComputeTargetException: print( "::debug::Could not find existing compute target with provided name inside given resource group" ) return
def attachExistingCluster(workspace, cluster_name, resource_group, compute_name, dev_cluster): ''' Attach an existing AKS cluster, unless there is an existing AMLS compute with the same name already attached to the AMLS workspace. PARAMS: workspace : azureml.core.Workspace : Existing AMLS Workspace cluster_name : String : Name of an existing AKS cluster resource_group : String : Name of the Azure Resource group existing cluster is in compute_name : String : Name of the AMLS compute to create/locate. dev_cluster : bool : Flag indicating if this is a development cluster. A development cluster generally has fewwer vCPU's based on node count than allowed for a production deployment. RETURNS: azureml.core.compute.AksCompute ''' print("Attaching existing AKS compute.....") purpose = _getClusterPurpose(dev_cluster) aks_target = _getExistingCompute(workspace, compute_name) if aks_target == None: attach_config = AksCompute.attach_configuration( resource_group=resource_group, cluster_name=cluster_name, cluster_purpose=purpose) if attach_config: aks_target = ComputeTarget.attach(workspace, compute_name, attach_config) return aks_target
try: service = Webservice(name=aks_service_name, workspace=ws) print("Deleting AKS service {}".format(aks_service_name)) service.delete() except: print("No existing webservice found: ", aks_service_name) compute_list = ws.compute_targets aks_target = None if aks_name in compute_list: aks_target = compute_list[aks_name] if aks_target == None: print("No AKS found. Creating new Aks: {} and AKS Webservice: {}".format( aks_name, aks_service_name)) prov_config = AksCompute.provisioning_configuration(location=aks_region) # Create the cluster aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) print("Creating new webservice") # Create the web service configuration (using defaults) aks_config = AksWebservice.deploy_configuration(description=args.description, tags={ 'name': aks_name, 'image_id': image.id })
# create aml compute targets for ct_name in amlcomputes: if ct_name not in ws.compute_targets: print(f"Creating AML compute {ct_name}") compute_config = AmlCompute.provisioning_configuration( **amlcomputes[ct_name]) ct = ComputeTarget.create(ws, ct_name, compute_config) ct.wait_for_completion(show_output=True) # create aks compute targets if args.create_aks: for ct_name in akscomputes: if ct_name not in ws.compute_targets: print(f"Creating AKS compute {ct_name}") compute_config = AksCompute.provisioning_configuration( **akscomputes[ct_name]) ct = ComputeTarget.create(ws, ct_name, compute_config) ct.wait_for_completion(show_output=True) if args.datalake_name not in ws.datastores: print(f"Creating datastore {args.datalake_name}") adlsgen2_datastore = Datastore.register_azure_data_lake_gen2( workspace=ws, datastore_name=args.datalake_name, account_name=args.datalake_name, subscription_id=ws.subscription_id, resource_group=args.datalake_rg_name, filesystem="datalake", grant_workspace_access=True, )
name=imageName, # this is the model object models=[model], image_config=image_config, workspace=ws) print("Wait for container image....") containerImage.wait_for_creation(show_output=True) os.chdir(currentDirectory) # Create the AKS target if it's not there. if not aks_target: print("Creating AKS target") # Use the default configuration (can also provide parameters to customize) prov_config = AksCompute.provisioning_configuration() # Create the cluster aks_target = ComputeTarget.create( workspace=ws, name=aksName, provisioning_configuration=prov_config) print("Wait for AKS compute target....") aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) if not aks_service: #Set the web service configuration (using default here) aks_config = AksWebservice.deploy_configuration() aks_service = Webservice.deploy_from_image(
ax.set_yticklabels(ticks) fig.colorbar(cax) plt.ylabel('true labels', fontsize=14) plt.xlabel('predicted values', fontsize=14) #plt.savefig(os.path.join(project_folder, 'conf.png')) plt.show() # Provision the AKS Cluster print("Provisioning an AKS cluster...") from azureml.core.compute import AksCompute, ComputeTarget from azureml.core.compute_target import ComputeTargetException aks_name = 'myaks' try: aks_target = AksCompute(workspace=ws, name=aks_name) print('found existing Azure Kubernetes Service:', aks_target.name) except ComputeTargetException: print('creating new Azure Kubernetes Service.') # AKS configuration prov_config = AksCompute.provisioning_configuration( #agent_count=2, #vm_size="Standard_D3_v2" ) # Create the cluster aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config)
model, = (m for m in model_list if m.version == model_version and m.name == model_name) print( 'Model picked: {} \nModel Description: {} \nModel Version: {}'.format( model.name, model.description, model.version)) # Set up Compute Target try: computeTargets = ComputeTarget.list(ws) aks_target, = (t for t in computeTargets if t.name == aks_service_name) if aks_target is None: raise Exception( "Compute Target {} not found. Attempting to create".format( aks_service_name)) except: prov_config = AksCompute.provisioning_configuration(location='eastus') # Create the cluster aks_target = ComputeTarget.create( workspace=ws, name=aks_service_name, provisioning_configuration=prov_config) print("Provisioning an AKS Cluster") aks_target.wait_for_completion() # Configure this particular web service's resources on your AKS Cluster aks_config = AksWebservice.deploy_configuration( autoscale_enabled=False, auth_enabled=True, cpu_cores=0.5, memory_gb=1,
}, synchronous=False) # COMMAND ---------- model_image.wait_for_creation(show_output=True) # COMMAND ---------- from azureml.core.compute import AksCompute, ComputeTarget # Get the resource id from https://porta..azure.com -> Find your resource group -> click on the Kubernetes service -> Properties #resource_id = "/subscriptions/<your subscription id>/resourcegroups/<your resource group>/providers/Microsoft.ContainerService/managedClusters/<your aks service name>" # Attach the cluster to your workgroup attach_config = AksCompute.attach_configuration( resource_group= "mthone-fe", # name of resource group in which AKS service is deployed cluster_name="mthoneAKS") # name of AKS service aks_target = ComputeTarget.attach( ws, 'mthone-ml-aks', attach_config ) # To be defined name of the compute target in Azure ML workspace (can be defined here) # Wait for the operation to complete aks_target.wait_for_completion(True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) # COMMAND ---------- from azureml.core.webservice import Webservice, AksWebservice # Set configuration and service name
from azureml.core.model import InferenceConfig class_inference_config = InferenceConfig(runtime='python', source_directory='service_files', entry_script='score.py', conda_file='env.yml') # now inference config is ready now So now we need to configure the compute to which the service will be deployed #if we are going for AKS cluster then we need to create the cluster and a compute target before deployment #creating the AKS cluster(Azure kubernetes service) from azureml.core.compute import ComputeTarget, AksCompute cluster_name = 'aks-cluster' compute_config = AksCompute.provisioning_configuration(location="eastus") production_cluster = ComputeTarget.create(ws, cluster_name, compute_config) production_cluster.wait_for_completion(show_output=True) from azureml.core.webservice import AksWebservice classifier_deploy_config = AksWebservice.deploy_configuration(cpu_core=1, memory_gb=1) #finally deploting the model from azureml.core.model import Model model = ws.models['classification_model'] service = Model.deploy(workspace=ws, name='classifier-service',
print("model name: ", model_name) ######################################################################################################### # Choose a name for your GPU cluster gpu_cluster_name = "aks-gpu-cluster" # Verify that cluster does not exist already try: aks_gpu_cluster = ComputeTarget(workspace=ws, name=gpu_cluster_name) print("Found existing gpu cluster") except ComputeTargetException: print("Creating new gpu-cluster") # Specify the configuration for the new cluster compute_config = AksCompute.provisioning_configuration( cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST, agent_count=1, vm_size="Standard_NC6") # Create the cluster with the specified name and configuration aks_gpu_cluster = ComputeTarget.create(ws, gpu_cluster_name, compute_config) # Wait for the cluster to complete, show the output log aks_gpu_cluster.wait_for_completion(show_output=True) ######################################################################################################### deployment_env = Environment.from_conda_specification( name="deployment_env", file_path="./configuration/deployment_env.yml") inference_config = InferenceConfig(entry_script="./scripts/score/score.py", environment=deployment_env) # Set the web service configuration (using default here)
with open("aml_config/aks_webservice.json") as f: config = json.load(f) aks_name = config["aks_name"] aks_service_name = config["aks_service_name"] compute_list = ws.compute_targets() aks_target, = (c for c in compute_list if c.name == aks_name) service = Webservice(name=aks_service_name, workspace=ws) print("Updating AKS service {} with image: {}".format( aks_service_name, image.image_location)) service.update(image=image) except: aks_name = "aks" + datetime.datetime.now().strftime("%m%d%H") aks_service_name = "akswebservice" + datetime.datetime.now().strftime( "%m%d%H") prov_config = AksCompute.provisioning_configuration(agent_count=6, vm_size="Standard_F2", location="eastus") print( "No AKS found in aks_webservice.json. Creating new Aks: {} and AKS Webservice: {}" .format(aks_name, aks_service_name)) # Create the cluster aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) # Use the default configuration (can also provide parameters to customize) aks_config = AksWebservice.deploy_configuration(enable_app_insights=True)
# Get Workspace print("Loading Workspace") cli_auth = AzureCliAuthentication() ws = Workspace.from_config(path=workspace_config_settings["path"], auth=cli_auth, _file_name=workspace_config_settings["file_name"]) print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep="\n") # Loading Image image_details = profiling_result["image_id"].split(":") image = Image(workspace=ws, name=image_details[0], version=image_details[1]) try: # Loading existing Test AKS Cluster print("Loading existing Test AKS Cluster") aks_test_cluster = AksCompute(workspace=ws, name=aks_compute_settings["name"]) # Check settings and redeploy if required settings have changed print("Found existing cluster") #aks_test_cluster.update() #print("Successfully updated Cluster definition") except ComputeTargetException: print("Loading failed ... Creating new Dev AKS Cluster") compute_config = AksCompute.provisioning_configuration( agent_count=aks_compute_settings["agent_count"], vm_size=aks_compute_settings["vm_size"], ssl_cname=aks_compute_settings["ssl_cname"], ssl_cert_pem_file=aks_compute_settings["ssl_cert_pem_file"], ssl_key_pem_file=aks_compute_settings["ssl_key_pem_file"], location=aks_compute_settings["location"], service_cidr=aks_compute_settings["service_cidr"],
'type': "regression" }) image = ContainerImage.create(name="diabetes-model", models=[model], image_config=image_config, workspace=ws) image.wait_for_creation(show_output=True) print("Provisioning an AKS cluster...") # Provision the AKS Cluster aks_name = 'myaks' try: aks_target = AksCompute(workspace=ws, name=aks_name) print('found existing Azure Kubernetes Service:', aks_target.name) except ComputeTargetException: print('creating new Azure Kubernetes Service.') # AKS configuration prov_config = AksCompute.provisioning_configuration( agent_count=3, vm_size="Standard_B4ms") # Create the cluster aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state)
myenv.python.conda_dependencies.add_channel("conda-forge") myenv.spark.packages = [ SparkPackage("com.microsoft.ml.spark", "mmlspark_2.11", "0.15"), SparkPackage("com.microsoft.azure", "azure-storage", "2.0.0"), SparkPackage("org.apache.hadoop", "hadoop-azure", "2.7.0") ] myenv.spark.repositories = ["https://mmlspark.azureedge.net/maven"] inference_config = InferenceConfig(entry_script='scoreSpark.py', environment=myenv) deployment_config = AksWebservice.deploy_configuration( auth_enabled=False, collect_model_data=True, enable_app_insights=True, cpu_cores=2, memory_gb=2) aks_target = AksCompute(ws, aks_name) service = Model.deploy(ws, service_name, [model], inference_config, deployment_config, aks_target) service.wait_for_deployment(show_output=True) print(service.state) print(service.scoring_uri) aks_webservice = {} aks_webservice['aks_name'] = service.name aks_webservice['aks_url'] = service.scoring_uri with open('../conf/' + service_name + '.json', 'w') as outfile: json.dump(aks_webservice, outfile)
'Subscription id: ' + ws.subscription_id, 'Resource group: ' + ws.resource_group, 'Workspace connected', sep='\n') # Choose a name for your cluster aks_name = "SIB2-AKS-GPU" # Check to see if the cluster already exists and create it if non existant try: aks_target = ComputeTarget(workspace=ws, name=aks_name) print('Found existing compute target') except ComputeTargetException: print('Creating a new compute target...') # Provision AKS cluster with GPU machine prov_config = AksCompute.provisioning_configuration(vm_size="Standard_NC6") # Create the cluster aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config) aks_target.wait_for_completion(show_output=True) # Define the deployment configuration gpu_aks_config = AksWebservice.deploy_configuration(autoscale_enabled=False, num_replicas=3, cpu_cores=2, memory_gb=4) # Define the inference configuration
# MAGIC # MAGIC To deploy an image, we need to create a new or connect to an existing Azure Kubernetes Service compute target. # COMMAND ---------- # MAGIC %md # MAGIC ### Create a New AKS Cluster # MAGIC # MAGIC *Note: It will take a few minutes to create a new AKS cluster* # COMMAND ---------- from azureml.core.compute import AksCompute, ComputeTarget # Use the default configuration (you can also provide parameters to customize this) prov_config = AksCompute.provisioning_configuration() aks_cluster_name = "<aks_name>" # Create the cluster aks_target = ComputeTarget.create(workspace=workspace, name=aks_cluster_name, provisioning_configuration=prov_config) # Wait for the create process to complete aks_target.wait_for_completion(show_output=True) print(aks_target.provisioning_state) print(aks_target.provisioning_errors) # COMMAND ----------
# In[78]: aks_config = AksWebservice.deploy_configuration( autoscale_enabled=False, cpu_cores=0.1, description='Student admissions logistic regression model', memory_gb=0.2, num_replicas=1, tags={'project': project}) # ## 2.11 Use an existing AKS cluster as the deployment target # In[79]: attach_config = AksCompute.attach_configuration( cluster_name=project, cluster_purpose='DevTest', # allows 1 node resource_group=project) # The cell below attaches the existing Kubernetes cluster as a compute target in the Azure ML workspace. It may take about 5 minutes. # In[80]: aks_target = ComputeTarget.attach( attach_configuration=attach_config, name=project, # limit of 16 characters workspace=ws) aks_target.wait_for_completion(True) # ## 2.12 Deploy the model and inference script to AKS # Up to this point the compute target Kubernetes cluster is empty. The step below will create several resources on the cluster, including the pod serving the prediction endpoint.