コード例 #1
0
    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())
コード例 #2
0
def get_environment(name="deploy", file_path="environment.yml"):
    """
    Return an environment
    """
    environment = Environment.from_conda_specification(
        name=name,
        file_path=file_path,
    )
    environment.python.user_managed_dependencies = False
    environment.docker.enabled = True
    environment.docker.base_image = (
        "mcr.microsoft.com/azureml/intelmpi2018.3-ubuntu16.04:20200821.v1"
    )
    return environment
コード例 #3
0
def main():
    ws = Workspace.get(name=WORKSPACE_NAME,
                       subscription_id=SUBSCRIPTION_ID,
                       resource_group=RESOURCE_GROUP)

    print("connect")

    model = Model.register(model_path=os.path.join(
        os.getcwd(), "retailai_recommendation_model.zip"),
                           model_name="retailai_recommendation_model",
                           description="Retail.AI Item-Based Recommender",
                           workspace=ws)
    print("model registered")

    myenv = Environment.from_conda_specification(name='myenv',
                                                 file_path="environment.yml")
    myenv.docker.base_image = "mcr.microsoft.com/mmlspark/release"
    myenv.inferencing_stack_version = 'latest'
    print("Environment Configured")

    inference_config = InferenceConfig(entry_script='score.py',
                                       environment=myenv)
    aks_target_name = AKS_CLUSTER_NAME

    try:
        aks_target = AksCompute(ws, aks_target_name)
        print(aks_target)
    except ComputeTargetException as err:
        aks_target = attachAksComputeToWorkspace(ws, RESOURCE_GROUP,
                                                 AKS_CLUSTER_NAME,
                                                 aks_target_name, True)
        print(aks_target)
    except Exception as err:
        print(err)
        sys.exit()
    try:
        deployToAks(ws, aks_target, "retail-ai-item-recommender", model,
                    inference_config, True)
    except Exception as err:
        print(err)
        sys.exit()
コード例 #4
0
from azureml.core.model import InferenceConfig
from azureml.core.environment import Environment
from azureml.core import Workspace
from azureml.core.model import Model
from azureml.core.webservice import AciWebservice

ws = Workspace.from_config(path='./.azureml', _file_name='config.json')
model = Model(ws, name='titanic_model', version=2)

env = Environment.from_conda_specification(
    name='sklearn-aml-env', file_path='./.azureml/sklearn-env-aml.yml')

inference_config = InferenceConfig(entry_script="./src/score.py",
                                   environment=env)

deployment_config = AciWebservice.deploy_configuration(cpu_cores=1,
                                                       memory_gb=1)

aci_service = Model.deploy(workspace=ws,
                           name='titanic-model-2',
                           models=[model],
                           inference_config=inference_config,
                           deployment_config=deployment_config)

aci_service.wait_for_deployment(show_output=True)
print(aci_service.state)
コード例 #5
0
    print("Creating new gpu-cluster")

    # Specify the configuration for the new cluster
    compute_config = AksCompute.provisioning_configuration(
        cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST,
        agent_count=1,
        vm_size="Standard_NC6")
    # Create the cluster with the specified name and configuration
    aks_gpu_cluster = ComputeTarget.create(ws, gpu_cluster_name,
                                           compute_config)

    # Wait for the cluster to complete, show the output log
    aks_gpu_cluster.wait_for_completion(show_output=True)

#########################################################################################################
deployment_env = Environment.from_conda_specification(
    name="deployment_env", file_path="./configuration/deployment_env.yml")
inference_config = InferenceConfig(entry_script="./scripts/score/score.py",
                                   environment=deployment_env)

# Set the web service configuration (using default here)
aks_config = AksWebservice.deploy_configuration(
    cpu_cores=2,
    auth_enabled=True,  # this flag generates API keys to secure access
    memory_gb=8,
    #tags={'name': 'mnist', 'framework': 'Keras'},
    #max_request_wait_time=300000,scoring_timeout_ms=300000,
    description='X-Ray ML Estimator AKS endpoint')

#########################################################################################################

service_name = 'mlops-estimator-model-aks'
from azureml.core.webservice import Webservice
from azureml.core.model import InferenceConfig
from azureml.core.environment import Environment
from azureml.core import Workspace
from azureml.core.model import Model
from azureml.core.webservice import LocalWebservice

ws = Workspace.from_config(path='./.azureml', _file_name='config.json')
model = Model(ws, name='mic_model.h5', version=2)

env = Environment.from_conda_specification(
    name='mic-env', file_path='./.azureml/multiclass-image-classification.yml')

inference_config = InferenceConfig(entry_script="./src/score.py",
                                   environment=env)

deployment_config = LocalWebservice.deploy_configuration(port=6789)

local_service = Model.deploy(workspace=ws,
                             name='mic-model-local',
                             models=[model],
                             inference_config=inference_config,
                             deployment_config=deployment_config)

local_service.wait_for_deployment(show_output=True)
print(f"Scoring URI is : {local_service.scoring_uri}")
コード例 #7
0
                    default="onnx-demo",
                    help='the web service name')
args = parser.parse_args()

print("Model name: ", args.name)
print("Model version: ", args.version)

# Load the AML Workspace and Model
ws = Workspace.from_config(auth=AzureCliAuthentication())

model = Model(workspace=ws, name=args.name, version=args.version)

# Configure Scoring App Environment
scoringenv = Environment.from_conda_specification(
    name="scoringenv",
    file_path=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                           '../../environments/',
                           'scoring/conda_dependencies.yml'))

inference_config = InferenceConfig(entry_script=os.path.join(
    os.path.dirname(os.path.realpath(__file__)), '../modeling/score.py'),
                                   environment=scoringenv)

# Configure Deployment Compute
compute_config = AciWebservice.deploy_configuration(
    cpu_cores=1,
    memory_gb=1,
    tags={'demo': 'onnx'},
    description='ONNX for text')

# Run the deployment
コード例 #8
0
def deploy_custom():
    subscription_id = request.json['subscription_id']
    resource_group = request.json['resource_group']
    workspace_name = request.json['workspace_name']
    location = request.json['location']
    deploy_mode = request.json['deploy_mode']  # AKS or ACI
    exp_name = request.json['exp_name']  #Model file Path
    reg_model_name = request.json['reg_model_name']  #Model name
    description = request.json['description']
    score_path = request.json['score_path']  #Python scoring file
    conda_en_path = request.json['conda_en_path']  #yml file
    service_name = request.json['service_name']

    if (deploy_mode == "AKS"):
        cluster_name = request.json['cluster_name']

    flg = 1
    if (flg == 1):

        import logging
        from matplotlib import pyplot as plt
        import numpy as np
        import pandas as pd
        from sklearn import datasets
        from azureml.core import Workspace

        import azureml.core
        from azureml.core.experiment import Experiment
        from azureml.core.workspace import Workspace
        from azureml.train.automl import AutoMLConfig
        from azureml.core.compute import AmlCompute
        from azureml.core.compute import ComputeTarget
        from azureml.core.runconfig import RunConfiguration
        from azureml.core.conda_dependencies import CondaDependencies

        #ws = Workspace.from_config()
        #!pip install azure.cli
        from azureml.core.authentication import AzureCliAuthentication
        import azure.cli.core
        #cli_auth = AzureCliAuthentication()

        ws = Workspace(subscription_id=subscription_id,
                       resource_group=resource_group,
                       workspace_name=workspace_name)

        print("Found workspace {} at location {}".format(ws.name, ws.location))
        print('Found existing Workspace.')

        cwd = 'D:\\DCSAIAUTOML\\BestModels\\Custom'
        model_path = cwd + '\\' + exp_name + '\\best_model.pkl'
        #model_path = os.path.join(cwd, exp_name)

        from azureml.core.model import Model
        # Tip: When model_path is set to a directory, you can use the child_paths parameter to include
        #      only some of the files from the directory
        model = Model.register(model_path=model_path,
                               model_name=reg_model_name,
                               description=description,
                               workspace=ws)

        model = Model(ws, name=reg_model_name)
        print(model.name, model.id, model.version, sep='\t')

        from azureml.core.model import InferenceConfig
        from azureml.core.webservice import AciWebservice
        from azureml.core.webservice import Webservice
        from azureml.core.model import Model
        from azureml.core.environment import Environment
        script_file_name = score_path
        conda_env_file_name = conda_en_path

        myenv = Environment.from_conda_specification(
            name="myenv", file_path=conda_env_file_name)
        inference_config = InferenceConfig(entry_script=script_file_name,
                                           environment=myenv)
        print(inference_config)
        service_name = service_name
        if (deploy_mode == "ACI"):
            # ACI deploment with-out DOCKER
            from azureml.core.model import Model
            model = Model(ws, id=model.id)

            try:
                deployment_config = AciWebservice.deploy_configuration(
                    cpu_cores=1, memory_gb=2)

                service = Model.deploy(ws, service_name, [model],
                                       inference_config, deployment_config)
                service.wait_for_deployment(show_output=True)
                print(service.state)
                compute_type = service.compute_type
                state = service.state
                url = service.scoring_uri
                s_url = service.swagger_uri
                #created_time = service.created_time
                #updated_time = service.updated_time
                v1 = "@"
                v2 = "Deployed Successfully"
                print(v2)
                return '{} {} {} {} {} {} {} {} {}'.format(
                    v2, v1, compute_type, v1, state, v1, url, v1, s_url)

            except Exception as e:
                error_statement = str(e)
                print("Error statement: ", error_statement)
                return error_statement

        else:  #AKS deployment

            from azureml.core.model import InferenceConfig
            from azureml.core.webservice import AciWebservice
            from azureml.core.model import Model
            from azureml.core.environment import Environment
            from azureml.core.webservice import AksWebservice, Webservice

            model = Model(ws, id=model.id)

            from azureml.core.compute import AksCompute, ComputeTarget
            service_name = service_name
            aks_target = AksCompute(ws, cluster_name)
            # If deploying to a cluster configured for dev/test, ensure that it was created with enough
            # cores and memory to handle this deployment configuration. Note that memory is also used by
            # things such as dependencies and AML components.
            try:
                deployment_config = AksWebservice.deploy_configuration(
                    cpu_cores=1,
                    memory_gb=2,
                    enable_app_insights=True,
                    collect_model_data=True,
                )
                service = Model.deploy(ws, service_name, [model],
                                       inference_config, deployment_config,
                                       aks_target)
                service.wait_for_deployment(show_output=True)
                print(service.state)
                compute_type = service.compute_type
                state = service.state
                url = service.scoring_uri
                s_url = service.swagger_uri
                #created_time = service.created_time
                #updated_time = service.updated_time
                v1 = "@"
                v2 = "Deployed Successfully"
                print(v2)
                return '{} {} {} {} {} {} {} {} {}'.format(
                    v2, v1, compute_type, v1, state, v1, url, v1, s_url)

            except Exception as e:
                error_statement = str(e)
                print("Error statement: ", error_statement)
                return error_statement
コード例 #9
0
from azureml.core.environment import Environment
from azureml.core.model import InferenceConfig, Model
from azureml.core.webservice import LocalWebservice


# Create inference configuration based on the environment definition and the entry script
myenv = Environment.from_conda_specification(name="ml", file_path="C:\\Users\\rbenn\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\home\\rbennett\\mlenvironment.yml")
inference_config = InferenceConfig(entry_script="EntryScript.py", environment=myenv)
# Create a local deployment, using port 8890 for the web service endpoint
deployment_config = LocalWebservice.deploy_configuration(port=8890)
# Deploy the service
service = Model.deploy(
    ws, "mymodel", [model], inference_config, deployment_config)
# Wait for the deployment to complete
service.wait_for_deployment(True)
# Display the port that the web service is available on
print(service.port)
コード例 #10
0
# %%
from azureml.core.conda_dependencies import CondaDependencies 

myenv = CondaDependencies.create(pip_packages=["numpy","onnxruntime","azureml-core", "azureml-defaults"])

with open("myenv.yml","w") as f:
    f.write(myenv.serialize_to_string())   

# %%    
# 
from azureml.core.model import InferenceConfig
from azureml.core.environment import Environment


myenv = Environment.from_conda_specification(name="myenv", file_path="myenv.yml")
inference_config = InferenceConfig(entry_script="score.py", environment=myenv) 

# %%    
from azureml.core.webservice import AciWebservice

aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1, 
                                               memory_gb = 1, 
                                               tags = {'demo': 'onnx'}, 
                                               description = 'web service for MNIST ONNX model')
#%%
from azureml.core.model import Model
from random import randint

aci_service_name = 'onnx-demo-mnist'+str(randint(0,100))
print("Service", aci_service_name)
コード例 #11
0
                             primary_metric='normalized_root_mean_squared_error',
                             training_data=dataset,
							 compute_target=compute_target,
                             label_column_name=dataset_label_column)

#Execute the AutoML run
experiment = Experiment(ws, experiment_name)
run = experiment.submit(automl_config, show_output=True)
run.wait_for_completion()

#Get the best model from the AutoML run and register it
best_run = run.get_best_child()
best_run.download_files(prefix='outputs', append_prefix=False)
model = Model.register(model_path='outputs/model.pkl',
                       model_name=model_name,
                       workspace=ws)

#Prepare an environment for the model
myenv = Environment.from_conda_specification(name='project_environment', file_path='outputs/conda_env_v_1_0_0.yml')
myenv.docker.enabled = True
inference_config = InferenceConfig(entry_script='outputs/scoring_file_v_1_0_0.py', environment=myenv)

#Create Docker container for the model
package = Model.package(ws, [model], inference_config,
					   image_name=docker_image_name,
					   image_label=docker_image_label)
package.wait_for_creation(show_output=True)

#Update web app with the latest container
requests.post(docker_webhook_url)
コード例 #12
0
with open(script_file_name, 'w') as cefw:
    content = content.replace('<<groups>>', args.group_column_names.rstrip())
    cefw.write(
        content.replace('<<time_colname>>', args.time_column_name.rstrip()))

with open(script_file_name, 'r') as cefr1:
    content1 = cefr1.read()
print(content1)

model_list = json.loads(args.model_names)
print(model_list)

run = Run.get_context()
ws = run.experiment.workspace

myenv = Environment.from_conda_specification(name="env",
                                             file_path=conda_env_file_name)

deployment_config = AciWebservice.deploy_configuration(
    cpu_cores=1,
    memory_gb=2,
    tags={"method": "grouping"},
    description='grouping demo aci deployment')

inference_config = InferenceConfig(entry_script=script_file_name,
                                   environment=myenv)

models = []
for model_name in model_list:
    models.append(Model(ws, name=model_name))

service = Model.deploy(ws,
コード例 #13
0
from azureml.core.model import InferenceConfig
from azureml.core.environment import Environment
from azureml.core import Workspace
from azureml.core.model import Model
from azureml.core.webservice import AciWebservice

ws = Workspace.from_config(path='./.azureml', _file_name='config.json')
model = Model(ws, name='model', version=4)

env = Environment.from_conda_specification(
    name='remote-env', file_path='./.azureml/remote-env.yml')

inference_config = InferenceConfig(entry_script="./src/score.py",
                                   environment=env)

deployment_config = AciWebservice.deploy_configuration(cpu_cores=1,
                                                       memory_gb=1)

aci_service = Model.deploy(workspace=ws,
                           name='model-service',
                           models=[model],
                           inference_config=inference_config,
                           deployment_config=deployment_config)

aci_service.wait_for_deployment(show_output=True)
print(aci_service.state)
コード例 #14
0
# 07-deploy-azure-model-local.py
from azureml.core.webservice import Webservice
from azureml.core.model import InferenceConfig
from azureml.core.environment import Environment
from azureml.core import Workspace
from azureml.core.model import Model
from azureml.core.webservice import LocalWebservice

ws = Workspace.from_config(path='./.azureml', _file_name='config.json')
model = Model(ws, name='mon_rcv_model', version=1)

env = Environment.from_conda_specification(
    name='rcv-aml-env', file_path='./.azureml/rcv-local-env.yml')

inference_config = InferenceConfig(entry_script="./src/score.py",
                                   environment=env)

deployment_config = LocalWebservice.deploy_configuration(port=6789)

local_service = Model.deploy(workspace=ws,
                             name='rcv-local',
                             models=[model],
                             inference_config=inference_config,
                             deployment_config=deployment_config)

local_service.wait_for_deployment(show_output=True)
print(f"Scoring URI is : {local_service.scoring_uri}")
コード例 #15
0
def register_enviroment(workspace, name, file_path):
    myenv = Environment.from_conda_specification(name=name, file_path=file_path)
    myenv = myenv.register(workspace=workspace)
    return myenv
コード例 #16
0
ファイル: initialise.py プロジェクト: Foresights-IT/MhMohona
    Returns
    -------
    CondaDependencies
        collection of conda dependencies
    """
    return CondaDependencies().create(conda_packages=pkg_list)

# Initialise variables
ENV_NAME = 'heart-failure'
run_pkg = ['pip', 'joblib', 'pandas', 'numpy', 'pyodbc', 'scikit-learn']
test_pkg = run_pkg + ['pytest', 'pylint', 'requests']
workspace = Workspace.from_config()

# Create dependencies for running
run_dependencies = dep_from_pkg_list(run_pkg)
run_dependencies.save('./conda_env.yaml')

# Push to environment
env = Environment.from_conda_specification(ENV_NAME, './conda_env.yaml')
env.python.conda_dependencies=run_dependencies
env.register(workspace=workspace)

# Create dependencies for testing
test_dependencies = dep_from_pkg_list(test_pkg)
test_dependencies.save('./conda_env_test.yaml')

# Initialise metadata
with open('./metadata.json', 'w') as f:
    json.dump({'env_name': ENV_NAME}, f)
コード例 #17
0
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)

    aks_target.wait_for_completion(show_output=True)

# Define the deployment configuration
gpu_aks_config = AksWebservice.deploy_configuration(autoscale_enabled=False,
                                                    num_replicas=3,
                                                    cpu_cores=2,
                                                    memory_gb=4)

# Define the inference configuration
myenv = Environment.from_conda_specification(
    name="testEnv",
    file_path=
    "C:/Users/Danilo.Bento/Icon Dropbox/DEVDATA/RO/DEVELOPMENT/SIB2/tutorials/model5/mod5_deploy/deploy_env.yaml"
)

myenv.docker.base_image = DEFAULT_GPU_IMAGE
inference_config = InferenceConfig(  #entry_script=os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'yolov5','score.py'),
    #entry_script="./yolov5/score.py",
    entry_script="score.py",
    environment=myenv,
    source_directory=
    "C:/Users/Danilo.Bento/Icon Dropbox/DEVDATA/RO/DEVELOPMENT/SIB2/tutorials/model5/mod5_deploy/deployassets"
)

# Name of the web service that is deployed
aks_service_name = 'aks-mod5-test'
# Get the registerd model
コード例 #18
0
def DeployAzureAKS():
    subscription_id = request.json['subscription_id']
    resource_group = request.json['resource_group']
    workspace_name = request.json['workspace_name']
    location = request.json['location']
    best_model = request.json['best_model']
    Model_path = request.json['Model_path']
    cluster_name = request.json['cluster_name']
    service_name = request.json['service_name']
    Reg_model_name = request.json['Reg_model_name']

    ws = Workspace(subscription_id=subscription_id,
                   resource_group=resource_group,
                   workspace_name=workspace_name)

    print("Found workspace {} at location {}".format(ws.name, ws.location))
    print('Found existing Workspace.')

    from azureml.core.model import Model
    model = Model(ws, name=Reg_model_name)
    print(model)

    from azureml.core.model import InferenceConfig
    from azureml.core.webservice import AciWebservice
    from azureml.core.webservice import Webservice
    from azureml.core.model import Model
    from azureml.core.environment import Environment

    from sklearn.externals import joblib
    cwd = 'D:\\DCSAIAUTOML\\BestModels\\Azure'
    model_path = os.path.join(cwd, Model_path, best_model, "outputs")
    #model_path1 = os.path.join(model_path, "outputs", "model.pkl")
    print(model_path)
    os.chdir(model_path)
    #import importlib
    script_file_name = 'scoring_file_v_1_0_0.py'
    conda_env_file_name = 'conda_env_v_1_0_0.yml'
    #importlib.import_module('scoring_file_v_1_0_0.py')
    #script_file_name = joblib.load('scoring_file_v_1_0_0.py')
    #import yaml
    #conda_env_file_name = yaml.load(open('conda_env_v_1_0_0.yml'))
    #conda_env_file_name = joblib.load('conda_env_v_1_0_0.yml')

    myenv = Environment.from_conda_specification(name="myenv",
                                                 file_path=conda_env_file_name)
    inference_config = InferenceConfig(entry_script=script_file_name,
                                       environment=myenv)

    aks_target = AksCompute(ws, cluster_name)
    # If deploying to a cluster configured for dev/test, ensure that it was created with enough
    # cores and memory to handle this deployment configuration. Note that memory is also used by
    # things such as dependencies and AML components.
    try:
        deployment_config = AksWebservice.deploy_configuration(
            cpu_cores=2,
            memory_gb=16,
            enable_app_insights=True,
            collect_model_data=True,
        )
        service = Model.deploy(ws, service_name, [model], inference_config,
                               deployment_config, aks_target)
        service.wait_for_deployment(show_output=True)
        print(service.state)
        compute_type = service.compute_type
        state = service.state
        url = service.scoring_uri
        s_url = service.swagger_uri
        #created_time = service.created_time
        #updated_time = service.updated_time
        v1 = "@"
        v2 = "Deployed Successfully"
        print(v2)
        return '{} {} {} {} {} {} {} {} {}'.format(v2, v1, compute_type, v1,
                                                   state, v1, url, v1, s_url)

    except Exception as e:
        error_statement = str(e)
        print("Error statement: ", error_statement)
        return error_statement
コード例 #19
0
def DeployAzureACI():
    subscription_id = request.json['subscription_id']
    resource_group = request.json['resource_group']
    workspace_name = request.json['workspace_name']
    location = request.json['location']
    best_model = request.json['best_model']
    Model_path = request.json['Model_path']
    #cluster_name = request.json['cluster_name']
    service_name = request.json['service_name']
    Reg_model_name = request.json['Reg_model_name']

    ws = Workspace(subscription_id=subscription_id,
                   resource_group=resource_group,
                   workspace_name=workspace_name)

    print("Found workspace {} at location {}".format(ws.name, ws.location))
    print('Found existing Workspace.')

    from azureml.core.model import Model
    model = Model(ws, name=Reg_model_name)
    print(model)

    from azureml.core.model import InferenceConfig
    from azureml.core.webservice import AciWebservice
    from azureml.core.webservice import Webservice
    from azureml.core.model import Model
    from azureml.core.environment import Environment

    cwd = 'D:\\DCSAIAUTOML\\BestModels\\Azure'
    model_path = os.path.join(cwd, Model_path, best_model, "outputs")
    #model_path1 = os.path.join(model_path, "outputs", "model.pkl")
    print(model_path)
    os.chdir(model_path)
    #import importlib
    script_file_name = 'scoring_file_v_1_0_0.py'
    conda_env_file_name = 'conda_env_v_1_0_0.yml'
    #importlib.import_module('scoring_file_v_1_0_0.py')
    #script_file_name = joblib.load('scoring_file_v_1_0_0.py')
    #import yaml
    #conda_env_file_name = yaml.load(open('conda_env_v_1_0_0.yml'))
    #conda_env_file_name = joblib.load('conda_env_v_1_0_0.yml')

    myenv = Environment.from_conda_specification(name="myenv",
                                                 file_path=conda_env_file_name)
    inference_config = InferenceConfig(entry_script=script_file_name,
                                       environment=myenv)

    try:
        deployment_config = AciWebservice.deploy_configuration(cpu_cores=2,
                                                               memory_gb=8)
        service = Model.deploy(ws, service_name, [model], inference_config,
                               deployment_config)
        service.wait_for_deployment(show_output=True)
        print(service.state)
        compute_type = service.compute_type
        state = service.state
        url = service.scoring_uri
        s_url = service.swagger_uri
        #created_time = service.created_time
        #updated_time = service.updated_time
        v1 = "@"
        v2 = "Deployed Successfully"
        print(v2)
        return '{} {} {} {} {} {} {} {} {}'.format(v2, v1, compute_type, v1,
                                                   state, v1, url, v1, s_url)

    except Exception as e:
        error_statement = str(e)
        print("Error statement: ", error_statement)
        return error_statement
コード例 #20
0
)
args = parser.parse_args()
sources_directory_train = e.sources_directory_train

# model_names = ["nyc_energy_model", "diabetes_model"]
model_names = get_model_names(os.path.join(sources_directory_train,
                                           "pipeline_config.json"))
print("models:")
print(model_names)
models = []
for model_name in model_names:
    models.append(Model(ws, name=model_name))

# Conda environment
myenv = Environment.from_conda_specification(
    "myenv",
    os.path.join(sources_directory_train, "conda_dependencies.yml"))
# Enable Docker based environment
myenv.docker.enabled = True

inference_config = InferenceConfig(
    source_directory=sources_directory_train,
    entry_script="scoring/score.py",
    environment=myenv)

package = Model.package(ws, models, inference_config)
package.wait_for_creation(show_output=True)
# Display the package location/ACR path
# print(package.location)
# location = get_location(package)
location = package.location
コード例 #21
0
args = parser.parse_args()

model = Model(ws, name=e.model_name, version=e.model_version)
sources_dir = e.sources_directory_train
if (sources_dir is None):
    sources_dir = 'londonboiler'
score_script = os.path.join(".", sources_dir, e.score_script)
score_file = os.path.basename(score_script)
path_to_scoring = os.path.dirname(score_script)
cwd = os.getcwd()
# Copy conda_dependencies.yml into scoring as this method does not accept relative paths. # NOQA: E501
shutil.copy(os.path.join(".", sources_dir, "conda_dependencies.yml"),
            path_to_scoring)
os.chdir(path_to_scoring)

scoring_env = Environment.from_conda_specification(
    name="scoringenv", file_path="conda_dependencies.yml")  # NOQA: E501
inference_config = InferenceConfig(entry_script=score_file,
                                   environment=scoring_env)
package = Model.package(ws, [model], inference_config)
package.wait_for_creation(show_output=True)
# Display the package location/ACR path
print(package.location)

os.chdir(cwd)

if package.state != "Succeeded":
    raise Exception("Image creation status: {package.creation_state}")

print("Package stored at {} with build log {}".format(
    package.location, package.package_build_log_uri))  # NOQA: E501
コード例 #22
0
# This code saves training environment
# Environment file 'environment.yml' is uploaded to GitHub for future trainings
#
from azureml.core.environment import Environment
from azureml.automl.core.shared import constants
best_run.download_file(constants.CONDA_ENV_FILE_PATH, 'environment.yml')
environment = Environment.from_conda_specification(name="environment",
                                                   file_path="environment.yml")