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
 def __init__(self, spn_credentials, subscription_id, workspace_name,
              resource_group):
     auth = ServicePrincipalAuthentication(**spn_credentials)
     self.workspace = Workspace(workspace_name=workspace_name,
                                auth=auth,
                                subscription_id=subscription_id,
                                resource_group=resource_group)
Пример #3
0
def init():
    global g_tf_sess

    svc_pr_password = "******"
 
    svc_pr = ServicePrincipalAuthentication(
        tenant_id="72f988bf-86f1-41af-91ab-2d7cd011db47",
        service_principal_id="8a3ddafe-6dd6-48af-867e-d745232a1833",
        service_principal_password="******")

    ws = Workspace(
        subscription_id="c46a9435-c957-4e6c-a0f4-b9a597984773",
        resource_group="mlops",
        workspace_name="gputraining",
        auth=svc_pr
        )
    model_root = os.getenv('AZUREML_MODEL_DIR')
    # Pull down the model from the workspace
    model_path = Model.get_model_path("tf-dnn-mnist")
    tf_model_folder = 'model'
    # Create a model folder in the current directory
    os.makedirs('./outputs', exist_ok=True)
    os.makedirs('./outputs/model', exist_ok=True)

    # Construct a graph to execute
    tf.reset_default_graph()
    saver = tf.train.import_meta_graph(os.path.join(model_path, 'tf-dnn-mnist.meta'))
    g_tf_sess = tf.Session()
    #saver.restore(g_tf_sess, os.path.join(model_path, tf_model_folder, 'tf-dnn-mnist.model'))
    saver.restore(g_tf_sess, os.path.join(model_path, 'tf-dnn-mnist'))
Пример #4
0
def get_workspace(compute_name=None, compute_config=None):
    if TENANT_ID is None or \
            SERVICE_PRINCIPAL_ID is None or \
            SERVICE_PRINCIPAL_PASSWORD is None or \
            SUBSCRIPTION_ID is None or \
            RESOURCE_GROUP_NAME is None or \
            WORKSPACE_NAME is None or \
            WORKSPACE_LOCATION is None:
        print("One of the required environment variables is not set. "
              "Running locally instead.")
        return None

    logger.info("Logging in as service principal.")
    auth = ServicePrincipalAuthentication(TENANT_ID,
                                          SERVICE_PRINCIPAL_ID,
                                          SERVICE_PRINCIPAL_PASSWORD)
    logger.info("Successfully logged in as service principal.")

    logger.info("Ensuring resource group {} exists.".format(RESOURCE_GROUP_NAME))
    resource_management_client = resource_client_factory(auth, SUBSCRIPTION_ID)
    resource_group_properties = ResourceGroup(location=WORKSPACE_LOCATION)
    resource_management_client.resource_groups.create_or_update(WORKSPACE_NAME,
                                                                resource_group_properties)
    logger.info("Ensured resource group {} exists.".format(RESOURCE_GROUP_NAME))

    logger.info("Ensuring workspace {} exists.".format(WORKSPACE_NAME))
    workspace = Workspace.create(name=WORKSPACE_NAME, auth=auth, subscription_id=SUBSCRIPTION_ID,
                                 resource_group=RESOURCE_GROUP_NAME, location=WORKSPACE_LOCATION,
                                 create_resource_group=False, exist_ok=True)
    logger.info("Ensured workspace {} exists.".format(WORKSPACE_NAME))
    logger.info("Ensuring compute exists.")
    get_or_create_compute_cluster(workspace, compute_name, compute_config)
    logger.info("Ensured compute exists.")
    return workspace
Пример #5
0
def authenticate():
    print(f'TENANT_ID : {secret.TENANT_ID}')
    svc_pr = ServicePrincipalAuthentication(
        tenant_id=secret.TENANT_ID,
        service_principal_id=secret.SERVICE_PRINCIPAL_APP_ID,
        service_principal_password=secret.SERVICE_PRINCIPAL_SECRET)
    return svc_pr
Пример #6
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.workspace = None
        self.compute_instance = None
        self._application_urls = None
        self.redirect_server = None

        self.subscription_id = os.environ['SUBSCRIPTION_ID']
        self.location = os.environ['LOCATION']

        self.tenant_id = os.environ["AAD_TENANT_ID"]
        self.client_id = os.environ["AAD_CLIENT_ID"]
        self.client_secret = os.environ["AAD_CLIENT_SECRET"]

        self.cred = ClientSecretCredential(tenant_id=self.tenant_id,
                                           client_id=self.client_id,
                                           client_secret=self.client_secret)
        self.sp_cred = ServicePrincipalCredentials(tenant=self.tenant_id,
                                                   client_id=self.client_id,
                                                   secret=self.client_secret)
        self.sp_auth = ServicePrincipalAuthentication(
            tenant_id=self.tenant_id,
            service_principal_id=self.client_id,
            service_principal_password=self.client_secret)
        self.res_mgmt_client = ResourceManagementClient(
            self.sp_cred, self.subscription_id)
        self.compute_mgmt_client = ComputeManagementClient(
            self.cred, self.subscription_id)
        self.available_vm_sizes = self._available_vm_sizes()
Пример #7
0
def get_workspace():
    import os
    import json
    from azureml.core.authentication import ServicePrincipalAuthentication
    from azureml.core import Workspace

    base_dir = "."

    config_json = os.path.join(base_dir, "config.json")
    with open(config_json, "r") as f:
        config = json.load(f)

    try:
        svc_pr = ServicePrincipalAuthentication(
            tenant_id=config["tenant_id"],
            service_principal_id=config["service_principal_id"],
            service_principal_password=config["service_principal_password"],
        )
    except KeyError:
        print("Getting Service Principal Authentication from Azure Devops.")
        svc_pr = None
        pass

    ws = Workspace.from_config(path=config_json, auth=svc_pr)

    return ws
Пример #8
0
def cancel_running_and_queued_jobs() -> None:
    environ = os.environ
    print("Authenticating")
    auth = ServicePrincipalAuthentication(
        tenant_id='72f988bf-86f1-41af-91ab-2d7cd011db47',
        service_principal_id=environ["APPLICATION_ID"],
        service_principal_password=environ["APPLICATION_KEY"])
    print("Getting AML workspace")
    workspace = Workspace.get(name="InnerEye-DeepLearning",
                              auth=auth,
                              subscription_id=environ["SUBSCRIPTION_ID"],
                              resource_group="InnerEye-DeepLearning")
    branch = environ["BRANCH"]
    print(f"Branch: {branch}")
    if not branch.startswith("refs/pull/"):
        print("This branch is not a PR branch, hence not cancelling anything.")
        exit(0)
    experiment_name = branch.replace("/", "_")
    print(f"Experiment: {experiment_name}")
    experiment = Experiment(workspace, name=experiment_name)
    print(f"Retrieved experiment {experiment.name}")
    for run in experiment.get_runs(include_children=True, properties={}):
        assert isinstance(run, Run)
        status_suffix = f"'{run.status}' run {run.id} ({run.display_name})"
        if run.status in (RunStatus.COMPLETED, RunStatus.FAILED,
                          RunStatus.FINALIZING, RunStatus.CANCELED,
                          RunStatus.CANCEL_REQUESTED):
            print(f"Skipping {status_suffix}")
        else:
            print(f"Cancelling {status_suffix}")
            run.cancel()
Пример #9
0
def retrieve_workspace() -> Workspace:
    ws = None

    try:
        run = Run.get_context()
        if not isinstance(run, _OfflineRun):
            ws = run.experiment.workspace
            return ws
    except Exception as e:
        print('Workspace from run not found', e)

    try:
        ws = Workspace.from_config()
        return ws
    except Exception as e:
        print('Workspace config not found in local folder', e)

    try:
        sp = ServicePrincipalAuthentication(
            tenant_id=os.environ['AML_TENANT_ID'],
            service_principal_id=os.environ['AML_PRINCIPAL_ID'],
            service_principal_password=os.environ['AML_PRINCIPAL_PASS'])
        ws = Workspace.get(name="ml-example",
                           auth=sp,
                           subscription_id="your-sub-id")
    except Exception as e:
        print('Workspace config not found in project', e)

    return ws
Пример #10
0
def retrieve_workspace() -> Workspace:
    ws = None

    try:
        ws = Workspace.from_config()
        return ws

    except Exception as e:
        print('Workspace not found in local repo.')
        print('Trying Service Principal')

    try:
        sp = ServicePrincipalAuthentication(
            tenant_id=os.environ['AML_TENANT_ID'],
            service_principal_id=os.environ['AML_PRINCIPAL_ID'],
            service_principal_password=os.environ['AML_PRINCIPAL_PASS'])

        ws = Workspace.get(name=os.environ['AML_WORKSPACE_NAME'],
                           auth=sp,
                           subscription_id=os.environ['SUBSCRIPTION_ID'])
        return ws
    except Exception as e:
        print('Connection via SP failed:', e)

    if not ws:
        print('Error - Workspace not found')
        print('Error - Shuting everything down.')
        sys.exit(-1)
Пример #11
0
def main():
    load_dotenv()
    TENANT_ID = os.environ.get('TENANT_ID')
    APP_ID = os.environ.get('SP_APP_ID')
    APP_SECRET = os.environ.get('SP_APP_SECRET')
    WORKSPACE_NAME = os.environ.get("BASE_NAME") + "-aml"
    SUBSCRIPTION_ID = os.environ.get('SUBSCRIPTION_ID')
    RESOURCE_GROUP = os.environ.get("RESOURCE_GROUP_NAME")
    EPIS_DATASTORE = os.environ.get("EPIS_DATASTORE")
    ANNO_PATH_TRAIN = os.environ.get("ANNO_PATH_TRAIN")
    ANNO_PATH_TEST = os.environ.get("ANNO_PATH_TEST")
    EPIS_CONTAINER = os.environ.get("EPIS_CONTAINER")

    SP_AUTH = ServicePrincipalAuthentication(
        tenant_id=TENANT_ID,
        service_principal_id=APP_ID,
        service_principal_password=APP_SECRET)

    WORKSPACE = Workspace.get(WORKSPACE_NAME, SP_AUTH, SUBSCRIPTION_ID,
                              RESOURCE_GROUP)

    try:
        convert_voc_annotation(WORKSPACE, EPIS_DATASTORE, "trainval",
                               ANNO_PATH_TRAIN, EPIS_CONTAINER)
        convert_voc_annotation(WORKSPACE, EPIS_DATASTORE, "test",
                               ANNO_PATH_TEST, EPIS_CONTAINER)
    except Exception as caught_error:
        print("Error while download datastore: " + str(caught_error))
Пример #12
0
def shutdownComputeInstances():

    #Get service principal details from app settings
    subscriptionID = os.environ["subscriptionID"]
    tenantID = os.environ["tenantID"]
    clientID = os.environ["clientID"]
    spSecret = os.environ["secret"]
    resourceGroupName = os.environ["resourceGroupName"]
    amlWorkspaceName = os.environ["amlWorkspaceName"]

    #logging.info(subscriptionID, tenantID, clientID, spSecret)

    #Authenticate to AML workspace with service principal
    auth = ServicePrincipalAuthentication(tenant_id=tenantID,
                                          service_principal_id=clientID,
                                          service_principal_password=spSecret)

    ws = Workspace(subscription_id=subscriptionID,
                   resource_group=resourceGroupName,
                   workspace_name=amlWorkspaceName,
                   auth=auth)

    #Loop through workspace compute, stop all compute instances
    computeList = ComputeTarget.list(ws)
    for compute in computeList:
        if compute.type == 'ComputeInstance':
            logging.info("stop compute instance")
            compute.stop()
Пример #13
0
def trigger_training_job(compute_name, script_folder):

    # Define Vars < Change the vars>
    tenant_id = "<Enter Your Tenant Id>"
    app_id = "<Application Id of the SPN you Create>"
    app_key = "<Key for the SPN>"
    workspace = "<Name of your workspace>"
    subscription_id = "<Subscription id>"
    resource_grp = "<Name of your resource group where aml service is created>"
    experiment_name = '<Name of your experiment you defined in dataprep.py>'

    print("Starting trigger engine")
    # Start creating
    # Point file to conf directory containing details for the aml service
    spn = ServicePrincipalAuthentication(tenant_id, app_id, app_key)
    ws = Workspace(auth=spn,
                   workspace_name=workspace,
                   subscription_id=subscription_id,
                   resource_group=resource_grp)

    #ws = Workspace.from_config(path="../conf/config.json")
    ds = ws.get_default_datastore()
    print(ds.datastore_type, ds.account_name, ds.container_name)
    exp = Experiment(workspace=ws, name=experiment_name)
    compute_target = ws.compute_targets[compute_name]
    script_params = {'--data-folder': ds.as_mount(), '--regularization': 0.8}
    est = Estimator(source_directory=script_folder,
                    script_params=script_params,
                    compute_target=compute_target,
                    entry_script='train.py',
                    conda_packages=['scikit-learn'])
    print("Submitting Runs to AML compute " + compute_name)
    run = exp.submit(config=est)
    run.wait_for_completion(show_output=True)  # specify True for a verbose log
Пример #14
0
def get_workspace():
    dotenv.load_dotenv()
    workspace_name = os.environ.get("WORKSPACE")
    resource_group = os.environ.get("RESOURCE_GROUP")
    subscription_id = os.environ.get("SUBSCRIPTION_ID")
    tenant_id = os.environ.get("TENANT_ID")
    app_id = os.environ.get("SP_APP_ID")
    app_secret = os.environ.get("SP_APP_SECRET")

    service_principal = ServicePrincipalAuthentication(
        tenant_id=tenant_id,
        service_principal_id=app_id,
        service_principal_password=app_secret)

    try:
        aml_workspace = Workspace.get(name=workspace_name,
                                      subscription_id=subscription_id,
                                      resource_group=resource_group,
                                      auth=service_principal)

        return aml_workspace
    except Exception as caught_exception:
        print("Error while retrieving Workspace...")
        print(str(caught_exception))
        sys.exit(1)
Пример #15
0
def run(model_path, model_name, tenant_id, service_principal_id,
        service_principal_password, subscription_id, resource_group, workspace,
        tags):
    auth_args = {
        'tenant_id': tenant_id,
        'service_principal_id': service_principal_id,
        'service_principal_password': service_principal_password
    }

    ws_args = {
        'auth': ServicePrincipalAuthentication(**auth_args),
        'subscription_id': subscription_id,
        'resource_group': resource_group
    }

    ws = Workspace.get(workspace, **ws_args)

    print(ws.get_details())

    print('\nSaving model {} to {}'.format(model_path, model_name))

    # Model Path needs to be relative
    model_path = relpath(model_path, '.')

    model = Model.register(ws,
                           model_name=model_name,
                           model_path=model_path,
                           tags=tags)
    print('Done!')
Пример #16
0
def main():
    load_dotenv()
    workspace_name = os.environ.get("BASE_NAME")+"-AML-WS"
    resource_group = os.environ.get("BASE_NAME")+"-AML-RG"
    subscription_id = os.environ.get("SUBSCRIPTION_ID")
    tenant_id = os.environ.get("TENANT_ID")
    experiment_name = os.environ.get("EXPERIMENT_NAME")
    model_name = os.environ.get("MODEL_NAME")
    app_id = os.environ.get('SP_APP_ID')
    app_secret = os.environ.get('SP_APP_SECRET')
    release_id = os.environ.get('RELEASE_RELEASEID')
    build_id = os.environ.get('BUILD_BUILDID')
    storageacctname = os.environ.get('STORAGE_ACCT_NAME')
    storageacctkey = os.environ.get('STORAGE_ACCT_KEY')
    containername = os.environ.get('STORAGE_BLOB_NAME')

    service_principal = ServicePrincipalAuthentication(
            tenant_id=tenant_id,
            service_principal_id=app_id,
            service_principal_password=app_secret)

    aml_workspace = Workspace.get(
        name=workspace_name,
        subscription_id=subscription_id,
        resource_group=resource_group,
        auth=service_principal
        )

    # Find the pipeline that was published by the specified build ID
    pipelines = PublishedPipeline.list(aml_workspace)
    matched_pipes = []

    for p in pipelines:
        if p.version == build_id:
            matched_pipes.append(p)

    if(len(matched_pipes) > 1):
        published_pipeline = None
        raise Exception(f"Multiple active pipelines are published for build {build_id}.")  # NOQA: E501
    elif(len(matched_pipes) == 0):
        published_pipeline = None
        raise KeyError(f"Unable to find a published pipeline for this build {build_id}")  # NOQA: E501
    else:
        published_pipeline = matched_pipes[0]

    pipeline_parameters = {
            "model_name": model_name, 
            "release_id": release_id,
            "storageacctname": storageacctname,
            "storageacctkey": storageacctkey,
            "containername": containername
        }

    response = published_pipeline.submit(
        aml_workspace,
        experiment_name,
        pipeline_parameters)

    run_id = response.id
    print("Pipeline run initiated ", run_id)
def get_workspace() -> Workspace:
    tenant_id = os.environ["SP_TENANT_ID"]
    app_id = os.environ["SP_APP_ID"]
    secret = os.environ["SP_PASSWORD"]
    sub_id = os.environ["SUBSCRIPTION"]
    sp = ServicePrincipalAuthentication(tenant_id, app_id, secret)
    ws = Workspace(sub_id, db_rg, az_ml_ws_name, auth=sp)
    return ws
Пример #18
0
def get_workspace():
    # Security for the RBAC principal
    client_id = 'e0ae87de-e27b-433a-b7b5-017b0cd0808f'
    client_secret = 'de90f973-5a74-4e1c-a3a1-fa8265ca8ccd'
    tenant_id = '5c384fed-84cc-44a6-b34a-b060bf102a6e'
    servicePrincipalAuth = ServicePrincipalAuthentication(
        tenant_id, client_id, client_secret)
    workspace = Workspace.from_config(auth=servicePrincipalAuth)
    return workspace
Пример #19
0
def get_service_principal():
    tenant_id = os.environ.get("TENANT_ID")
    service_principal_id = os.environ.get("SERVICE_PRINCIPAL_ID")
    service_principal_password = os.environ.get("SERVICE_PRINCIPAL_SECRET")

    return ServicePrincipalAuthentication(
        tenant_id=tenant_id,
        service_principal_id=service_principal_id,
        service_principal_password=service_principal_password)
Пример #20
0
def get_workspace(
    name: str,
    resource_group: str,
    subscription_id: str,
    tenant_id: str,
    app_id: str,
    app_secret: str,
    region: str,
    create_if_not_exist=False,
):
    """

    Parameters:
      name (str): name of the workspace
      resource_group (str): resource group name
      subscription_id (str): subscription id
      tenant_id (str): tenant id (aad id)
      app_id (str): service principal id
      app_secret (str): service principal password
      region (str): location of the workspace
      create_if_not_exist (bool): Default value is False

    Returns:
      Workspace: a reference to a workspace
    """
    service_principal = ServicePrincipalAuthentication(
        tenant_id=tenant_id,
        service_principal_id=app_id,
        service_principal_password=app_secret,
    )

    try:
        aml_workspace = Workspace.get(
            name=name,
            subscription_id=subscription_id,
            resource_group=resource_group,
            auth=service_principal,
        )

    except WorkspaceException as exp_var:
        log.error("Error while retrieving Workspace...: %s", exp_var)
        if create_if_not_exist:
            log.info("Creating AzureML Workspace: %s", name)
            aml_workspace = Workspace.create(
                name=name,
                subscription_id=subscription_id,
                resource_group=resource_group,
                create_resource_group=True,
                location=region,
                auth=service_principal,
            )
            log.info("Workspace %s created.", aml_workspace.name)
        else:
            sys.exit(-1)

    return aml_workspace
Пример #21
0
    def get_serviceprincipal_auth(self):        
        svc_pr = None
        if self.service_principal_password:
            svc_pr = ServicePrincipalAuthentication(
                tenant_id=self.service_principal_tenant_id,
                service_principal_id=self.service_principal_id,
                service_principal_password=self.service_principal_password
            )

        return svc_pr
Пример #22
0
    def get_serviceprincipal_auth(self):
        from azureml.core.authentication import ServicePrincipalAuthentication

        svc_pr = None
        if self.client_secret:
            svc_pr = ServicePrincipalAuthentication(
                tenant_id=self.directory_tenant_id,
                service_principal_id=self.application_client_id,
                service_principal_password=self.client_secret)
        return svc_pr
def main():
    load_dotenv()
    workspace_name = os.environ.get("WORKSPACE_NAME")
    resource_group = os.environ.get("RESOURCE_GROUP_NAME")
    subscription_id = os.environ.get("SUBSCRIPTION_ID")
    tenant_id = os.environ.get("TENANT_ID")
    experiment_name = os.environ.get("EXPERIMENT_NAME")
    model_name = os.environ.get("MODEL_NAME")
    ckpt_path = os.environ.get("MODEL_CHECKPOINT_PATH")
    app_id = os.environ.get('SP_APP_ID')
    app_secret = os.environ.get('SP_APP_SECRET')
    build_id = os.environ.get('BUILD_BUILDID')
    datastore = os.environ.get('EPIS_DATASTORE')
    container_name = os.environ.get('EPIS_CONTAINER')

    service_principal = ServicePrincipalAuthentication(
        tenant_id=tenant_id,
        service_principal_id=app_id,
        service_principal_password=app_secret)

    aml_workspace = Workspace.get(name=workspace_name,
                                  subscription_id=subscription_id,
                                  resource_group=resource_group,
                                  auth=service_principal)

    pipelines = PublishedPipeline.list(aml_workspace)
    matched_pipes = []

    for p in pipelines:
        if p.version == build_id:
            matched_pipes.append(p)

    if (len(matched_pipes) > 1):
        published_pipeline = None
        raise Exception(
            f"Multiple active pipelines are published for build {build_id}.")
    elif (len(matched_pipes) == 0):
        published_pipeline = None
        raise KeyError(
            f"Unable to find a published pipeline for this build {build_id}")
    else:
        published_pipeline = matched_pipes[0]

    pipeline_parameters = {
        "model_name": model_name,
        "ckpt_path": ckpt_path,
        "datastore": datastore,
        "storage_container": container_name
    }

    response = published_pipeline.submit(aml_workspace, experiment_name,
                                         pipeline_parameters)

    run_id = response.id
    print("Pipeline run initiated ", run_id)
Пример #24
0
def get_ws():
    auth_args = {
        'tenant_id': os.environ.get('AZ_TENANT_ID'),
        'service_principal_id': os.environ.get('AZ_CLIENT_ID'),
        'service_principal_password': os.environ.get('AZ_CLIENT_SECRET')
    }
    ws = Workspace.get(name=os.environ.get('AZ_NAME'),
                       auth=ServicePrincipalAuthentication(**auth_args),
                       subscription_id=os.environ.get('AZ_SUBSCRIPTION_ID'),
                       resource_group=os.environ.get('AZ_RESOURCE_GROUP'))
    return ws
Пример #25
0
def run(model_path, model_name):
    auth_args = {
        'tenant_id': os.environ['TENANT_ID'],
        'service_principal_id': os.environ['SERVICE_PRINCIPAL_ID'],
        'service_principal_password': os.environ['SERVICE_PRINCIPAL_PASSWORD']
    }

    ws_args = {
        'auth': ServicePrincipalAuthentication(**auth_args),
        'subscription_id': os.environ['SUBSCRIPTION_ID'],
        'resource_group': os.environ['RESOURCE_GROUP']
    }

    ws = Workspace.get(os.environ['WORKSPACE_NAME'], **ws_args)

    print(ws.get_details())

    print('\nSaving model {} to {}'.format(model_path, model_name))
    model = Model.register(ws, model_name=model_name, model_path=model_path)
    print('Done!')

    print('Checking for existing service {}'.format(model_name))
    service_name = 'simplemnist-svc'
    if model_name in ws.webservices:
        print('Found it!\nRemoving Existing service...')
        ws.webservices[model_name].delete()
        print('Done!')
    else:
        print('Not found, creating new one!')

    # image configuration
    image_config = ContainerImage.image_configuration(
        execution_script="score.py",
        runtime="python",
        conda_file="environment.yml")

    # deployement configuration
    aciconfig = AciWebservice.deploy_configuration(cpu_cores=1,
                                                   memory_gb=1,
                                                   description=model_name)

    # deploy
    service = Webservice.deploy_from_model(workspace=ws,
                                           name=model_name,
                                           models=[model],
                                           image_config=image_config,
                                           deployment_config=aciconfig)

    service.wait_for_deployment(show_output=True)

    #print logs
    print(service.get_logs())

    print('Done!')
Пример #26
0
def get_service_principal_auth():
    tenant_id = os.environ[_TENANT_ID_ENV_NAME]
    service_principal_id = os.environ[_SERVICE_PRINCIPAL_ID_ENV_NAME]
    service_principal_password = os.environ[_SERVICE_PRINCIPAL_SECRET_ENV_NAME]

    svc_pr = ServicePrincipalAuthentication(
        tenant_id=tenant_id,
        service_principal_id=service_principal_id,
        service_principal_password=service_principal_password)

    return svc_pr
Пример #27
0
def loadAuthCredentials(args):
    with open(args.spconfig) as jsonFile:
        data = json.load(jsonFile)
    tenantid = data['tenantid']
    applicationid = data['applicationid']
    password = data['password']
    if (args.verbose):
        print("Tenant Id                  : {0}".format(tenantid))
        print("Application Id is          : {0}".format(applicationid))

    svc_pr = ServicePrincipalAuthentication(tenantid, applicationid, password)
    return svc_pr
def run():
    global model
    svc_pr = ServicePrincipalAuthentication(
        tenant_id="1faf88fe-a998-4c5b-93c9-210a11d9a5c2",
        service_principal_id="3683e499-d9d1-4b25-9e51-fc0c056415da",
        service_principal_password=os.environ.get("AZUREML_PASSWORD"))
    # retrieve the path to the model file using the model name
    ws = Workspace.get(name='foram-workspace',
                       subscription_id='d90d34f0-1175-4d80-a89e-b74e16c0e31b',
                       auth=svc_pr)
    model_path = Model.get_model_path('resnet18', _workspace=ws)
    model = load_checkpoint(model_path)
Пример #29
0
def get_workspace(workspace: str, subscription: str, resource_group: str,
                  tenantId: str, clientId: str,
                  clientSecret: str) -> Workspace:

    svcprincipal = ServicePrincipalAuthentication(
        tenant_id=tenantId,
        service_principal_id=clientId,
        service_principal_password=clientSecret)
    return Workspace.get(name=workspace,
                         subscription_id=subscription,
                         resource_group=resource_group,
                         auth=svcprincipal)
Пример #30
0
def get_workspace(workspace_name, resource_group, subscription_id):
  svc_pr = ServicePrincipalAuthentication(
      tenant_id = dbutils.secrets.get(scope = "azure-key-vault", key = "tenant-id"),
      service_principal_id = dbutils.secrets.get(scope = "azure-key-vault", key = "client-id"),
      service_principal_password = dbutils.secrets.get(scope = "azure-key-vault", key = "client-secret"))

  workspace = Workspace.get(name = workspace_name,
                            resource_group = resource_group,
                            subscription_id = subscription_id,
                            auth=svc_pr)
  
  return workspace
def get_auth():
    logger = logging.getLogger(__name__)
    if os.environ.get("AML_SP_PASSWORD", None):
        logger.debug("Trying to create Workspace with Service Principal")
        aml_sp_password = os.environ.get("AML_SP_PASSWORD")
        aml_sp_tennant_id = os.environ.get("AML_SP_TENNANT_ID")
        aml_sp_username = os.environ.get("AML_SP_USERNAME")
        auth = ServicePrincipalAuthentication(
            tenant_id=aml_sp_tennant_id,
            username=aml_sp_username,
            password=aml_sp_password,
        )
    else:
        logger.debug("Trying to create Workspace with CLI Authentication")
        try:
            auth = AzureCliAuthentication()
            auth.get_authentication_header()
        except AuthenticationException:
            logger.debug("Trying to create Workspace with Interactive login")
            auth = InteractiveLoginAuthentication()

    return auth