def setupenv_cluster()

in playbooks/roles/ood-applications/files/bc_amlsdk/template/amlwrapperfunctions.py [0:0]


def setupenv_cluster():

    credential = AzureCliCredential()
    try:
        ml_client = MLClient.from_config(credential=credential)
    except Exception as ex:
        client_config = {
            "subscription_id": envsetup.subscription_id,
            "resource_group": envsetup.resource_group,
            "workspace_name": envsetup.workspace_name,
        }
        import json
        import os

        config_path = ".azureml/config.json"
        os.makedirs(os.path.dirname(config_path), exist_ok=True)
        with open(config_path, "w") as fo:
            fo.write(json.dumps(client_config))
        ml_client = MLClient.from_config(
            credential=credential, path=config_path)

    gpu_compute_target = "gpu-cluster"

    try:
        ml_client.compute.get(gpu_compute_target)
    except Exception:
        print("Creating a new compute target...")
        compute = AmlCompute(
            name=gpu_compute_target,
            size=envsetup.machine_type,
            min_instances=0,
            max_instances=envsetup.max_instances
        )
        ml_client.compute.begin_create_or_update(compute).result()

    return ml_client