Model deployment failed when using an environment prebuilt from a Dockerfile
See original GitHub issue- Package Name: azureml.core.model
- Package Version: 1.43.0
- Operating System: ubuntu20.04
- Python Version: Python 3.7.9
Describe the bug
We used a custom environment built from Dockerfile as the environment for model serving (named as my-model-serving-env
), but the model deployment failed with error of:
File "/opt/miniconda/lib/python3.7/site-packages/azureml/core/model.py", line 2222, in validate_configuration
or not self.environment.docker.base_image.startswith('mcr.microsoft.com/azureml')):
AttributeError: 'NoneType' object has no attribute 'startswith'
Here’s the Dockerfile for building the environment:
FROM mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:20220504.v1
COPY myapplication-1.0.0-py2.py3-none-any.whl /local-wheels/
COPY requirements.txt .
RUN python -m pip install --upgrade pip && \
python -m pip install /local-wheels/myapplication-1.0.0-py2.py3-none-any.whl && \
python -m pip install -r requirements.txt && \
rm requirements.txt
CMD ["/bin/bash"]
Here’s the requirements.txt
:
azureml-defaults
Below is the code snippet of model deployment:
def getMyModel(ws, name, id):
registered_models = Model.list(
workspace=ws,
name=name,
)
for m in registered_models:
if m.id == id:
return m
return None
run = Run.get_context()
ws = run.experiment.workspace
# Get the prebuilt registered environment my-model-serving-env:
env = Environment.get(ws, 'my-model-serving-env')
model_inference_config = InferenceConfig(
environment=env,
source_directory=".",
entry_script="./_my_model_score.py",
)
deployment_config = AciWebservice.deploy_configuration(
cpu_cores=0.5, memory_gb=1, auth_enabled=True
)
model_to_deploy = getMyModel(ws, "my_model", my_model_id)
if model_to_deploy != None:
service = Model.deploy(
ws,
"mymodelservice",
[model_to_deploy],
model_inference_config,
deployment_config,
overwrite=True,
)
service.wait_for_deployment(show_output=True)
print("model deployed.")
else:
print(f"[Error]: my_model with ID {my_model_id} not found.")
It seems that the docker.base_image
of the environment is not properly populated for the environments built from Dockerfiles (even if the base image is specified as FROM mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:20220504.v1
in the Dockerfile).
To Reproduce Steps to reproduce the behavior:
- Build the environment using the Dockerfile and the
requirements.txt
(as well as the application wheel file which provides implementation needed for model serving, but the application wheel file has nothing to do with the error reported). - Deploy the model to an endpoint using the above Python code snippet.
Expected behavior
The code for checking the base_image
of the environment (base_image.startswith('mcr.microsoft.com/azureml')
) in azureml.core.model.py
shouldn’t fail.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:9 (2 by maintainers)
Top GitHub Comments
@Rainfarm - Thanks for opening an issue! Directing this to @azureml-github to investigate as soon as possible.
We’ve already migrated to SDK v2, and don’t need the fix of this issue. Thank you @luigiw!