def get_workspace(self, workspace_name):
     """
     Authenticates and returns the AzureML workspace handle
     
     :param workspace_name: The workspace's name
     :return The workspace handle. None on failure
     """
     if not self.valid_config:
         print("Please configure your Service Principal before trying to access the workspace")
         print("\nVisit this URL for further details about setting up a Service Principal in your own subscription:")
         print("https://docs.microsoft.com/en-us/azure/machine-learning/how-to-setup-authentication")
         return None
     # Authenticate via principal's credentials
     config_data = self.config_data
     svc_pr = ServicePrincipalAuthentication(
        tenant_id=config_data['tenantId'],
        service_principal_id=config_data['clientId'],
        service_principal_password=config_data['clientSecret'])        
     workspaces = [key for key in Workspace.list(config_data['subscriptionId'], auth=svc_pr).keys()]
     if workspace_name not in workspaces:
         print(f"Workspace {workspace_name} not found in workspace list. Please create the workspace or adjust the scripts accordingly.")
         print("\nFollowing workspaces could be found:")
         for workspace in workspaces:
             print(f"- {workspace}")
         return None
     if self.workspace==None:
         self.workspace = Workspace.get(name=workspace_name, auth=svc_pr, resource_group=config_data['resourceGroup'], subscription_id=config_data['subscriptionId'])        
     return self.workspace
示例#2
0
acr_details.address = os.environ.get('ACR_ADDRESS')
acr_details.username = os.environ.get('ACR_USERNAME')
acr_details.password = os.environ.get('ACR_PASSWORD')
acr_image = 'aml-r'

# R Script related information
r_script = 'hello.r'

#   1. Authenticate with Azure ML Service
auth = ServicePrincipalAuthentication(
    tenant_id=azure_tentant_id,
    service_principal_id=azure_app_id,
    service_principal_password=azure_app_secret)

aml_workspace = Workspace.get(name=aml_workspace_name,
                              auth=auth,
                              subscription_id=azure_subscription_id,
                              resource_group=azure_resource_group)

if (aml_workspace):
    print(f'Connected to AML Workspace {aml_workspace._workspace_name}')
else:
    print(f'ERROR: Not connected to AML Workspace {aml_workspace_name}')
    exit(-1)

bootstrap_args = [r_script]

estimator = Estimator(source_directory='src',
                      entry_script='bootstrapper.py',
                      compute_target=aml_compute_target,
                      custom_docker_image=acr_image,
                      image_registry_details=acr_details,
from azureml.core.experiment import Experiment
from azureml.core.authentication import ServicePrincipalAuthentication
from azureml.core.compute import AmlCompute
from azureml.train.automl import AutoMLConfig
import logging, os, time
from sklearn.model_selection import train_test_split
from sklearn.externals import joblib

from app_helper import AppHelper
helper = AppHelper()

## Connect to our Azure Machine Learning Workspace
auth_obj = ServicePrincipalAuthentication(helper.tenant_id, helper.username,
                                          helper.password)
ws = Workspace.get(name=helper.aml_workspace_name,
                   auth=auth_obj,
                   subscription_id=helper.subscription_id,
                   resource_group=helper.aml_resource_group)

## Experiment name and project folder, and max nodes for remote compute
experiment_name = 'azureautoml'
project_folder = 'remote_automl'
nodes = 4

dsvm_name = 'dsvmaml'
try:
    dsvm_compute = AmlCompute(ws, dsvm_name)
    print('found existing dsvm.')
except:
    print('creating new dsvm.')
    # Below is using a VM of SKU Standard_D2_v2 which is 2 core machine. You can check Azure virtual machines documentation for additional SKUs of VMs.
    dsvm_config = AmlCompute.provisioning_configuration(vm_size="Standard_NC6",
示例#4
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    # interactive_auth = InteractiveLoginAuthentication(tenant_id="b88f1ff4-e3ab-4adb-83e6-4ea99d41c665")

    sp = ServicePrincipalAuthentication(tenant_id='b88f1ff4-e3ab-4adb-83e6-4ea99d41c665',
                                    service_principal_id='2e90efa1-d53f-45d4-96d8-7adde8a02cdc',
                                    service_principal_password='******'
    )
    query = req.params.get('query')

    if not query:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            query = req_body.get('query')

    if query == 'run':
        try:
            ws = Workspace.get(name="vrd-ml",
               subscription_id="b9301f45-7da5-41f6-9125-1331de94f262",
               resource_group="vrd-dev-asia",
               auth=sp
               )
            
            compute_name = 'automl-compute'

            if compute_name in ws.compute_targets:
                compute_target = ws.compute_targets[compute_name]
                if compute_target and type(compute_target) is AmlCompute:
                    print('found compute target. just use it. ' + compute_name)
            else:
                print('creating a new compute target...')
                provisioning_config = AmlCompute.provisioning_configuration(vm_size = 'STANDARD_D2_V2',
                                                                            min_nodes = 0, 
                                                                            max_nodes = 4)
                compute_target = ComputeTarget.create(ws, compute_name, provisioning_config)
                compute_target.wait_for_completion(show_output=True, min_node_count=None, timeout_in_minutes=20)

            dataset = Dataset.get_by_name(ws, name='datasetfunc')

            train_data, test_data = dataset.random_split(percentage=0.8, seed=223)
            label = "ERP"

            automl_config = AutoMLConfig(task = 'regression',
                            compute_target = compute_name,
                            training_data = train_data,
                            label_column_name = label,
                            validation_data = test_data,
                            # n_cross_validations= 3,
                            primary_metric= 'r2_score',
                            enable_early_stopping= True, 
                            experiment_timeout_hours= 0.3,
                            max_concurrent_iterations= 4,
                            max_cores_per_iteration= -1,
                            verbosity= logging.INFO
                            )

            experiment_name = 'expfunc'
            experiment = Experiment(workspace = ws, name = experiment_name)

            run = experiment.submit(automl_config, show_output = True)                
            run

            run.wait_for_completion()
        except ValueError:
            pass
        return func.HttpResponse("AutoML Run Completed")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )
from sklearn.linear_model import LogisticRegression
from azureml.core.workspace import Workspace
from azureml.core.model import Model

# %%

# Use Service Principal
from azureml.core.authentication import ServicePrincipalAuthentication

sp = ServicePrincipalAuthentication(
    tenant_id=os.environ['TENANT_ID'],  # tenantID
    service_principal_id=os.environ['CLIENT_ID'],  # clientId
    service_principal_password=os.environ['CLIENT_SECRET'])  # clientSecret

ws = Workspace.get(name=os.environ['WORKSPACE_NAME'],
                   auth=sp,
                   subscription_id=os.environ['SUBSCRIPTION_ID'],
                   resource_group=os.environ['RESOURCE_GROUP'])

# %%


def score(raw_data, model_name):
    # Get predictions and explanations for each data point
    data = pd.read_json(raw_data)

    model_path = Model.get_model_path(model_name, version=None, _workspace=ws)

    model = joblib.load(model_path)

    # Make prediction
    predictions = model.predict(data)
示例#6
0
      "of the Azure ML SDK")

parse = argparse.ArgumentParser()
parse.add_argument("--tenantid")
parse.add_argument("--acclientid")
parse.add_argument("--accsecret")

args = parse.parse_args()

sp = ServicePrincipalAuthentication(
    tenant_id=args.tenantid,  # tenantID
    service_principal_id=args.acclientid,  # clientId
    service_principal_password=args.accsecret)  # clientSecret

ws = Workspace.get(name="mlopsdev",
                   auth=sp,
                   subscription_id="c46a9435-c957-4e6c-a0f4-b9a597984773",
                   resource_group="mlops")

# choose a name for experiment
experiment_name = 'automl-classification-ccard-remote'

experiment = Experiment(ws, experiment_name)

output = {}
output['Subscription ID'] = ws.subscription_id
output['Workspace'] = ws.name
output['Resource Group'] = ws.resource_group
output['Location'] = ws.location
output['Experiment Name'] = experiment.name
pd.set_option('display.max_colwidth', -1)
outputDf = pd.DataFrame(data=output, index=[''])
示例#7
0
def main(args):
    ws = Workspace.get(subscription_id=args.id)
示例#8
0
aci_service_name = 'automl-sample-01' + \
    "_" + str(run_id) + "_" + str(iteration)
image_name = "automlsampleimage"

directory = "./autoDeployment/" + run_id + "/" + str(iteration)
conda_env_file_name = "myenv.yml"
scoring_file_name = "scoring.py"

if not os.path.exists(directory):
    os.makedirs(directory)

os.chdir(directory)
os.getcwd()

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

experiment = Experiment(ws, experiment_name)

ml_run = AutoMLRun(experiment=experiment, run_id=run_id)

if ml_run.model_id is None:
    model = ml_run.register_model(description=description,
                                  tags=tags,
                                  iteration=iteration)

file = open(scoring_file_name, "w")

file.writelines([
    "import pickle\n", "import json\n", "import numpy\n",
示例#9
0
from azureml.core.compute import ComputeTarget, DatabricksCompute
from azureml.core.compute_target import ComputeTargetException
import math
from pyspark.sql.window import Window
from azureml.core.webservice import AciWebservice
from azureml.core.model import InferenceConfig
from azureml.core.model import Model
from azureml.core.webservice import Webservice
from azureml.core.conda_dependencies import CondaDependencies
from azureml.core.environment import Environment
from azureml.core.datastore import Datastore

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

ws = Workspace.get(name="mlws-poc-eastus",
               subscription_id='7e48a1e8-8d3e-4e00-8bc0-098c43f5ace7',
               resource_group='rg-machinelearning-eastus')

experiment_name = 'automl-nyctaxi-classification-dbr'
experiment=Experiment(ws, experiment_name)

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

# MAGIC %md
# MAGIC 
# MAGIC #### Create DBR Compute

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

db_compute_name = "dbr-compute-nyc"
db_resource_group = "rg-smartbox-aml-eastus-poc"