第1章 modelcar イメージを作成し、コンテナーイメージレジストリーにプッシュする


Red Hat AI Inference Server でデプロイできる言語モデルを含む modelcar イメージを作成できます。

modelcar イメージを作成するには、Hugging Face からモデルをダウンロードしてコンテナーイメージにパッケージ化して、modelcar コンテナーをイメージレジストリーにプッシュします。

前提条件

  • Python 3.11 以降がインストールされている。
  • Podman または Docker がインストールされている。
  • Hugging Face からモデルをダウンロードするには、インターネットにアクセスできる。
  • イメージをプッシュできるコンテナーイメージレジストリーを設定してログインした。

手順

  1. Python 仮想環境を作成し、huggingface_hub Python ライブラリーをインストールします。

    python3 -m venv venv && \
    source venv/bin/activate && \
    pip install --upgrade pip && \
    pip install huggingface_hub
    Copy to Clipboard Toggle word wrap
  2. モデルダウンローダーの Python スクリプトを作成します。

    vi download_model.py
    Copy to Clipboard Toggle word wrap
  3. 必要に応じて model_repo の値を調整し、download_model.py ファイルに次のコンテンツを追加します。

    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"],
    )
    Copy to Clipboard Toggle word wrap
  4. modelcar 用の Dockerfile を作成します。

    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 1001
    Copy to Clipboard Toggle word wrap
  5. modelcar イメージをビルドします。

    podman build . -t modelcar-example:latest --platform linux/amd64
    Copy to Clipboard Toggle word wrap

    出力例

    Successfully tagged localhost/modelcar-example:latest
    Copy to Clipboard Toggle word wrap

  6. modelcar イメージをコンテナーレジストリーにプッシュします。以下に例を示します。

    $ podman push modelcar-example:latest quay.io/<your_model_registry>/modelcar-example:latest
    Copy to Clipboard Toggle word wrap

    出力例

    Getting image source signatures
    Copying blob b2ed7134f853 done
    Copying config 4afd393610 done
    Writing manifest to image destination
    Storing signatures
    Copy to Clipboard Toggle word wrap

トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat