def get_cluster(): ws = get_workspace() aks_name = AKS_NAME cts = ws.compute_targets if aks_name in cts and cts[aks_name].type == 'AKS': print('Found existing AKS cluster, will use it!') aks_target = cts[aks_name] return aks_target else: print('AKS cluster not found, sorry') return None
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 deploy_image(): ws = get_workspace() azure_image = get_image() aci_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1, tags={'method': 'sklearn'}, description='Worst model', location=LOCATION) webservice = Webservice.deploy_from_image(image=azure_image, workspace=ws, name=MODEL_NAME, deployment_config=aci_config) webservice.wait_for_deployment(show_output=True)
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 deploy_image(): ws = get_workspace() azure_image = get_image() # Set the web service configuration (using default here with app insights) aks_config = AksWebservice.deploy_configuration(enable_app_insights=True) # Unique service name service_name = AKS_NAME aks_target = get_cluster() # Webservice creation using single command aks_service = Webservice.deploy_from_image(workspace=ws, name=service_name, deployment_config=aks_config, image=azure_image, deployment_target=aks_target) aks_service.wait_for_deployment(show_output=True)
def get_service(): ws = get_workspace() services = Webservice.list(workspace=ws, compute_type='AKS') return services[0]
def model_register(): ws = get_workspace() model = Model.register(workspace=ws, model_path="../artifacts/worst.pickle", model_name="worst-model") return model
def get_model_path(): ws = get_workspace() model_path = Model.get_model_path('worst-model', _workspace=ws) return model_path
def get_experiment(): ws = get_workspace() experiment_name = EXPERIMENT_NAME exp = ws.experiments[experiment_name] return exp
def get_model(runId=get_last_run_id(), model_save_path=MODEL_PATH): ws = get_workspace() mlflow.set_tracking_uri(ws.get_mlflow_tracking_uri()) model_uri = get_model_uri(runId, model_save_path) model = mlflow.sklearn.load_model(model_uri) return model
def get_model_uri(runId=get_last_run_id(), model_save_path=MODEL_PATH): ws = get_workspace() mlflow.set_tracking_uri(ws.get_mlflow_tracking_uri()) model_uri = 'runs:/{}/{}'.format(runId, model_save_path) return model_uri