from azureml.core import Workspace,Experiment,Run, ScriptRunConfig from azureml.core.compute import ComputeTarget from azureml.core.model import InferenceConfig, Model from azureml.core.webservice import AciWebservice, Webservice from azureml.core.environment import Environment, CondaDependencies from azureml.core import ScriptRunConfig import os import shutil def custom_deploy(exp_name, run_id, env_name, mymodelname,file_path_modified_yml = './conda_env_v_1_0_0.yml',cpu_cores = 1.8, memory_gb =7): # connect to your workspace ws = Workspace.from_config() #retrieve the run from the experiment exp = Experiment(workspace=ws, name=exp_name) # get run run = Run(exp,run_id) #download outputs folder to local temp folder run.download_files('outputs','temp/') #Modify your yaml file accoding to what is needed #Create your deployment env based on the modified yaml file deplyenv = Environment.from_conda_specification(name = env_name, file_path = file_path_modified_yml) # Register the model to deploy model = run.register_model(model_name = mymodelname, model_path = "outputs/model.pkl") # Combine scoring script & environment in Inference configuration inference_config = InferenceConfig(entry_script="./temp/outputs/scoring_file_v_2_0_0.py", environment=deplyenv) # Set deployment configuration deployment_config = AciWebservice.deploy_configuration(cpu_cores = 1.8, memory_gb = 7) # Define the model, inference, & deployment configuration and web service name and location to deploy service = Model.deploy(workspace = ws, name = mymodelname, models = [model], inference_config = inference_config, deployment_config = deployment_config) shutil.rmtree('./temp')