def create_service(self): iothub_compute = IotHubCompute(self.ws, self.iot_device_id) print('IotHubCompute:\n{0}'.format(iothub_compute)) routes = {"route": "FROM /messages/* INTO "} # Here, we define the Azure ML module with the container_config options above aml_module = IotBaseModuleSettings(name=self.module_name, create_option=self.container_config) # This time, we will leave off the external module from the deployment manifest deploy_config = IotWebservice.deploy_configuration( device_id=self.iot_device_id, routes=routes, aml_module=aml_module) # Deploy from latest version of image, using module_name as your IotWebservice name iot_service_name = self.module_name # Can specify version=x, otherwise will grab latest image = Image(self.ws, self.image_name) print('Deploying image: {0}'.format(image)) iot_service = IotWebservice.deploy_from_image(self.ws, iot_service_name, image, deploy_config, iothub_compute)
# MAGIC %md # MAGIC # MAGIC ### Option 2: Connected to a previously created image # COMMAND ---------- import mlflow.azureml from azureml.core import Image from azureml.core.image import ContainerImage #enter the image name from the Azure ML workspace image_name = "model" #retrieve the image configuration model_image = Image(workspace, name=image_name) # COMMAND ---------- # #for DEV deployments, Azure Container Instances from azureml.core.webservice import AciWebservice, Webservice dev_webservice_name = "skurecs-dev" dev_webservice_deployment_config = AciWebservice.deploy_configuration() dev_webservice = Webservice.deploy_from_image( name=dev_webservice_name, image=model_image, deployment_config=dev_webservice_deployment_config, workspace=workspace)
latest_model_accuracy = latest_model_run.get_metrics().get("acc") print('Latest model accuracy: ', latest_model_accuracy) ws_list = Webservice.list(ws, model_name=latest_model_name) print('webservice list') print(ws_list) deploy_model = False current_model = None if (len(ws_list) > 0): webservice = ws_list[0] try: image_id = webservice.tags['image_id'] image = Image(ws, id=image_id) current_model = image.models[0] print('Found current deployed model!') except: deploy_model = True print('Image id tag not found!') else: deploy_model = True print('No deployed webservice for model: ', latest_model_name) current_model_accuracy = -1 # undefined if current_model != None: current_model_run = Run(run.experiment, run_id=current_model.tags.get("run_id")) current_model_accuracy = current_model_run.get_metrics().get("acc") print('accuracies')
with open(os.path.join("aml_service", "profiling_result.json")) as f: profiling_result = json.load(f) # Get workspace print("Loading Workspace") cli_auth = AzureCliAuthentication() config_file_path = os.environ.get("GITHUB_WORKSPACE", default="aml_service") config_file_name = "aml_arm_config.json" ws = Workspace.from_config(path=config_file_path, auth=cli_auth, _file_name=config_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]) # Deploying model on ACI print("Deploying model on ACI") try: print("Trying to update existing ACI service") dev_service = AciWebservice(workspace=ws, name=aci_settings["name"]) dev_service.update(image=image, tags=deployment_settings["image"]["tags"], properties=deployment_settings["image"]["properties"], description=deployment_settings["image"]["description"], auth_enabled=aci_settings["auth_enabled"], ssl_enabled=aci_settings["ssl_enabled"], ssl_cert_pem_file=aci_settings["ssl_cert_pem_file"], ssl_key_pem_file=aci_settings["ssl_key_pem_file"], ssl_cname=aci_settings["ssl_cname"],
previouslyDeployedRestServiceFound = False print('..4. completed') print('') print('') print( '5. Get the previously deployed model from previously deployed REST service, if any' ) print('.............................................') previouslyDeployedModel = None if previouslyDeployedRestService != None: try: previouslyDeployedContainerImageId = previouslyDeployedRestService.tags[ 'image_id'] previouslyDeployedContainerImage = Image(amlWs, id=image_id) previouslyDeployedModel = previouslyDeployedContainerImage.models[0] print( 'Found the model of the previously deployed REST service, for the experiment!' ) except: print( 'No previously deployed container image not found for the experiment!' ) else: deployModelBool = True print('No deployed Rest service for model: ', currentlyTrainedModelName) print('..5. completed') print('') print('')
ws = Workspace(auth=spAuth, subscription_id=subscription_id, resource_group=resource_group, workspace_name=workspace_name) print("Loaded workspace: " + ws.name) build_version = os.environ["BUILD_BUILDNUMBER"] aciconfig = AciWebservice.deploy_configuration( cpu_cores=2, memory_gb=4, tags={'BuildVersion': build_version}, description= 'Container instance hosting web service to consume ABC Bricks routing solution' ) image = Image(ws, name="breast-cancer-image", tags=[['BuildVersion', build_version]]) print("Picked image with version: " + str(image.version) + " which was built on : " + str(image.created_time)) aci_service = Webservice.deploy_from_image(deployment_config=aciconfig, image=image, name='breast-cancer-instance', workspace=ws) aci_service.wait_for_deployment(True) print(aci_service.state) print(aci_service.scoring_uri)
required=True) args = parser.parse_args() print("Argument 1: %s" % args.service_name) print("Argument 2: %s" % args.aci_name) print("Argument 3: %s" % args.description) print('creating AzureCliAuthentication...') cli_auth = AzureCliAuthentication() print('done creating AzureCliAuthentication!') print('get workspace...') ws = Workspace.from_config(auth=cli_auth) print('done getting workspace!') image = Image(ws, image_name) print(image) ws_list = Webservice.list(ws, image_name=image_name) print(ws_list) if len(ws_list) > 0: if ws_list[0].name == args.service_name: print('Deleting: ', ws_list[0].name) ws_list[0].delete() print('Done') aci_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1, tags={'name': args.aci_name}, description=args.description)
def create_service(self): self.iothub_compute = IotHubCompute(self.ws, self.iot_device_id) compute_targets = ComputeTarget.list(self.ws) for t in compute_targets: if t.type == "IotHub": print("IotHub '{}' has provisioning state '{}'.".format(t.name, t.provisioning_state)) self.container_config = """{ "ExposedPorts": { "50051/tcp": {} }, "HostConfig": { "Binds": [ "/etc/hosts:/etc/hosts" ], "Privileged": true, "Devices": [ { "PathOnHost": "/dev/catapult0", "PathInContainer": "/dev/catapult0" }, { "PathOnHost": "/dev/catapult1", "PathInContainer": "/dev/catapult1" } ], "PortBindings": { "50051/tcp": [ { "HostPort": "50051" } ] } } }""" self.routes = { "route": "FROM /messages/* INTO " } # Here, we define the Azure ML module with the container_config options above self.aml_module = IotBaseModuleSettings( name = self.module_name, create_option = self.container_config ) # This time, we will leave off the external module from the deployment manifest self.deploy_config = IotWebservice.deploy_configuration( device_id = self.iot_device_id, routes = self.routes, aml_module = self.aml_module ) # Deploy from latest version of image, using module_name as your IotWebservice name iot_service_name = self.module_name # Can specify version=x, otherwise will grab latest self.image = Image(self.ws, self.image_name) self.iot_service = IotWebservice.deploy_from_image( self.ws, iot_service_name, self.image, self.deploy_config, self.iothub_compute )
print('') print('5. Authenticating with AzureCliAuthentication...') clientAuthn = AzureCliAuthentication() print('..5.completed') print('') print('') print('6. Instantiate AML workspace') amlWs = Workspace.from_config(auth=clientAuthn) print('..6.completed') print('') print('') print('7. Instantiate image') containerImage = Image(amlWs, id=image_id) print(containerImage) print('..7.completed') print('') print('') print('8. Check for and delete any existing web service instance') aksName = args.aks_name aksRegion = args.aks_region aksServiceName = args.service_name print('aksName=', aksName) print('aksRegion=', aksRegion) print('aksServiceName=', aksServiceName)