Chapter 2. Creating a modelcar image and pushing it to a container image registry
You can create a modelcar image that contains a language model that you can deploy with Red Hat AI Inference Server.
To create a modelcar image, download the model from Hugging Face and then package it into a container image and push the modelcar container to an image registry.
Prerequisites
- You have installed Python 3.11 or later.
- You have installed Podman or Docker.
- You have access to the internet to download models from Hugging Face.
- You have configured a container image registry that you can push images to and have logged in.
Procedure
Create a Python virtual environment and install the
huggingface_hubPython library:python3 -m venv venv && \ source venv/bin/activate && \ pip install --upgrade pip && \ pip install huggingface_hub
python3 -m venv venv && \ source venv/bin/activate && \ pip install --upgrade pip && \ pip install huggingface_hubCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create a model downloader Python script:
vi download_model.py
vi download_model.pyCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following content to the
download_model.pyfile, adjusting the value formodel_repoas required:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a
Dockerfilefor the modelcar:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build the modelcar image:
podman build . -t modelcar-example:latest --platform linux/amd64
podman build . -t modelcar-example:latest --platform linux/amd64Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Successfully tagged localhost/modelcar-example:latest
Successfully tagged localhost/modelcar-example:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Push the modelcar image to the container registry. For example:
podman push modelcar-example:latest quay.io/<your_model_registry>/modelcar-example:latest
$ podman push modelcar-example:latest quay.io/<your_model_registry>/modelcar-example:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Getting image source signatures Copying blob b2ed7134f853 done Copying config 4afd393610 done Writing manifest to image destination Storing signatures
Getting image source signatures Copying blob b2ed7134f853 done Copying config 4afd393610 done Writing manifest to image destination Storing signaturesCopy to Clipboard Copied! Toggle word wrap Toggle overflow