OCI 準拠のモデルコンテナーの推論サービング言語モデル


Red Hat AI Inference Server 3.2

Red Hat AI Inference Server における OCI 準拠モデルの推論

Red Hat AI Documentation Team

概要

OCI コンテナーマウントを使用して、完全にサポートされた GPU アクセラレーションパスで、言語モデルをローカルレジストリーまたはパブリックレジストリーから OpenShift クラスターに移動します。

はじめに

Red Hat AI Inference Server で OCI 準拠モデルの推論を実行できます。言語モデルの S3 または URI ベースのストレージの代替手段として、OCI 準拠のモデルコンテナー (modelcars) にモデルを保存します。

modelcar コンテナーを使用すると、繰り返しダウンロードを回避することで起動時間が短縮され、ディスク使用量が削減され、事前に取得したイメージを使用することでパフォーマンスが向上します。クラスター内の modelcar に言語モデルをデプロイする前に、モデルを OCI コンテナーイメージにパッケージ化し、そのコンテナーイメージをクラスターにデプロイする必要があります。

第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

第2章 OpenShift Container Platform の AI Inference Server を使用した推論サービング modelcar イメージ

シークレット、永続ストレージ、および Red Hat AI Inference Server を使用して modelcar コンテナーイメージを推論するデプロイメントカスタムリソース (CR) を設定して、OpenShift Container Platform を使用して modelcar コンテナーに言語モデルをデプロイします。

前提条件

  • OpenShift CLI (oc) がインストールされている。
  • cluster-admin 権限を持つユーザーとしてログインしている。
  • 基盤となる AI アクセラレーターハードウェアに NFD と必要な GPU Operator がインストールされている。
  • 言語モデル用の modelcar コンテナーイメージを作成し、コンテナーイメージレジストリーにプッシュした。

手順

  1. Red Hat AI Inference Server イメージをデプロイした場所と一致するようにクラスター namespace を設定します。以下に例を示します。

    $ NAMESPACE=rhaiis-namespace
    Copy to Clipboard Toggle word wrap
    1. PersistentVolumeClaim (PVC) カスタムリソース (CR) を作成し、クラスターに適用します。次の PVC CR の例では、デフォルトの IBM VPC ブロック永続ボリュームを使用します。

      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: model-cache
        namespace: rhaiis-namespace
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 20Gi
        storageClassName: ibmc-vpc-block-10iops-tier
      Copy to Clipboard Toggle word wrap
      注記

      要件を満たすようにクラスターストレージを設定することは、この手順の範囲外です。詳細は、永続ストレージの設定 を参照してください。

    2. modelcar イメージをプルし、Red Hat AI Inference Server コンテナーをデプロイする Deployment カスタムリソース (CR) を作成します。AI Inference Server を使用して modelcar イメージをサービングする次の Deployment CR 例を参照してください。

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: rhaiis-oci-deploy
        namespace: rhaiis-namespace
        labels:
          app: granite
      spec:
        replicas: 0
        selector:
          matchLabels:
            app: rhaiis-oci-deploy
        template:
          metadata:
            labels:
              app: rhaiis-oci-deploy
          spec:
            imagePullSecrets:
              - name: docker-secret
            volumes:
              - name: model-volume
                persistentVolumeClaim:
                  claimName: model-cache 
      1
      
              - name: shm
                emptyDir:
                  medium: Memory
                  sizeLimit: "2Gi"
              - name: oci-auth
                secret:
                  secretName: docker-secret
                  items:
                    - key: .dockercfg
                      path: config.json
            initContainers: 
      2
      
              - name: fetch-model
                image: ghcr.io/oras-project/oras:v1.2.0
                command: ["/bin/sh","-c"]
                args:
                  - |
                    set -e
                    # Only pull if /model is empty
                    if [ -z "$(ls -A /model)" ]; then
                      echo "Pulling model…"
                      oras pull <your_modelcar_registry_url> \ 
      3
      
                        --output /model \
                    else
                      echo "Model already present, skipping pull"
                    fi
                volumeMounts:
                  - name: model-volume
                    mountPath: /model
                  - name: oci-auth
                    mountPath: /auth
                    readOnly: true
            containers:
              - name: granite
                image: 'registry.redhat.io/rhaiis/vllm-cuda-rhel9@sha256:a6645a8e8d7928dce59542c362caf11eca94bb1b427390e78f0f8a87912041cd'
                imagePullPolicy: IfNotPresent
                env:
                  - name: VLLM_SERVER_DEV_MODE
                    value: '1'
                command:
                  - python
                  - '-m'
                  - vllm.entrypoints.openai.api_server
                args:
                  - '--port=8000'
                  - '--model=/model'
                  - '--served-model-name=ibm-granite/granite-3.1-2b-instruct' 
      4
      
                  - '--tensor-parallel-size=1'
                resources:
                  limits:
                    cpu: '10'
                    nvidia.com/gpu: '1'
                    memory: 16Gi
                  requests:
                    cpu: '2'
                    memory: 6Gi
                    nvidia.com/gpu: '1'
                volumeMounts:
                  - name: model-volume
                    mountPath: /model
                  - name: shm
                    mountPath: /dev/shm 
      5
      
            restartPolicy: Always
      Copy to Clipboard Toggle word wrap
      1
      spec.template.spec.volumes.persistentVolumeClaim.claimName は、作成した PVC の名前と一致する必要があります。
      2
      このサンプルデプロイメントでは、メインのアプリケーションコンテナーの前に実行され、必要な modelcar イメージをダウンロードする単純な initContainers 設定を使用します。たとえば、以前のデプロイメントからモデルディレクトリーがすでに設定されている場合は、モデルプルのステップはスキップされます。
      3
      推論する modelcar イメージのイメージレジストリー URL。
      4
      デプロイするモデルに合わせて --served-model-name の値を更新します。
      5
      NVIDIA Collective Communications Library (NCCL) では、/dev/shm ボリュームマウントが必要です。/dev/shm ボリュームマウントが設定されていない場合、Tensor 並列 vLLM デプロイメントは失敗します。
      1. デプロイメントのレプリカ数を必要な数まで増やします。たとえば、以下のコマンドを実行します。

        oc scale deployment granite -n rhaiis-namespace --replicas=1
        Copy to Clipboard Toggle word wrap
      2. オプション: デプロイメントを監視し、成功したことを確認します。

        $ oc get deployment -n rhaiis-namespace --watch
        Copy to Clipboard Toggle word wrap

        出力例

        NAME                READY   UP-TO-DATE   AVAILABLE   AGE
        rhaiis-oci-deploy   0/1     1            0           2s
        rhaiis-oci-deploy   1/1     1            1           14s
        Copy to Clipboard Toggle word wrap

    3. モデル推論用の Service CR を作成します。以下に例を示します。

      apiVersion: v1
      kind: Service
      metadata:
        name: rhaiis-oci-deploy
        namespace: rhaiis-namespace
      spec:
        selector:
          app: rhaiis-oci-deploy
        ports:
          - name: http
            port: 80
            targetPort: 8000
      Copy to Clipboard Toggle word wrap
    4. オプション: モデルへのパブリックアクセスを有効にするには、Route CR を作成します。以下に例を示します。

      apiVersion: route.openshift.io/v1
      kind: Route
      metadata:
        name: rhaiis-oci-deploy
        namespace: rhaiis-namespace
      spec:
        to:
          kind: Service
          name: rhaiis-oci-deploy
        port:
          targetPort: http
      Copy to Clipboard Toggle word wrap
    5. 公開されたルートの URL を取得します。以下のコマンドを実行します。

      $ oc get route granite -n rhaiis-namespace -o jsonpath='{.spec.host}'
      Copy to Clipboard Toggle word wrap

      出力例

      rhaiis-oci-deploy-rhaiis-namespace.apps.example.com
      Copy to Clipboard Toggle word wrap

検証

モデルをクエリーして、デプロイメントが成功したことを確認します。以下のコマンドを実行します。

curl -v -k   http://rhaiis-oci-deploy-rhaiis-namespace.apps.modelsibm.ibmmodel.rh-ods.com/v1/chat/completions   -H "Content-Type: application/json"   -d '{
    "model":"ibm-granite/granite-3.1-2b-instruct",
    "messages":[{"role":"user","content":"Hello?"}],
    "temperature":0.1
  }'| jq
Copy to Clipboard Toggle word wrap

出力例

{
  "id": "chatcmpl-07b177360eaa40a3b311c24a8e3c7f43",
  "object": "chat.completion",
  "created": 1755189746,
  "model": "ibm-granite/granite-3.1-2b-instruct",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "reasoning_content": null,
        "content": "Hello! How can I assist you today?",
        "tool_calls": []
      },
      "logprobs": null,
      "finish_reason": "stop",
      "stop_reason": null
    }
  ],
  "usage": {
    "prompt_tokens": 61,
    "total_tokens": 71,
    "completion_tokens": 10,
    "prompt_tokens_details": null
  },
  "prompt_logprobs": null,
  "kv_transfer_params": null
}
Copy to Clipboard Toggle word wrap

法律上の通知

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

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

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

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

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

会社概要

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

Theme

© 2025 Red Hat