0

I am trying to print a .yml file for an environment. I can do it for this environment:

env = Environment.get(workspace = ws, name = 'AzureML-AutoML', version=115)
print(env)
print(env.python.conda_dependencies.serialize_to_string())

>>>Environment(Name: AzureML-AutoML,
Version: 115)
channels:
- anaconda
- conda-forge
- pytorch
dependencies:
- python=3.7.9
- pip=20.2.4
- pip:
  - azureml-core==1.42.0
  - azureml-mlflow==1.42.0
...

When I use the same code for this other environment I get an error:

infer_env = 'AzureML-pytorch-1.10-ubuntu18.04-py37-cpu-inference'
curated_pytorch_infer_env = Environment.get(workspace = ws, name = infer_env, version=4)

print(curated_pytorch_infer_env)
print(curated_pytorch_infer_env.python.conda_dependencies.serialize_to_string())

>>> AttributeError: 'NoneType' object has no attribute 'serialize_to_string'

How do I get/print a .yml file for 'curated_pytorch_infer_env'?

Ecstasy
  • 1,866
  • 1
  • 9
  • 17
Mattpats
  • 414
  • 2
  • 9
  • 21

2 Answers2

0

To resolve AttributeError: 'NoneType' object has no attribute 'serialize_to_string' try following ways:

1. According to Use curated environments:

Note: The name prefix AzureML is reserved for curated environments. Don't use it for your own environment.

You can try this code snippet taken from the document:

envs = Environment.list(workspace=ws)

for env in envs:
    if env.startswith("AzureML"):
        print("Name",env)
        if envs[env].python.conda_dependencies is not None:
            print("packages", envs[env].python.conda_dependencies.serialize_to_string())

2. Try upgrading to the latest version i.e. PyTorch 1.12

Ecstasy
  • 1,866
  • 1
  • 9
  • 17
  • thanks for the response. dependencies of some environments print, but the dependencies for the env I'm interested in do not print. is there a way to print all dependencies (not just conda dependencies)? – Mattpats Jun 30 '22 at 22:54
  • I don't think so it's possible in curated environments, maybe it's possible for `user_managed_dependencies`. References: [Use a curated environment](https://learn.microsoft.com/en-us/azure/machine-learning/how-to-use-environments#use-a-curated-environment) and [azureml.core.conda_dependencies](https://learn.microsoft.com/en-us/python/api/azureml-core/azureml.core.conda_dependencies?view=azure-ml-py) – Ecstasy Jul 01 '22 at 04:48
0

You can submit a job with the environment that would do conda export in a subprocess. Probably this might work https://learn.microsoft.com/en-us/python/api/azureml-core/azureml.core.environment.environment?view=azure-ml-py#azureml-core-environment-environment-from-existing-conda-environment

Environment name is returned in env.get_image_details(ws) response.

Easiest way might be to pull corresponding image and run it locally to conda export

vizhur
  • 467
  • 3
  • 7
  • how would I pull the image from Azure? – Mattpats Jul 06 '22 at 01:08
  • docker pull of the image returned from get_image_details() or UI. you'd need to docker login to the registry, from the azure portal (workspace view) you can navigate to container registry tab and get credentials if admin mode is enabled, otherwise you can create scoped access Azure Container Registry help page has all the info. – vizhur Jul 06 '22 at 16:27