MataEvanUSA-1581 avatar image
0 Votes"
MataEvanUSA-1581 asked ramr-msft edited

Path to already registered model file for docker image construction

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:
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 \
 ENTRYPOINT python /opt/azureml-app/ 

The only files in the directory I'm building from are model.pkl,, 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:

· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MataEvanUSA-1581 Thanks for the question. If you have model file in the working directory and uploaded it to the run using upload_file and then registered the model.
Generally AML automatically upload content under ./outputs to AML workspace, and then run the run.register_model.

Here is the sample to register the model and deploy to the ACI and troubleshoot model doc for local deployment.

0 Votes 0 ·

Thanks, The script can directly import from them because the whole folder including and all other folders will be available at the inference running environment. There is no need to save them as a "model".

0 Votes 0 ·

I'm not sure I understand why this is relevant (at the step I'm at) - my python code files are in my relevant directory, and the COPY command at line 3 of the dockerfile seems to work fine for them? I don't believe I've had any issues with getting the python files to work properly, just <file not found> when looking for the model.pkl file using my docker build command. Of course I'd like to load the model.pkl in my init method eventually, but for now I'm just trying to get my container to build w. a that doesn't even load anything.

0 Votes 0 ·

I've already completed my runs / experiment, the model itself is already registered. I'm just attempting to access that model after its been trained and registered (my understanding is upload_file is for when you're training / registering in the first place - I'm attempt to access my already trained model and simply don't know the relevant file path).

0 Votes 0 ·

@MataEvanUSA-1581 Thanks for the details. Generally AML automatically upload content under ./outputs to AML workspace. Can you please share snapshot of the outputs+logs.

0 Votes 0 ·
Show more comments

0 Answers