第1章 modelcar イメージを作成し、コンテナーイメージレジストリーにプッシュする
Red Hat AI Inference Server でデプロイできる言語モデルを含む modelcar イメージを作成できます。
modelcar イメージを作成するには、Hugging Face からモデルをダウンロードしてコンテナーイメージにパッケージ化して、modelcar コンテナーをイメージレジストリーにプッシュします。
前提条件
- Python 3.11 以降がインストールされている。
- Podman または Docker がインストールされている。
- Hugging Face からモデルをダウンロードするには、インターネットにアクセスできる。
- イメージをプッシュできるコンテナーイメージレジストリーを設定してログインした。
手順
Python 仮想環境を作成し、
huggingface_hubPython ライブラリーをインストールします。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 モデルダウンローダーの Python スクリプトを作成します。
vi download_model.py
vi download_model.pyCopy to Clipboard Copied! Toggle word wrap Toggle overflow 必要に応じて
model_repoの値を調整し、download_model.pyファイルに次のコンテンツを追加します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow modelcar 用の
Dockerfileを作成します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow modelcar イメージをビルドします。
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 出力例
Successfully tagged localhost/modelcar-example:latest
Successfully tagged localhost/modelcar-example:latestCopy to Clipboard Copied! Toggle word wrap Toggle overflow modelcar イメージをコンテナーレジストリーにプッシュします。以下に例を示します。
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 出力例
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