def __deploy_model(self): service_name = self.__args.service_name model = Model(self.__ws, self.__args.model_name) explainer_model = Model(self.__ws, self.__args.explainer_model_name) myenv = Environment.from_conda_specification( name=self.__config.get('DEPLOY', 'ENV_NAME'), file_path=self.__config.get('DEPLOY', 'ENV_FILE_PATH')) inference_config = InferenceConfig( entry_script=self.__config.get('DEPLOY', 'SCORE_PATH'), environment=myenv, source_directory=self.__config.get('DEPLOY', 'DEPENDENCIES_DIRECTORY')) if not self.__args.update_deployment: deployment_config = AciWebservice.deploy_configuration( cpu_cores=self.__config.getint('DEPLOY', 'ACI_CPU'), memory_gb=self.__config.getint('DEPLOY', 'ACI_MEM'), collect_model_data=True, enable_app_insights=True) service = Model.deploy(self.__ws, service_name, [model, explainer_model], inference_config, deployment_config) else: service = AciWebservice(self.__ws, service_name) service.update(models=[model, explainer_model], inference_config=inference_config) service.wait_for_deployment(show_output=True) print(service.state) print(service.get_logs())
def main(): ws = Workspace.from_config() conda = CondaDependencies() conda.add_conda_package("python==3.5") conda.add_pip_package("h5py==2.8.0") conda.add_pip_package("html5lib==1.0.1") conda.add_pip_package("keras==2.2.0") conda.add_pip_package("Keras-Applications==1.0.2") conda.add_pip_package("Keras-Preprocessing==1.0.1") conda.add_pip_package("matplotlib==2.2.2") conda.add_pip_package("numpy==1.14.5") conda.add_pip_package("opencv-python==3.3.0.9") conda.add_pip_package("pandas==0.23.3") conda.add_pip_package("Pillow==5.2.0") conda.add_pip_package("requests==2.19.1") conda.add_pip_package("scikit-image==0.14.0") conda.add_pip_package("scikit-learn==0.19.2") conda.add_pip_package("scipy==1.1.0") conda.add_pip_package("sklearn==0.0") conda.add_pip_package("tensorflow==1.9.0") conda.add_pip_package("urllib3==1.23") conda.add_pip_package("azureml-sdk") with open("environment.yml", "w") as f: f.write(conda.serialize_to_string()) with open("environment.yml", "r") as f: print(f.read()) image_config = ContainerImage.image_configuration( execution_script="score.py", runtime="python", conda_file="environment.yml", docker_file="Dockerfile", dependencies=DEPENDENCIES) webservices = ws.webservices(compute_type='ACI') image = ContainerImage.create(name="ai-bootcamp", models=[], image_config=image_config, workspace=ws) image.wait_for_creation(show_output=True) webservices_list = [] for key in webservices: webservices_list.append(key) service_name = webservices_list[0] aciwebservice = AciWebservice(ws, service_name) aciwebservice.update(image=image)
def deploy(): parser = argparse.ArgumentParser() parser.add_argument("--model_name", required=True) parser.add_argument("--model_path", required=True) args = parser.parse_args() print(f"model_name : {args.model_name}") print(f"model_path: {args.model_path}") run = Run.get_context() ws = run.experiment.workspace model = Model.register(workspace=ws, model_path=args.model_path, model_name=args.model_name) print("Registered version {0} of model {1}".format(model.version, model.name)) inference_config = InferenceConfig( entry_script='score.py', runtime='python', conda_file='conda.yml', extra_docker_file_steps='extra_docker_steps', source_directory='server_files/') deployment_config = AciWebservice.deploy_configuration(cpu_cores=0.1, memory_gb=0.5, auth_enabled=True) try: service = AciWebservice(ws, "testscorescriptauto") service.update(models=[model]) print("EXISTING ENDPOINT FOUND: MODEL UPDATED") except Exception: Model.deploy(ws, "testscorescriptauto", [model], inference_config, deployment_config) print("NO EXISTING ENDPOINT FOUND: DEPLOYED MODEL TO NEW ENDPOINT")
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"], enable_app_insights=aci_settings["enable_app_insights"]) print("Successfully updated existing ACI service") except WebserviceException: print("Failed to update ACI service... Creating new ACI instance") aci_config = AciWebservice.deploy_configuration( cpu_cores=profiling_result["cpu"], memory_gb=profiling_result["memory"], tags=deployment_settings["image"]["tags"], properties=deployment_settings["image"]["properties"], description=deployment_settings["image"]["description"], location=aci_settings["location"], auth_enabled=aci_settings["auth_enabled"],