Skip to content

Commit 3c9030f

Browse files
authored
Merge pull request #108392 from rastala/master
Describe user managed dependencies
2 parents ede6502 + f72ffd1 commit 3c9030f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

articles/machine-learning/how-to-use-environments.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ myenv.docker.base_image="your_base-image"
246246
myenv.docker.base_image_registry="your_registry_location"
247247
```
248248

249-
Alternatively, you can specify a custom Dockerfile. It is simplest to start from one of Azure Machine Learning base images using Docker ```FROM``` command, and then add your own custom steps. Use this approach if you need to install non-Python packages as dependencies.
249+
You can also specify a custom Dockerfile. It's simplest to start from one of Azure Machine Learning base images using Docker ```FROM``` command, and then add your own custom steps. Use this approach if you need to install non-Python packages as dependencies.
250250

251251
```python
252252
# Specify docker steps as a string. Alternatively, load the string from a file.
@@ -260,8 +260,29 @@ myenv.docker.base_image = None
260260
myenv.docker.base_dockerfile = dockerfile
261261
```
262262

263-
> [!NOTE]
264-
> If you specify `environment.python.user_managed_dependencies=False` while you're using a custom Docker image, then the service will build a Conda environment within the image. It will execute the run in that environment instead of using any Python libraries that you installed on the base image. Set the parameter to `True` to use your own installed packages.
263+
### Use user-managed dependencies
264+
265+
In some situations, your custom base image may already contain a Python environment with packages that you want to use.
266+
267+
By default, Azure Machine Learning service will build a Conda environment with dependencies you specified, and will execute the run in that environment instead of using any Python libraries that you installed on the base image.
268+
269+
To use your own installed packages, set the parameter `Environment.python.user_managed_dependencies = True`. Ensure that the base image contains a Python interpreter, and has the packages your training script needs.
270+
271+
For example, to run in a base Miniconda environment that has NumPy package installed, first specify a Dockerfile with a step to install the package. Then set the user-managed dependencies to `True`.
272+
273+
You can also specify a path to a specific Python interpreter within the image, by setting the `Environment.python.interpreter_path` variable.
274+
275+
```python
276+
dockerfile = """
277+
FROM mcr.microsoft.com/azureml/base:intelmpi2018.3-ubuntu16.04
278+
RUN conda install numpy
279+
"""
280+
281+
myenv.docker.base_image = None
282+
myenv.docker.base_dockerfile = dockerfile
283+
myenv.python.user_managed_dependencies=True
284+
myenv.python.interpreter_path = "/opt/miniconda/bin/python"
285+
```
265286

266287
## Use environments for training
267288

0 commit comments

Comments
 (0)