Este contenido no está disponible en el idioma seleccionado.
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_hubCreate a model downloader Python script:
vi download_model.pyAdd the following content to the
download_model.pyfile, adjusting the value formodel_repoas required:from huggingface_hub import snapshot_download # Specify the Hugging Face repository containing the model model_repo = "ibm-granite/granite-3.1-2b-instruct" snapshot_download( repo_id=model_repo, local_dir="/models", allow_patterns=["*.safetensors", "*.json", "*.txt"], )Create a
Dockerfilefor the modelcar:FROM registry.access.redhat.com/ubi9/python-311:latest as base USER root RUN pip install huggingface-hub # Download the model file from Hugging Face COPY download_model.py . RUN python download_model.py # Final image containing only the essential model files FROM registry.access.redhat.com/ubi9/ubi-micro:9.4 # Copy the model files from the base container COPY --from=base /models /models USER 1001Build the modelcar image:
podman build . -t modelcar-example:latest --platform linux/amd64Example output
Successfully tagged localhost/modelcar-example:latestPush the modelcar image to the container registry. For example:
$ podman push modelcar-example:latest quay.io/<your_model_registry>/modelcar-example:latestExample output
Getting image source signatures Copying blob b2ed7134f853 done Copying config 4afd393610 done Writing manifest to image destination Storing signatures