def get_aks(workspace: Workspace, compute_name: str):
    # Verify that cluster does not exist already
    try:
        aks_target = workspace.compute_targets.get(compute_name)
        if aks_target is not None and type(aks_target) is AksCompute:
            print('Found existing compute target ' + compute_name +
                  ' so using it.')  # noqa: E127
        else:
            prov_config = AksCompute.provisioning_configuration(
                cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST)
            aks_name = compute_name

            print("No Azure Kubernetes Service cluster found, "
                  "creating one now...")

            # Create the cluster
            aks_target = ComputeTarget.create(
                workspace=workspace,
                name=aks_name,
                provisioning_configuration=prov_config)

            # Wait for the create process to complete
            aks_target.wait_for_completion(show_output=True)
        return aks_target
    except ComputeTargetException as e:
        print(e)
        print('An error occurred trying to provision compute.')
        raise
def AKSCompute():
    subscription_id = request.json['subscription_id']
    resource_group = request.json['resource_group']
    workspace_name = request.json['workspace_name']
    location = request.json['location']
    cluster_name = request.json['cluster_name']
    vm_size = request.json['vm_size']
    agent_count = request.json['agent_count']
    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.')
    #aml_compute = AmlCompute(ws, cluster_name)
    #cluster_name = 'cpu-cluster'
    try:
        aks_target = AksCompute(ws, cluster_name)
        print('Found existing AKS compute context.')
        return "Found existing AKS compute context."
    except:
        print('need to create new Compute.')
        print('Creating new AKS compute context.')
        prov_config = AksCompute.provisioning_configuration(
            vm_size=vm_size, agent_count=agent_count, location=location)
        aks_target = ComputeTarget.create(
            workspace=ws,
            name=cluster_name,
            provisioning_configuration=prov_config)

        # Wait for the create process to complete
        aks_target.wait_for_completion(show_output=True)
        return "Compute successfully created"
Example #3
0
def create_aks_cluster(workspace, parameters):
    print("::debug::Creating aks cluster configuration")
    aks_config = AksCompute.provisioning_configuration(
        agent_count=parameters.get("agent_count", None),
        vm_size=parameters.get("vm_size", "Standard_D3_v2"),
        location=parameters.get("location", None),
        service_cidr=parameters.get("service_cidr", None),
        dns_service_ip=parameters.get("dns_service_ip", None),
        docker_bridge_cidr=parameters.get("docker_bridge_cidr", None))

    print(
        "::debug::Changing cluster purpose if specified settings were provided"
    )
    if "dev" in parameters.get("cluster_purpose",
                               "").lower() or "test" in parameters.get(
                                   "cluster_purpose", "").lower():
        aks_config.cluster_purpose = AksCompute.ClusterPurpose.DEV_TEST

    print(
        "::debug::Adding VNET settings to configuration if all required settings were provided"
    )
    if parameters.get(
            "vnet_resource_group_name", None) is not None and parameters.get(
                "vnet_name", None) is not None and parameters.get(
                    "subnet_name", None) is not None:
        aks_config.vnet_resourcegroup_name = parameters.get(
            "vnet_resource_group_name", None)
        aks_config.vnet_name = parameters.get("vnet_name", None)
        aks_config.subnet_name = parameters.get("subnet_name", None)

    print(
        "::debug::Adding SSL settings to configuration if all required settings were provided"
    )
    if parameters.get("ssl_cname", None) is not None and parameters.get(
            "ssl_cert_pem_file", None) is not None and parameters.get(
                "ssl_key_pem_file", None) is not None:
        aks_config.ssl_cname = parameters.get("ssl_cname", None)
        aks_config.ssl_cert_pem_file = parameters.get("ssl_cert_pem_file",
                                                      None)
        aks_config.ssl_key_pem_file = parameters.get("ssl_key_pem_file", None)

    print(
        "::debug::Adding load balancer settings to configuration if all required settings were provided"
    )
    if parameters.get("load_balancer_type",
                      None) == "InternalLoadBalancer" and parameters.get(
                          "load_balancer_subnet", None) is not None:
        aks_config.load_balancer_type = parameters.get("load_balancer_type",
                                                       None)
        aks_config.load_balancer_subnet = parameters.get(
            "load_balancer_subnet", None)

    print("::debug::Creating compute target")
    # Default compute target name
    repository_name = str(os.environ.get("GITHUB_REPOSITORY")).split("/")[-1]
    aks_cluster = create_compute_target(workspace=workspace,
                                        name=parameters.get(
                                            "name", repository_name),
                                        config=aks_config)
    return aks_cluster
Example #4
0
def create_aks(workspace, aks_cluster_name):
    from azureml.core.compute import AksCompute, ComputeTarget
    # Create an AKS cluster
    print("Creating AKS cluster...")
    # Use the default configuration (you can also provide parameters to customize this)
    prov_config = AksCompute.provisioning_configuration()
    # Create the cluster
    aks_target = ComputeTarget.create(workspace=workspace,
                                      name=aks_cluster_name,
                                      provisioning_configuration=prov_config)
    # Wait for the create process to complete
    aks_target.wait_for_completion(show_output=True)
    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)
    print("AKS cluster creation completed")
    return aks_target
Example #5
0
def create_cluster():
    ws = get_workspace()
    # Use the default configuration (can also provide parameters to customize)
    prov_config = AksCompute.provisioning_configuration()
    aks_name = AKS_CLUSTER_NAME

    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)

    aks_target.wait_for_completion(show_output=True)

    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)

    return aks_target
Example #6
0
def createComputeCluster(workspace, region, compute_name, compute_sku,
                         node_count, dev_cluster):
    '''
        Create new AKS cluster, unless there is an existing AMLS compute with the same 
        name already attached to the AMLS workspace. 

        PARAMS: 
            workspace        : azureml.core.Workspace   : Existing AMLS Workspace
            region           : String                   : Azure region
            compute_name     : String                   : Name of the AMLS compute to create/locate.
            compute_sku      : String                   : Azure ML VM Sku
            node_count       : int                      : Number of VM's to add to the cluster
            dev_cluster      : bool                     : Flag indicating if this is a development cluster. A development
                                                          cluster generally has fewwer vCPU's based on node count than allowed
                                                          for a production deployment. 

        RETURNS: 
            azureml.core.compute.AksCompute

    '''
    purpose = _getClusterPurpose(dev_cluster)
    aks_target = _getExistingCompute(workspace, compute_name)

    if aks_target == None:
        print("Creating new AKS compute.....")
        prov_config = AksCompute.provisioning_configuration(
            agent_count=node_count,
            vm_size=compute_sku,
            location=region,
            cluster_purpose=purpose)

        aks_target = ComputeTarget.create(
            workspace=workspace,
            name=compute_name,
            provisioning_configuration=prov_config)

        aks_target.wait_for_completion(show_output=True)

        aks_status = aks_target.get_status()
        assert aks_status == 'Succeeded'

    return aks_target
    def __create_or_get_compute(self):
        compute_config = self.__config['compute']
        compute_list = AksCompute.list(self.__ws)
        compute = compute_list.find_by_property('name', compute_config['name'])
        if compute:
            return compute
        prov_config = AksCompute.provisioning_configuration(
            agent_count=compute_config['agent_count'],
            vm_size=compute_config['vm_size'],
            location=compute_config['location'])
        aks_name = compute_config['name']
        aks_target = ComputeTarget.create(
            workspace=self.__ws,
            name=aks_name,
            provisioning_configuration=prov_config)

        aks_target.wait_for_completion(show_output=True)
        print(aks_target.provisioning_state)
        print(aks_target.provisioning_errors)
        return aks_target
Example #8
0
# create aml compute targets
for ct_name in amlcomputes:
    if ct_name not in ws.compute_targets:
        print(f"Creating AML compute {ct_name}")
        compute_config = AmlCompute.provisioning_configuration(
            **amlcomputes[ct_name])
        ct = ComputeTarget.create(ws, ct_name, compute_config)
        ct.wait_for_completion(show_output=True)

# create aks compute targets
if args.create_aks:
    for ct_name in akscomputes:
        if ct_name not in ws.compute_targets:
            print(f"Creating AKS compute {ct_name}")
            compute_config = AksCompute.provisioning_configuration(
                **akscomputes[ct_name])
            ct = ComputeTarget.create(ws, ct_name, compute_config)
            ct.wait_for_completion(show_output=True)

if args.datalake_name not in ws.datastores:
    print(f"Creating datastore {args.datalake_name}")
    adlsgen2_datastore = Datastore.register_azure_data_lake_gen2(
        workspace=ws,
        datastore_name=args.datalake_name,
        account_name=args.datalake_name,
        subscription_id=ws.subscription_id,
        resource_group=args.datalake_rg_name,
        filesystem="datalake",
        grant_workspace_access=True,
    )
# Provision the AKS Cluster
print("Provisioning an AKS cluster...")
from azureml.core.compute import AksCompute, ComputeTarget
from azureml.core.compute_target import ComputeTargetException

aks_name = 'myaks'

try:
    aks_target = AksCompute(workspace=ws, name=aks_name)
    print('found existing Azure Kubernetes Service:', aks_target.name)
except ComputeTargetException:
    print('creating new Azure Kubernetes Service.')

    # AKS configuration
    prov_config = AksCompute.provisioning_configuration(
        #agent_count=2,
        #vm_size="Standard_D3_v2"
    )

    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)

print("Creating docker image configuration...")
from azureml.core.conda_dependencies import CondaDependencies

myenv = CondaDependencies()
myenv.add_conda_package("scikit-learn")

with open(os.path.join(project_folder, "myenv.yml"), "w") as f:
    f.write(myenv.serialize_to_string())
Example #10
0
      'Subscription id: ' + ws.subscription_id,
      'Resource group: ' + ws.resource_group,
      'Workspace connected',
      sep='\n')

# Choose a name for your cluster
aks_name = "SIB2-AKS-GPU"

# Check to see if the cluster already exists and create it if non existant
try:
    aks_target = ComputeTarget(workspace=ws, name=aks_name)
    print('Found existing compute target')
except ComputeTargetException:
    print('Creating a new compute target...')
    # Provision AKS cluster with GPU machine
    prov_config = AksCompute.provisioning_configuration(vm_size="Standard_NC6")

    # Create the cluster
    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
Example #11
0
# Provision the AKS Cluster
print("Provisioning an AKS cluster...")
from azureml.core.compute import AksCompute, ComputeTarget
from azureml.core.compute_target import ComputeTargetException

aks_name = 'myaks'

try:
    aks_target = AksCompute(workspace=ws, name=aks_name)
    print('found existing Azure Kubernetes Service:', aks_target.name)
except ComputeTargetException:
    print('creating new Azure Kubernetes Service.')

    # AKS configuration
    prov_config = AksCompute.provisioning_configuration(
        agent_count=3, vm_size="Standard_B4ms")

    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)

print("Creating docker image configuration...")
from azureml.core.conda_dependencies import CondaDependencies

myenv = CondaDependencies()
myenv.add_conda_package("scikit-learn")

with open(os.path.join(project_folder, "myenv.yml"), "w") as f:
    f.write(myenv.serialize_to_string())
Example #12
0
from azureml.core.model import InferenceConfig

class_inference_config = InferenceConfig(runtime='python',
                                         source_directory='service_files',
                                         entry_script='score.py',
                                         conda_file='env.yml')

# now inference config is ready now So now we need to configure the compute to which the service will be deployed
#if we are going for AKS cluster then we need to create the cluster and a compute target before deployment

#creating the AKS cluster(Azure kubernetes service)

from azureml.core.compute import ComputeTarget, AksCompute

cluster_name = 'aks-cluster'
compute_config = AksCompute.provisioning_configuration(location="eastus")
production_cluster = ComputeTarget.create(ws, cluster_name, compute_config)
production_cluster.wait_for_completion(show_output=True)

from azureml.core.webservice import AksWebservice

classifier_deploy_config = AksWebservice.deploy_configuration(cpu_core=1,
                                                              memory_gb=1)

#finally deploting the model

from azureml.core.model import Model

model = ws.models['classification_model']
service = Model.deploy(workspace=ws,
                       name='classifier-service',
Example #13
0
print("model name: ", model_name)
#########################################################################################################
# Choose a name for your GPU cluster
gpu_cluster_name = "aks-gpu-cluster"

# Verify that cluster does not exist already
try:
    aks_gpu_cluster = ComputeTarget(workspace=ws, name=gpu_cluster_name)
    print("Found existing gpu cluster")
except ComputeTargetException:
    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)
Example #14
0
    print("Loading existing Test AKS Cluster")
    aks_test_cluster = AksCompute(workspace=ws,
                                  name=aks_compute_settings["name"])

    # Check settings and redeploy if required settings have changed
    print("Found existing cluster")
    #aks_test_cluster.update()
    #print("Successfully updated Cluster definition")
except ComputeTargetException:
    print("Loading failed ... Creating new Dev AKS Cluster")
    compute_config = AksCompute.provisioning_configuration(
        agent_count=aks_compute_settings["agent_count"],
        vm_size=aks_compute_settings["vm_size"],
        ssl_cname=aks_compute_settings["ssl_cname"],
        ssl_cert_pem_file=aks_compute_settings["ssl_cert_pem_file"],
        ssl_key_pem_file=aks_compute_settings["ssl_key_pem_file"],
        location=aks_compute_settings["location"],
        service_cidr=aks_compute_settings["service_cidr"],
        dns_service_ip=aks_compute_settings["dns_service_ip"],
        docker_bridge_cidr=aks_compute_settings["docker_bridge_cidr"],
        cluster_purpose=AksCompute.ClusterPurpose.DEV_TEST)
    # Deploy to VNET if provided
    if aks_compute_settings["vnet_resourcegroup_name"] and aks_compute_settings[
            "vnet_name"] and aks_compute_settings["subnet_name"]:
        compute_config.vnet_resourcegroup_name = aks_compute_settings[
            "vnet_resourcegroup_name"]
        compute_config.vnet_name = aks_compute_settings["vnet_name"]
        compute_config.subnet_name = aks_compute_settings["subnet_name"]

    # Create Compute Target
    aks_test_cluster = ComputeTarget.create(
Example #15
0
from azureml.core import Model, Workspace, Environment
from azureml.core.model import InferenceConfig
from azureml.core.compute import ComputeTarget, AksCompute
from azureml.core.webservice import AksWebservice

cluster_name = 'aks-cluster'

classifier_deploy_config = AksWebservice.deploy_configuration(cpu_cores=1,
                                                              memory_gb=0.5)
workspace = Workspace.from_config(_file_name='config.json')
model = Model(workspace, 'lightGBM')
#cluster AKS
compute_config = AksCompute.provisioning_configuration(location='northeurope')
production_cluster = ComputeTarget.create(workspace, cluster_name,
                                          compute_config)
production_cluster.wait_for_completion(show_output=True)

env = Environment.from_conda_specification(name="EnergyPrediction",
                                           file_path="env.yml")
inference_config = InferenceConfig(entry_script="score.py", environement=env)

service = Model.deploy(workspace=workspace,
                       name="energy_prediction",
                       models=[model],
                       inference_config=inference_config,
                       deployment_config=classifier_deploy_config)
Example #16
0
    with open("aml_config/aks_webservice.json") as f:
        config = json.load(f)
    aks_name = config["aks_name"]
    aks_service_name = config["aks_service_name"]
    compute_list = ws.compute_targets()
    aks_target, = (c for c in compute_list if c.name == aks_name)
    service = Webservice(name=aks_service_name, workspace=ws)
    print("Updating AKS service {} with image: {}".format(
        aks_service_name, image.image_location))
    service.update(image=image)
except:
    aks_name = "aks" + datetime.datetime.now().strftime("%m%d%H")
    aks_service_name = "akswebservice" + datetime.datetime.now().strftime(
        "%m%d%H")
    prov_config = AksCompute.provisioning_configuration(agent_count=6,
                                                        vm_size="Standard_F2",
                                                        location="eastus")
    print(
        "No AKS found in aks_webservice.json. Creating new Aks: {} and AKS Webservice: {}"
        .format(aks_name, aks_service_name))
    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)

    aks_target.wait_for_completion(show_output=True)
    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)

    # Use the default configuration (can also provide parameters to customize)
    aks_config = AksWebservice.deploy_configuration(enable_app_insights=True)
try:
    service = Webservice(name=aks_service_name, workspace=ws)
    print("Deleting AKS service {}".format(aks_service_name))
    service.delete()
except:
    print("No existing webservice found: ", aks_service_name)

compute_list = ws.compute_targets
aks_target = None
if aks_name in compute_list:
    aks_target = compute_list[aks_name]

if aks_target == None:
    print("No AKS found. Creating new Aks: {} and AKS Webservice: {}".format(
        aks_name, aks_service_name))
    prov_config = AksCompute.provisioning_configuration(location=aks_region)
    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)
    aks_target.wait_for_completion(show_output=True)
    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)

print("Creating new webservice")
# Create the web service configuration (using defaults)
aks_config = AksWebservice.deploy_configuration(description=args.description,
                                                tags={
                                                    'name': aks_name,
                                                    'image_id': image.id
                                                })
with open(os.path.join(source_directory, 'models.json'), 'w') as f:
    json.dump(
        {
            "prednet_model_names": prednet_model_names,
            "clf_model_names": clf_model_names
        }, f)

env = Environment.get(ws, 'prednet')
env.python.conda_dependencies.add_pip_package('azureml-defaults')

inference_config = InferenceConfig(entry_script='score.py',
                                   environment=env,
                                   source_directory=source_directory)

prov_config = AksCompute.provisioning_configuration(cluster_purpose="DevTest")

aks_name = 'videoanom-aks'

try:
    aks_target = AksCompute(ws, aks_name)
except Exception:
    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)
    aks_target.wait_for_completion(show_output=True)

aks_config = AksWebservice.deploy_configuration()

aks_service_name = 'videoanom-service'
Example #19
0
    print("Deleting AKS service {}".format(aks_service_name))
    service.delete()
except:
    print("No existing webservice found: ", aks_service_name)

compute_list = ws.compute_targets
aks_target = None
if aks_name in compute_list:
    aks_target = compute_list[aks_name]

if aks_target == None:
    print("No AKS found. Creating new Aks: {} and AKS Webservice: {}".format(
        aks_name, aks_service_name))
    prov_config = AksCompute.provisioning_configuration(
        location=aks_region,
        agent_count=2,
        cluster_purpose='DevTest',
        vm_size='STANDARD_D2_v3')
    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws,
                                      name=aks_name,
                                      provisioning_configuration=prov_config)
    aks_target.wait_for_completion(show_output=True)
    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)

print("Creating new webservice")

score_path = 'score_fixed.py'
print('Updating scoring file with the correct model name')
with open('aml_service/score.py') as f:
Example #20
0
try:
    service = Webservice(name=aks_service_name, workspace=ws)
    print("Deleting AKS service {}".format(aks_service_name))
    service.delete()
except:
    print("No existing webservice found: ", aks_service_name)

compute_list = ws.compute_targets
aks_target = None
if aks_name in compute_list:
    aks_target = compute_list[aks_name]
    
if aks_target == None:
    print("No AKS found. Creating new Aks: {} and AKS Webservice: {}".format(aks_name, aks_service_name))
    prov_config = AksCompute.provisioning_configuration(location=aks_region, vm_size="STANDARD_DS2_V2")
    # Create the cluster
    aks_target = ComputeTarget.create(workspace=ws, name=aks_name, provisioning_configuration=prov_config)
    aks_target.wait_for_completion(show_output=True)
    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)
    
print("Creating new webservice")
# Create the web service configuration (using defaults)
aks_config = AksWebservice.deploy_configuration(description = args.description, 
                                                tags = {'name': aks_name, 'image_id': image.id})
service = Webservice.deploy_from_image(
    workspace=ws,
    name=aks_service_name,
    image=image,
    deployment_config=aks_config,
Example #21
0
# Check if AKS already Available
try:
    with open("aml_config/aks_webservice.json") as f:
        config = json.load(f)
    aks_name = config['aks_name']
    aks_service_name = config['aks_service_name']
    compute_list = ws.compute_targets()
    aks_target, =(c for c in compute_list if c.name ==aks_name)
    service=Webservice(name =aks_service_name, workspace =ws)
    print('Updating AKS service {} with image: {}'.format(aks_service_name,image.image_location))
    service.update(image=image)
except:
    aks_name = 'aks'+ datetime.datetime.now().strftime('%m%d%H')
    aks_service_name = 'akswebservice'+ datetime.datetime.now().strftime('%m%d%H')
    prov_config = AksCompute.provisioning_configuration(agent_count = 6, vm_size = 'Standard_F2', location='eastus')
    print('No AKS found in aks_webservice.json. Creating new Aks: {} and AKS Webservice: {}'.format(aks_name,aks_service_name))
    # Create the cluster
    aks_target = ComputeTarget.create(workspace = ws, 
                                    name = aks_name, 
                                    provisioning_configuration = prov_config)

    aks_target.wait_for_completion(show_output = True)
    print(aks_target.provisioning_state)
    print(aks_target.provisioning_errors)

    # Use the default configuration (can also provide parameters to customize)
    aks_config = AksWebservice.deploy_configuration(enable_app_insights=True)

    service = Webservice.deploy_from_image(workspace = ws, 
                                            name = aks_service_name,
###########################################
import json
age = 60
km = 40000
test_data = json.dumps([[age, km]])
test_data
result = webservice.run(input_data=test_data)
print(result)

# Step 9 - Provision an AKS cluster
####################################
from azureml.core.compute import AksCompute, ComputeTarget
from azureml.core.webservice import Webservice, AksWebservice

# Use the default configuration, overriding the default location to a known region that supports AKS
prov_config = AksCompute.provisioning_configuration(location='westus2')

aks_name = 'aks-cluster01'

# Create the cluster
aks_target = ComputeTarget.create(workspace=ws,
                                  name=aks_name,
                                  provisioning_configuration=prov_config)

# Wait for cluster to be ready
aks_target.wait_for_completion(show_output=True)
print(aks_target.provisioning_state)
print(aks_target.provisioning_errors)

# Step 10 - Deploy webservice to AKS
####################################
Example #23
0
    model, = (m for m in model_list
              if m.version == model_version and m.name == model_name)
    print(
        'Model picked: {} \nModel Description: {} \nModel Version: {}'.format(
            model.name, model.description, model.version))

    # Set up Compute Target
    try:
        computeTargets = ComputeTarget.list(ws)
        aks_target, = (t for t in computeTargets if t.name == aks_service_name)
        if aks_target is None:
            raise Exception(
                "Compute Target {} not found.  Attempting to create".format(
                    aks_service_name))
    except:
        prov_config = AksCompute.provisioning_configuration(location='eastus')

        # Create the cluster
        aks_target = ComputeTarget.create(
            workspace=ws,
            name=aks_service_name,
            provisioning_configuration=prov_config)
        print("Provisioning an AKS Cluster")
        aks_target.wait_for_completion()

    # Configure this particular web service's resources on your AKS Cluster
    aks_config = AksWebservice.deploy_configuration(
        autoscale_enabled=False,
        auth_enabled=True,
        cpu_cores=0.5,
        memory_gb=1,
Example #24
0
# MAGIC
# MAGIC To deploy an image, we need to create a new or connect to an existing Azure Kubernetes Service compute target.

# COMMAND ----------

# MAGIC %md
# MAGIC ### Create a New AKS Cluster
# MAGIC
# MAGIC *Note: It will take a few minutes to create a new AKS cluster*

# COMMAND ----------

from azureml.core.compute import AksCompute, ComputeTarget

# Use the default configuration (you can also provide parameters to customize this)
prov_config = AksCompute.provisioning_configuration()

aks_cluster_name = "<aks_name>"

# Create the cluster
aks_target = ComputeTarget.create(workspace=workspace,
                                  name=aks_cluster_name,
                                  provisioning_configuration=prov_config)

# Wait for the create process to complete
aks_target.wait_for_completion(show_output=True)
print(aks_target.provisioning_state)
print(aks_target.provisioning_errors)

# COMMAND ----------
Example #25
0
    data = np.array(json.loads(raw_data)['data'])
    return list(model.predict(data))


from azureml.core.model import InferenceConfig

classifier_inference_config = InferenceConfig(runtine = "python",
                                              source_directory=".",
                                              entry_script = 'entry.py',
                                              conda_file='env.yml')


from azureml.core.compute import AksCompute, ComputeTarget

cluster_name = 'aks_cluster'
compute_config = AksCompute.provisioning_configuration(location = 'centralindia')
production_cluster = ComputeTarget.create(ws, cluster_name, compute_config)
production_cluster.wait_for_deployment(show_output=True)


from azureml.core.webservice import AksWebservice

classifier_deploy_config = AksWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)


#final deployment

from azureml.core.model import Model

model = ws.models['classi_model']