azure-machine-learning-serviceazure-ml-pipelines

Azureml create environment using AzureML CLI v2 based on conda file and custom wheel


I want to create an environment using the AzureML CLI v2 by using the conda.yml and custom wheel file? I need an alternative of Environment.add_private_pip_wheel from the AzureML SDK v1.

Thank you


Solution

  • You can directly add your wheel file link in the Conda file pip dependencies.

    Here is the sample Conda file

    name: pydata-example
    channels:
      - conda-forge
    dependencies:
      - python=3.8
      - pip=21.2.4
      - pip:
        - scipy==1.7.1
        - pandas==1.3.0
        - scikit-learn==0.24.2
        - adlfs==2021.9.1
        - fsspec==2021.8.1
        - xgboost==1.4.2
        - lightgbm==3.2.1
        - mlflow==1.20.2
        - azureml-mlflow==1.34.0
        - matplotlib==3.4.3
        - tqdm==4.62.2
        - joblib==1.2.0
        - jupyter==1.0.0
        - ipykernel==6.4.1
        - papermill==2.3.3
        - https://files.pythonhosted.org/packages/76/9b/139b42e808e44571412e2b70f970085dc6bd215a46814f91503a75ff5be5/numpy-1.22.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
    

    Here, at the end i have given wheel file link.

    Next use below code to create environment.

    from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
    from azure.ai.ml import MLClient
    
    try:
        credential = DefaultAzureCredential()
        # Check if given credential can get token successfully.
        credential.get_token("https://management.azure.com/.default")
    except Exception as ex:
        # Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
        credential = InteractiveBrowserCredential()
    
    
    ml_client = MLClient(
        credential, subscription_id, resource_group, workspace
    )
    

    Now, create environment

    env_docker_conda = Environment(
        image="mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04",
        conda_file="conda-yamls/your-conda-file.yml",
        name="docker-image-plus-conda-example",
        description="Environment created from a Docker image plus Conda environment.",
    )
    
    ml_client.environments.create_or_update(env_docker_conda)
    

    This will create a job which makes new environment.

    Make sure you giving correct wheel file according to the platform.

    Refer this for more ways to build environment.