def deploy_service(ws, model, inference_config, service_name, compute_target): tags = {'model': '{}:{}'.format(model.name, model.version)} try: service = Webservice(ws, service_name) print("Service {} exists, update it".format(service_name)) service.update(models=[model], inference_config=inference_config, tags=tags) except Exception: print('deploy a new service {}'.format(service_name)) deployment_config = AksWebservice.deploy_configuration( cpu_cores=1, memory_gb=2, tags=tags, collect_model_data=True, enable_app_insights=True) service = Model.deploy(ws, service_name, [model], inference_config, deployment_config, compute_target) service.wait_for_deployment(show_output=True) if service.auth_enabled: token = service.get_keys()[0] elif service.token_auth_enabled: token = service.get_token()[0] return service.scoring_uri, token
def update_service(aml_interface): inference_config = get_inference_config(aml_interface) service = Webservice(name=DEPLOYMENT_SERVICE_NAME, workspace=aml_interface.workspace) model = aml_interface.workspace.models.get(MODEL_NAME) service.update(models=[model], inference_config=inference_config) print(service.state) print(service.scoring_uri)
def deploy(workspace, name, model, script, source_directory, environment=None, target='local', cpu_cores=1, memory_gb=1, compute_target_name=None): inference_config = InferenceConfig(entry_script=script, source_directory=source_directory, environment=environment) if target == 'local': deployment_config = LocalWebservice.deploy_configuration(port=8890) elif target == 'aci': deployment_config = AciWebservice.deploy_configuration( cpu_cores=cpu_cores, memory_gb=memory_gb) elif target == 'aks': if compute_target_name is None: print("compute_target_name required when target='aks'") return None deployment_config = AksWebservice.deploy_configuration( cpu_cores=cpu_cores, memory_gb=memory_gb, compute_target_name=compute_target_name, auth_enabled=False) try: service = Webservice(workspace, name) except WebserviceException: service = None if service is None: service = Model.deploy(workspace, name, [model], inference_config, deployment_config) else: print( "Existing service with that name found, updating InferenceConfig\n" "If you meant to redeploy or change the deployment option, first " "delete the existing service.") service.update(models=[model], inference_config=inference_config) return service
from azureml.core import Workspace from azureml.core.webservice import Webservice # Requires the config to be downloaded first to the current working directory ws = Workspace.from_config() # Set with the deployment name name = "automl-voting-ensemble" # load existing web service service = Webservice(name=name, workspace=ws) service.update(enable_app_insights=True) logs = service.get_logs() for line in logs.split('\n'): print(line)
# image = max(images, key=attrgetter('version')) # print('From Max Version, Image used to deploy webservice on ACI: {}\nImage Version: {}\nImage Location = {}'.format(image.name, image.version, image.image_location)) # Check if AKS already Available try: 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)
from azureml.core.webservice import AciWebservice, Webservice from inference_config import ws, m_inference_config from azureml.core.model import Model #deployment_config = AciWebservice.deploy_configuration(memory_gb=4) #model = Model(ws, id="test_model_1:1") service = Webservice(ws, "mytestservice2") service.update(inference_config=m_inference_config) service.wait_for_deployment(show_output=True) print(service.state)
deployment_config=deployment_config) service.wait_for_deployment(show_output=True) print(service.state) print(service.scoring_uri) print(service.get_logs()) else: print(" ") print("**************************************") print("Existing Service, updating the service") print(" ") print("**************************************") service = Webservice(name=DEPLOYMENT_SERVICE_NAME, workspace=ws) service.update(models=[model], inference_config=inference_config) print(service.state) print(service.scoring_uri) print(service.get_logs()) # AKS deployment **************************************************************************************** from azureml.core.webservice import AksWebservice, Webservice from azureml.core.webservice import AksEndpoint from azureml.core.compute import AksCompute from azureml.core.compute import ComputeTarget print("AKS deployement ") AKS_DELOYMENT_SERVICE_NAME = "aks-dgraphics1" AML_AKS_COMPUTE_NAME = "aks-amlcompute" aks_target = ComputeTarget(ws, AML_AKS_COMPUTE_NAME) namespace_name = "default"
# MAGIC %md ### Deploy to the model's image to the specified AKS cluster # COMMAND ---------- from azureml.core.webservice import Webservice, AksWebservice from azureml.core.image import Image # Get Model model_image = Image(workspace, id=model_image_id) # Get Webservice prod_webservice_name = "wine-quality-aks" try: prod_webservice = Webservice(workspace, prod_webservice_name) print('updating existing webservice.') prod_webservice.update(image=model_image) prod_webservice.wait_for_deployment(show_output=True) except: print('creating new webservice.') # Set configuration and service name prod_webservice_deployment_config = AksWebservice.deploy_configuration() # Deploy from image prod_webservice = Webservice.deploy_from_image( workspace=workspace, name=prod_webservice_name, image=model_image, deployment_config=prod_webservice_deployment_config, deployment_target=aks_target) # Wait for the deployment to complete prod_webservice.wait_for_deployment(show_output=True)
# You can update the same AKS service when you want to update next time(REST end points won't change) from azureml.core.model import Model from azureml.core import Workspace from azureml.core.model import InferenceConfig from azureml.core.webservice import Webservice ws = Workspace.from_config() service_name = 'sentimentclassifier' model_1 = Model(ws, name='onboard_sentiment_vector.pkl') model_2 = Model(ws, name='onboard_sentiment_classifier.pkl') model_3 = Model(ws, name='onboard_vector.pkl') model_4 = Model(ws, name='onboard_classifier.pkl') inference_config = InferenceConfig(runtime="python", entry_script="AMLscore.py", conda_file="aml_config/myenv.yml") # Retrieve existing service. service = Webservice(name=service_name, workspace=ws) service.update(models=[model_1, model_2, model_3, model_4], inference_config=inference_config) print(service.state) print(service.get_logs())