def main(args):

    # Define workspace object
    try:
        ws = Workspace.from_config(path='deploy/.azureml/config.json')
    # Need to create the workspace
    except Exception as err:
        print('No workspace.  Check for deploy/.azureml/config.json file.')
        assert False

    inference_config = InferenceConfig(runtime="python",
                                       entry_script="score.py",
                                       conda_file="keras_env.yml",
                                       source_directory="./deploy")

    deployment_config = LocalWebservice.deploy_configuration()

    model = Model(ws, name=args.model_workspace)

    # This deploys AND registers model (if not registered)
    service = Model.deploy(workspace=ws,
                           name=args.service_name,
                           models=[model],
                           inference_config=inference_config,
                           deployment_config=deployment_config)

    service.wait_for_deployment(True)
    print(service.state)
示例#2
0
def deploy_locally(workspace, service_name, models, inference_config, port=8890):
    deployment_config = LocalWebservice.deploy_configuration(port=port)
    service = Model.deploy(workspace=workspace, name=service_name, models=models, inference_config=inference_config,
                           deployment_config=deployment_config)
    service.wait_for_deployment(show_output=True)
    print(service.state)
    return service
def depoly_to_local_web(inference_env_name,port_num:int,model_name,model_version,deployment_name):
    try:
        inference_config=_create_inference_config(inference_env_name)
    except Exception as e:
        raise e
    try:
        deployment_config=LocalWebservice.deploy_configuration(port_num)
        _start_deploy_model(inference_config,deployment_config,model_name,model_version,deployment_name)
    except Exception as e:
        print("failed to deploy")
        raise e
def deploy(local, aks, aci, num_cores, mem_gb, compute_name):
    # Get the workspace
    ws = Workspace.from_config()
    # Create inference configuration based on the environment definition and the entry script
    # yolo = Environment.from_conda_specification(name="env", file_path="yolo.yml")
    yolo = Environment.from_pip_requirements(
        name="yolo", file_path="./deployed_requirements.txt")
    # yolo.save_to_directory('')
    yolo.register(workspace=ws)
    inference_config = InferenceConfig(entry_script="azure.py",
                                       environment=yolo,
                                       source_directory="yolov5")
    # Retrieve registered model
    model = Model(ws, id="lpr:1")
    deploy_target = None
    if local:
        # Create a local deployment, using port 8890 for the web service endpoint
        deployment_config = LocalWebservice.deploy_configuration(port=8890)
    elif aks:
        # Create a AKS deployment
        deployment_config = AksWebservice.deploy_configuration(
            cpu_cores=num_cores,
            memory_gb=mem_gb,
            compute_target_name=compute_name)
        deploy_target = ComputeTarget(workspace=ws, name=compute_name)
        # if deploy_target.get_status() != "Succeeded":
        #     print(f"Deploy Target: {deploy_target.get_status()}")
        #     deploy_target.wait_for_completion(show_output=True)
    elif aks:
        # Create a AKS deployment
        deployment_config = AciWebservice.deploy_configuration(
            cpu_cores=num_cores,
            memory_gb=mem_gb,
            compute_target_name=compute_name)
    else:
        raise NotImplementedError("Choose deploy target please")
    # Deploy the service
    print("Deploying:")
    service = Model.deploy(workspace=ws,
                           name="lpr",
                           models=[model],
                           inference_config=inference_config,
                           deployment_config=deployment_config,
                           overwrite=True,
                           deployment_target=deploy_target)
    # Wait for the deployment to complete
    print("Deploying:")
    service.wait_for_deployment(True)
    # Display the port that the web service is available on
    if local:
        print(service.port)
示例#5
0
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
示例#6
0
    def deploy_local(self):

        try:
            LocalWebservice(self.ws, "test").delete()
            print("webservice deleted")
        except WebserviceException:
            pass

        shoes_designer_env = Environment('shoes_designer_env')
        shoes_designer_env.python.conda_dependencies.add_pip_package("joblib")
        shoes_designer_env.python.conda_dependencies.add_pip_package("torch")
        shoes_designer_env.python.conda_dependencies.add_pip_package("torchvision")
        shoes_designer_env.python.conda_dependencies.add_pip_package("azure-storage-blob")
        shoes_designer_env.python.conda_dependencies.add_pip_package("azureml-sdk")
        shoes_designer_env.python.conda_dependencies.add_pip_package("PyYAML")
        shoes_designer_env.python.conda_dependencies.add_pip_package("scikit-learn")
        shoes_designer_env.python.conda_dependencies.add_pip_package("matplotlib")
        conda_dep.add_pip_package("opencensus-ext-azure")

        # explicitly set base_image to None when setting base_dockerfile
        shoes_designer_env.docker.base_image = None
        shoes_designer_env.docker.base_dockerfile = "FROM mcr.microsoft.com/azureml/base:intelmpi2018.3-ubuntu16.04\nRUN echo \"this is test\""
        shoes_designer_env.inferencing_stack_version = "latest"

        inference_config = InferenceConfig(entry_script="score.py",environment=shoes_designer_env)
        
        model = self.ws.models[self.MODEL_NAME]

        # This is optional, if not provided Docker will choose a random unused port.
        deployment_config = LocalWebservice.deploy_configuration(port=6789)

        local_service = Model.deploy(self.ws, "test", [model], inference_config, deployment_config)

        local_service.wait_for_deployment()
        print("success deployement")
        
        return local_service
示例#7
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)
示例#8
0
#Copy the already created scoring_file_v_1_0_0.py file from the automl run into the scope.py
script_file_name = 'inference/scope.py'
best_run.download_file('outputs/scoring_file_v_1_0_0.py', 'inference/scope.py')

#Set up the inference_config
#The environment is set from the best_run of the automl run
inference_config = InferenceConfig(entry_script=script_file_name,
                                   environment=best_run.get_environment())

#Local Deployment
from azureml.core.webservice import LocalWebservice
local_config = LocalWebservice.deploy_configuration(port=9000)
local_service = Model.deploy(ws, "test", [auto_ml], inference_config,
                             local_config)
local_service.wait_for_deployment(show_output=True)

#Set up the deployment_config as webservice
aci_config = AciWebservice.deploy_configuration(cpu_cores=1,
                                                memory_gb=1,
                                                enable_app_insights=True)

#Deploy the model
service = Model.deploy(workspace=ws,
                       name="mywebservice",
                       models=[auto_ml],
                       inference_config=inference_config,
                       deployment_config=aci_config,
                       overwrite=True)

#wait until deployment is complete
service.wait_for_deployment(show_output=True)
示例#9
0
def submit_update_call(service, models, inference_config, deploy_config, aks_endpoint_version_config):
    if service._webservice_type.lower() == ACI_WEBSERVICE_TYPE.lower():
        # aci update
        service.update(auth_enabled=deploy_config.auth_enabled,
                       ssl_enabled=deploy_config.ssl_enabled,
                       ssl_cert_pem_file=deploy_config.ssl_cert_pem_file,
                       ssl_key_pem_file=deploy_config.ssl_key_pem_file,
                       ssl_cname=deploy_config.ssl_cname,
                       enable_app_insights=deploy_config.enable_app_insights,
                       models=models,
                       inference_config=inference_config)
    elif service._webservice_type.lower() == AKS_WEBSERVICE_TYPE.lower():
        # aks update
        service.update(autoscale_enabled=deploy_config.autoscale_enabled,
                       autoscale_min_replicas=deploy_config.autoscale_min_replicas,
                       autoscale_max_replicas=deploy_config.autoscale_max_replicas,
                       autoscale_refresh_seconds=deploy_config.autoscale_refresh_seconds,
                       autoscale_target_utilization=deploy_config.autoscale_target_utilization,
                       collect_model_data=deploy_config.collect_model_data,
                       auth_enabled=deploy_config.auth_enabled,
                       cpu_cores=deploy_config.cpu_cores,
                       memory_gb=deploy_config.memory_gb,
                       enable_app_insights=deploy_config.enable_app_insights,
                       scoring_timeout_ms=deploy_config.scoring_timeout_ms,
                       replica_max_concurrent_requests=deploy_config.replica_max_concurrent_requests,
                       max_request_wait_time=deploy_config.max_request_wait_time,
                       num_replicas=deploy_config.num_replicas,
                       token_auth_enabled=deploy_config.token_auth_enabled,
                       models=models, inference_config=inference_config,
                       cpu_cores_limit=deploy_config.cpu_cores_limit,
                       memory_gb_limit=deploy_config.memory_gb_limit)
    elif service._webservice_type.lower() == AKS_ENDPOINT_TYPE.lower():
        # aksendpoint update
        if aks_endpoint_version_config and aks_endpoint_version_config['version_operation_type'] is not None:
            version_operation_type = aks_endpoint_version_config['version_operation_type'].lower()
            is_default = aks_endpoint_version_config['is_default']
            is_control_version_type = aks_endpoint_version_config['is_control_version']

            if version_operation_type == AKS_ENDPOINT_CREATE_VERSION.lower():
                service.create_version(
                    version_name=deploy_config.version_name,
                    autoscale_enabled=deploy_config.autoscale_enabled,
                    autoscale_min_replicas=deploy_config.autoscale_min_replicas,
                    autoscale_max_replicas=deploy_config.autoscale_max_replicas,
                    autoscale_refresh_seconds=deploy_config.autoscale_refresh_seconds,
                    autoscale_target_utilization=deploy_config.autoscale_target_utilization,
                    collect_model_data=deploy_config.collect_model_data,
                    cpu_cores=deploy_config.cpu_cores,
                    memory_gb=deploy_config.memory_gb,
                    scoring_timeout_ms=deploy_config.scoring_timeout_ms,
                    replica_max_concurrent_requests=deploy_config.replica_max_concurrent_requests,
                    max_request_wait_time=deploy_config.max_request_wait_time,
                    num_replicas=deploy_config.num_replicas,
                    models=models, inference_config=inference_config,
                    gpu_cores=deploy_config.gpu_cores,
                    period_seconds=deploy_config.period_seconds,
                    initial_delay_seconds=deploy_config.initial_delay_seconds,
                    timeout_seconds=deploy_config.timeout_seconds,
                    success_threshold=deploy_config.success_threshold,
                    failure_threshold=deploy_config.failure_threshold,
                    traffic_percentile=deploy_config.traffic_percentile, is_default=is_default,
                    is_control_version_type=is_control_version_type,
                    cpu_cores_limit=deploy_config.cpu_cores_limit,
                    memory_gb_limit=deploy_config.memory_gb_limit)
            elif version_operation_type == AKS_ENDPOINT_DELETE_VERSION.lower():
                service.delete_version(version_name=deploy_config.version_name)
            elif version_operation_type == AKS_ENDPOINT_UPDATE_VERSION.lower():
                service.update_version(
                    version_name=deploy_config.version_name,
                    autoscale_enabled=deploy_config.autoscale_enabled,
                    autoscale_min_replicas=deploy_config.autoscale_min_replicas,
                    autoscale_max_replicas=deploy_config.autoscale_max_replicas,
                    autoscale_refresh_seconds=deploy_config.autoscale_refresh_seconds,
                    autoscale_target_utilization=deploy_config.autoscale_target_utilization,
                    collect_model_data=deploy_config.collect_model_data,
                    cpu_cores=deploy_config.cpu_cores,
                    memory_gb=deploy_config.memory_gb,
                    scoring_timeout_ms=deploy_config.scoring_timeout_ms,
                    replica_max_concurrent_requests=deploy_config.replica_max_concurrent_requests,
                    max_request_wait_time=deploy_config.max_request_wait_time,
                    num_replicas=deploy_config.num_replicas,
                    models=models, inference_config=inference_config,
                    gpu_cores=deploy_config.gpu_cores,
                    period_seconds=deploy_config.period_seconds,
                    initial_delay_seconds=deploy_config.initial_delay_seconds,
                    timeout_seconds=deploy_config.timeout_seconds,
                    success_threshold=deploy_config.success_threshold,
                    failure_threshold=deploy_config.failure_threshold,
                    traffic_percentile=deploy_config.traffic_percentile, is_default=is_default,
                    is_control_version_type=is_control_version_type,
                    cpu_cores_limit=deploy_config.cpu_cores_limit,
                    memory_gb_limit=deploy_config.memory_gb_limit)
        else:
            service.update(auth_enabled=deploy_config.auth_enabled,
                           token_auth_enabled=deploy_config.token_auth_enabled,
                           enable_app_insights=deploy_config.enable_app_insights)
    elif service._webservice_type.lower() == 'local':
        # local update
        deployment_config = \
            LocalWebservice.deploy_configuration(port=deploy_config.port if deploy_config else None)

        service.update(models=models,
                       deployment_config=deployment_config,
                       inference_config=inference_config)
    else:
        raise WebserviceException("Unknown deployment type: {}".format(service._webservice_type))
示例#10
0
from azureml.core.model import InferenceConfig
from azureml.core.webservice import LocalWebservice
from azureml.core.model import Model
from azureml.core import Workspace

classifier_inference_config = InferenceConfig(runtime="python",
                                              source_directory='deploy',
                                              entry_script="eval_emotion.py",
                                              conda_file="deploy-env.yml")

classifier_deploy_config = LocalWebservice.deploy_configuration(port=8080)

ws = Workspace.from_config()
model = ws.models['sentiment_model']
service = Model.deploy(workspace=ws,
                       name='classifier-service',
                       models=[model],
                       inference_config=classifier_inference_config,
                       deployment_config=classifier_deploy_config,
                       deployment_target=None)
service.wait_for_deployment(show_output=True)

endpoint = service.scoring_uri
print(endpoint)
示例#11
0
                             auth=svc_pr,
                             exist_ok=True)

# Get the model registered in your Azure ML Workspace
model = Model.list(workspace, conf.MODEL_NAME)[0]

# Create the environment to manage the dependencies
env = Environment(name="env-local-deploy")

# Here we will use a .yml file to control the dependencies
conda_dep = CondaDependencies(conda_dependencies_file_path='conda_env.yml')

# Adds dependencies to PythonSection of myenv
env.python.conda_dependencies = conda_dep

# Our inference config with the score.py file
inference_config = InferenceConfig(entry_script="score.py", environment=env)

# Create a local deployment, using port 8890 for the web service endpoint
deployment_config = LocalWebservice.deploy_configuration(port=conf.PORT)

# Deploy the service
service = Model.deploy(workspace, conf.ENDPOINT_NAME, [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)
示例#12
0
try:
    Webservice(ws, service_name).delete()
except WebserviceException:
    pass
from azureml.core import Environment
from azureml.core.conda_dependencies import CondaDependencies

myenv = Environment.get(workspace=ws, name="myenv")
from azureml.core.model import InferenceConfig

with open('src/score.py') as f:
    print(f.read())

inference_config = InferenceConfig(entry_script='src/score.py',
                                   environment=myenv)
aci_deployment_config = AciWebservice.deploy_configuration(cpu_cores=1,
                                                           memory_gb=1)
from azureml.core.webservice import LocalWebservice

local_deployment_config = LocalWebservice.deploy_configuration(port=6789)

service = Model.deploy(workspace=ws,
                       name=service_name,
                       models=[model],
                       inference_config=inference_config,
                       deployment_config=aci_deployment_config,
                       overwrite=True)
service.wait_for_deployment(show_output=True)
print(service.get_logs())