Chapter 1. Storing models
You must store your model before you can deploy it. You can store a model in an S3 bucket, URI or Open Container Initiative (OCI) containers.
1.1. Using OCI containers for model storage Copy linkLink copied to clipboard!
As an alternative to storing a model in an S3 bucket or URI, you can upload models to Open Container Initiative (OCI) containers. Deploying models from OCI containers is also known as modelcars in KServe.
Using OCI containers for model storage can help you:
- Reduce startup times by avoiding downloading the same model multiple times.
- Reduce disk space usage by reducing the number of models downloaded locally.
- Improve model performance by allowing pre-fetched images.
Using OCI containers for model storage involves the following tasks:
- Storing a model in an OCI image.
Deploying a model from an OCI image by using either the user interface or the command line interface. To deploy a model by using:
- The user interface, see Deploying models on the single-model serving platform.
- The command line interface, see Deploying a model stored in an OCI image by using the CLI.
1.2. Storing a model in an OCI image Copy linkLink copied to clipboard!
You can store a model in an OCI image. The following procedure uses the example of storing a MobileNet v2-7 model in ONNX format.
Prerequisites
- You have a model in the ONNX format. The example in this procedure uses the MobileNet v2-7 model in ONNX format.
- You have installed the Podman tool.
Procedure
In a terminal window on your local machine, create a temporary directory for storing both the model and the support files that you need to create the OCI image:
cd $(mktemp -d)
cd $(mktemp -d)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
modelsfolder inside the temporary directory:mkdir -p models/1
mkdir -p models/1Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis example command specifies the subdirectory
1because OpenVINO requires numbered subdirectories for model versioning. If you are not using OpenVINO, you do not need to create the1subdirectory to use OCI container images.Download the model and support files:
DOWNLOAD_URL=https://github.com/onnx/models/raw/main/validated/vision/classification/mobilenet/model/mobilenetv2-7.onnx curl -L $DOWNLOAD_URL -O --output-dir models/1/
DOWNLOAD_URL=https://github.com/onnx/models/raw/main/validated/vision/classification/mobilenet/model/mobilenetv2-7.onnx curl -L $DOWNLOAD_URL -O --output-dir models/1/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
treecommand to confirm that the model files are located in the directory structure as expected:tree
treeCopy to Clipboard Copied! Toggle word wrap Toggle overflow The
treecommand should return a directory structure similar to the following example:. ├── Containerfile └── models └── 1 └── mobilenetv2-7.onnx. ├── Containerfile └── models └── 1 └── mobilenetv2-7.onnxCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Docker file named
Containerfile:Note-
Specify a base image that provides a shell. In the following example,
ubi9-microis the base container image. You cannot specify an empty image that does not provide a shell, such asscratch, because KServe uses the shell to ensure the model files are accessible to the model server. - Change the ownership of the copied model files and grant read permissions to the root group to ensure that the model server can access the files. OpenShift runs containers with a random user ID and the root group ID.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Specify a base image that provides a shell. In the following example,
Use
podman buildcommands to create the OCI container image and upload it to a registry. The following commands use Quay as the registry.NoteIf your repository is private, ensure that you are authenticated to the registry before uploading your container image.
podman build --format=oci -t quay.io/<user_name>/<repository_name>:<tag_name> . podman push quay.io/<user_name>/<repository_name>:<tag_name>
podman build --format=oci -t quay.io/<user_name>/<repository_name>:<tag_name> . podman push quay.io/<user_name>/<repository_name>:<tag_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.3. Uploading model files to a Persistent Volume Claim (PVC) Copy linkLink copied to clipboard!
When deploying a model, you can serve it from a preexisting Persistent Volume Claim (PVC) where your model files are stored. You can upload your local model files to a PVC in the IDE that you access from a running workbench.
Prerequisites
- You have access to the OpenShift AI dashboard.
- You have access to a project that has a running workbench.
- You have created a persistent volume claim (PVC) with a context type of Model storage.
The workbench is attached to the persistent volume (PVC).
- For instructions on attaching a PVC, see Creating a project workbench.
- You have the model files saved on your local machine.
Procedure
Follow these steps to upload your model files to the PVC mount point (/opt/app-root/src/) within your workbench:
-
From the OpenShift AI dashboard, click the open icon (
) to open your IDE in a new window.
In your IDE, navigate to the File Browser pane on the left-hand side.
- In JupyterLab, this is usually labeled Files.
- In code-server, this is usually the Explorer view.
In the file browser, navigate to the
/opt/app-root/src/folder. This folder represents the root of your attached PVC.NoteAny files or folders that you create or upload to this folder persist in the PVC.
Optional: Create a new folder to organize your models:
-
In the file browser, right-click within the
/opt/app-root/src/folder in the file browser and select New Folder. -
Name the folder (for example,
models). -
Double-click the new
modelsfolder to enter it.
-
In the file browser, right-click within the
Upload your model files to the current folder (
/opt/app-root/src/or/opt/app-root/src/models/):Using JupyterLab:
-
Click the Upload Files icon (
) in the file browser toolbar above the folder listing.
- In the file selection dialog, navigate to and select the model files from your local computer. Click Open.
- Wait for the upload progress bars next to the filenames to complete.
-
Click the Upload Files icon (
Using code-server:
- Drag the model files directly from your local file explorer and drop them into the file browser pane in the target folder within code-server.
- Wait for the upload process to complete.
Verification
- Confirm that your files appear in the file browser at the path where you uploaded them.
Next steps
When you follow the procedure to deploy a model, you can access the model files from the specified path within your PVC:
- In the Deploy model dialog, select Existing cluster storage under the Source model location section.
- From the Cluster storage list, select the PVC associated with your workbench.
- In the Model path field, enter the path to your model or the folder containing your model.