Search code examples
azureazure-machine-learning-serviceazuremlsdk

Importing MLClient in online endpoint gives error "cannot import name TokenCredential from azure.core.credentials"


I am trying to deploy an online endpoint where i fetch a pre-trained model, as well as a data asset containing embeddings. The reason is that i want to compare the endpoint input to the data asset and return the 5 most similar embeddings. However, when i import ML client like this from azure.ai.ml import MLClient i get the error cannot import name TokenCredential from azure.core.credentials

Am i missing a dependency, or is this not intended to work in online endpoints?

Here is the endpoint.yml file

name: model-env
channels:
  - conda-forge
dependencies:
  - python=3.8
  - numpy=1.21.2
  - pip=22.3.1
  - scipy=1.7.1
  - pandas>=1.1,<1.2
  - pip:
    - inference-schema[numpy-support]==1.3.0
    - applicationinsights==0.11.10
    - sentence-transformers ==2.2.2
    - pytorch-lightning == 1.7.6
    - azure-ai-ml
    - azure-identity 
    - azureml-defaults==1.38.0

Solution

  • Issue was solved. Turned out to be an issue with the azure-packages, and is expected to be fixed soon. In the meantime you can work around this by creating your own dockerfile rather than env.yaml, and force the azure-core, azure-idendity and azurem-ai-ml packages to the latest versions. More info on how to do that here: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-manage-environments-v2?tabs=cli#create-an-environment-from-a-docker-build-context