Path to already registered model file for docker image construction

Mata, Evan [USA] 1 Reputation point
2021-10-18T18:15:56.15+00:00

I'm attempting to create a docker image containing my already registered model; working with my currently working python code. My question is - what is the Model directory?

In this guide:
https://learn.microsoft.com/en-us/azure/machine-learning/how-to-extend-prebuilt-docker-image-inference
it states:

If the model and code need to be built into the image, the following environment variables need to be set in the Dockerfile:

AZUREML_ENTRY_SCRIPT: The entry script of your code. This file contains the init() and run() methods.
AZUREML_MODEL_DIR: The directory that contains the model file(s). The entry script should use this directory as the root directory of the model.

It then goes on to give an example with this line:
COPY <model_directory> /var/azureml-app/azureml-models
Basically, I'm trying to figure out what <model_directory> should be.

My dockerfile is currently:

FROM python:3  
  
COPY *.py /opt/azureml-app \  
    requirements.txt /opt/azureml-app \  
    ./model.pkl /opt/azureml-app/azureml-models  
  
RUN pip install -r requirements.txt   
  
ENV AZUREML_ENTRY_SCRIPT=trivialEntryScript.py \  
    AZUREML_MODEL_DIR=/opt/azureml-app/azureml-models  
  
ENTRYPOINT python /opt/azureml-app/trivialEntryScript.py   

The only files in the directory I'm building from are model.pkl, trivialEntryScript.py, requirements.txt and my Dockerfile. The folder structure is notebooks: myName/dockerTesting. I do have other directories, eg myName/mainCode which is where I ran my actual model training and registering. However, I manually added the model.pkl file into the dockerTesting folder (which I probably shouldn't need to do anyways?).

I've tried the following:
dockerfile as shown - error file does not exist
dockerfile COPY model.pkl /opt/azureml-app/azureml-models (eg no ./ in front of model.pkl) - error file does not exist

My confusion is a bit more general - I have no idea where the actual registered models are stored in terms of actual filepaths; eg when I registered model.pkl in the first place, its not in myName/mainCode where I trained it, though it does show up in the registered models tab. If I run a script that is only:

print( Model.get_model_path(model_name) )  

It will tell me my model isn't found in Cache or my current working directory - regardless of if I run in mainCode or dockerTesting. However, if I run the exact same command in the init method of a entryScript after deploying my model with an inference config and whatnot, it will load the model (deploying the model seems to download it to cache - but from Where? How do I put the original location into my docker file???).

trivialEntryScript is literally just the basic entry script from: https://learn.microsoft.com/en-us/azure/machine-learning/how-to-deploy-and-where?tabs=azcli

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,563 questions
{count} votes