GPU を使用して vLLM フレームワークで Google Kubernetes Engine(GKE)に Gemma 4 大規模言語モデル(LLM)をサービングするには、NVIDIA B200、H100、RTX Pro 6000、L4 GPU などのサポートされているアクセラレータを使用して GKE クラスタをプロビジョニングする必要があります。
Gemma 4 モデルの重みを取得するには、Hugging Face リポジトリからダウンロードするように事前構築済みの vLLM コンテナを構成します。また、コンテナは、Google Cloud Managed Lustre インスタンスに Cloud Storage モデルバケットをキャッシュに保存するなどして、既存の永続ストレージからモデルの重みを読み込むこともできます。
重みが読み込まれると、vLLM コンテナは高スループット推論用の OpenAI 互換 API エンドポイントを公開します。
このチュートリアルは、ML エンジニア、プラットフォームの管理者とオペレーターのほか、Kubernetes のコンテナ オーケストレーション機能を使用して H200、H100、A100、L4 GPU ハードウェアで AI / ML ワークロードをサービングすることに関心があるデータと AI のスペシャリストを対象としています。 Google Cloud のコンテンツで使用されている一般的なロールとタスクの例の詳細については、一般的な GKE ユーザーのロールとタスクをご覧ください。
ML モデルを費用対効果の高い方法で迅速に構築してサービングする目的で設計された統合マネージド AI プラットフォームが必要な場合は、Vertex AI デプロイ ソリューションをお試しになることをおすすめします。
このページを読む前に、次のことをよく理解しておいてください。
背景
このセクションでは、このガイドで使用されている重要なテクノロジーについて説明します。
GPU
GPU を使用すると、ノードで実行される特定のワークロード(ML やデータ処理など)を高速化できます。GKE では、NVIDIA H200、H100、L4、A100 GPU を搭載したマシンタイプをはじめとする、さまざまなマシンタイプ オプションをノード構成に使用できます。
vLLM
vLLM は、GPU のサービング スループットを向上できる、高度に最適化されたオープンソースの LLM サービング フレームワークであり、次のような機能を備えています。
- PagedAttention による Transformer の実装の最適化
- サービング スループットを全体的に向上させる連続的なバッチ処理
- 複数の GPU でのテンソル並列処理と分散サービング
詳細については、vLLM のドキュメントをご覧ください。
目標
このチュートリアルでは、マネージド Kubernetes 環境における推論用 LLM の実用的なデプロイに関する基礎を学ぶことができます。
- Autopilot モードまたは Standard モードの GKE クラスタで環境を準備する。
- vLLM コンテナをクラスタにデプロイする。
- vLLM を使用し、curl とウェブチャット インターフェースを介して Gemma 4 モデルをサービングする。
始める前に
- Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the required API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
プロジェクトに次のロール(複数の場合あり)が割り当てられていることを確認します。 roles/container.admin、roles/iam.serviceAccountAdmin
ロールを確認する
-
Google Cloud コンソールで、[IAM] ページに移動します。
IAM に移動 - プロジェクトを選択します。
-
[プリンシパル] 列で、自分または自分が所属するグループの行をすべて確認します。所属するグループについては、管理者にお問い合わせください。
- 自分のメールアドレスを含む行の [ロール] 列で、ロールのリストに必要なロールが含まれているかどうか確認します。
ロールを付与する
-
Google Cloud コンソールで、[IAM] ページに移動します。
IAM に移動 - プロジェクトを選択します。
- [ アクセスを許可] をクリックします。
-
[新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。
- [ロールを選択] をクリックし、ロールを検索します。
- 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
- [保存] をクリックします。
-
- L4 GPU 用にプロジェクトに十分な割り当てがあることを確認します。詳細については、GPU についてと数量に基づく割り当てをご覧ください。
環境を準備する
このチュートリアルでは、Cloud Shell を使用してGoogle Cloudでホストされているリソースを管理します。Cloud Shell には、このチュートリアルに必要な kubectl や gcloud CLI などのソフトウェアがプリインストールされています。
Cloud Shell を使用して環境を設定するには、次の操作を行います。
Google Cloud コンソールで
(Cloud Shell をアクティブにする)をクリックして、Google Cloud コンソールで Cloud Shell セッションを起動します。これにより、 Google Cloud コンソールの下部ペインでセッションが起動します。
デフォルトの環境変数を設定します。
gcloud config set project PROJECT_ID gcloud config set billing/quota_project PROJECT_ID export PROJECT_ID=$(gcloud config get project) export REGION=REGION export ZONE=ZONE export CLUSTER_NAME=CLUSTER_NAME次の値を置き換えます。
PROJECT_ID: Google Cloudのプロジェクト ID。REGION: 使用するアクセラレータ タイプをサポートするリージョン(たとえば、L4 GPU の場合はus-central1)。どのリージョンでどの GPU が使用可能かを確認できます。ZONE: 使用するアクセラレータ タイプをサポートするゾーン(たとえば、RTX PRO 6000 GPU の場合はus-central1-bとus-central1-f)。どのゾーンでどの GPU を使用できるかを確認できます。CLUSTER_NAME: クラスタの名前。
Google Cloud リソースを作成して構成する
次の手順で、必要なリソースを作成します。
GKE クラスタとノードプールを作成する
GKE Autopilot クラスタまたは GKE Standard クラスタの GPU で Gemma を提供できます。フルマネージドの Kubernetes エクスペリエンスを実現するには、Autopilot クラスタを使用することをおすすめします。ワークロードに最適な GKE の運用モードを選択するには、GKE の運用モードを選択するをご覧ください。
Autopilot
Cloud Shell で、次のコマンドを実行します。
gcloud container clusters create-auto CLUSTER_NAME \
--project=PROJECT_ID \
--location=CONTROL_PLANE_LOCATION \
--release-channel=rapid
次の値を置き換えます。
PROJECT_ID: Google Cloudのプロジェクト ID。CONTROL_PLANE_LOCATION: クラスタのコントロール プレーンの Compute Engine の リージョン。使用するアクセラレータ タイプをサポートするリージョンを指定します(たとえば、L4 GPU の場合はus-central1)。CLUSTER_NAME: クラスタの名前。
GKE は、デプロイされたワークロードからのリクエストに応じた CPU ノードと GPU ノードを持つ Autopilot クラスタを作成します。
Standard
Cloud Shell で、次のコマンドを実行して Standard クラスタを作成します。
gcloud container clusters create CLUSTER_NAME \ --project=PROJECT_ID \ --location=CONTROL_PLANE_LOCATION \ --workload-pool=PROJECT_ID.svc.id.goog \ --release-channel=rapid \ --num-nodes=1次の値を置き換えます。
PROJECT_ID: Google Cloudのプロジェクト ID。CONTROL_PLANE_LOCATION: クラスタのコントロール プレーンの Compute Engine の リージョン。使用するアクセラレータ タイプをサポートするリージョンを指定します(たとえば、L4 GPU の場合はus-central1)。CLUSTER_NAME: クラスタの名前。
クラスタの作成には数分かかることもあります。
クラスタ用のノードプールを適切なディスクサイズで作成するため、次のコマンドを実行します。
gcloud container node-pools create gpupool \ --accelerator type=nvidia-rtx-pro-6000,count=1,gpu-driver-version=latest \ --project=PROJECT_ID \ --location=REGION \ --node-locations=ZONE \ --cluster=CLUSTER_NAME \ --machine-type=g4-standard-48 \ --num-nodes=1GKE は、RTX PRO を含む単一のノードプールを作成します。各ノードに 6,000 個の GPU。
Hugging Face の重みを使用して vLLM に Gemma 4 モデルをデプロイする
Hugging Face の重みを使用して Gemma 4 モデルをデプロイするには、選択したモデルサイズの Kubernetes Deployment マニフェストを適用します。Deployment は、クラスタ内のノードに分散された Pod の複数のレプリカを実行できる Kubernetes API オブジェクトです。
手順
このマニフェストを適用すると、vLLM コンテナ イメージが pull され、NVIDIA GPU がリクエストされ、Hugging Face から重みが自動的にダウンロードされて vLLM 推論エンジンが起動します。
Gemma 4 E2B-it
Gemma 4 E2B の指示チューニング済みモデル(テキストのみの入力)をデプロイする手順は次のとおりです。
次の
vllm-4-e2b-it.yamlマニフェストを作成します。apiVersion: apps/v1 kind: Deployment metadata: name: vllm-gemma-deployment spec: replicas: 1 selector: matchLabels: app: gemma-server template: metadata: labels: app: gemma-server ai.gke.io/model: gemma-4-e2b-it ai.gke.io/inference-server: vllm examples.ai.gke.io/source: user-guide spec: containers: - name: inference-server image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4 resources: requests: cpu: "2" memory: "10Gi" ephemeral-storage: "10Gi" nvidia.com/gpu: "1" limits: cpu: "2" memory: "10Gi" ephemeral-storage: "10Gi" nvidia.com/gpu: "1" command: ["python3", "-m", "vllm.entrypoints.api_server"] args: - --model=$(MODEL_ID) - --host=0.0.0.0 - --port=8000 - --tensor-parallel-size=1 - --enable-log-requests - --enable-chunked-prefill - --enable-prefix-caching - --enable-auto-tool-choice - --generation-config=auto - --tool-call-parser=gemma4 - --dtype=bfloat16 - --max-num-seqs=16 - --max-model-len=32768 - --gpu-memory-utilization=0.95 - --reasoning-parser=gemma4 - --trust-remote-code env: - name: LD_LIBRARY_PATH value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64 - name: MODEL_ID value: google/gemma-4-E2B-it volumeMounts: - mountPath: /dev/shm name: dshm volumes: - name: dshm emptyDir: medium: Memory nodeSelector: cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000 cloud.google.com/gke-gpu-driver-version: latest --- apiVersion: v1 kind: Service metadata: name: llm-service spec: selector: app: gemma-server type: ClusterIP ports: - protocol: TCP port: 8000 targetPort: 8000次のようにマニフェストを適用します。
kubectl apply -f vllm-4-e2b-it.yaml
Gemma 4 E4B-it
次の手順に沿って、Gemma 4 E4B 指示用にチューニングされたモデルをデプロイします。
次の
vllm-4-e4b-it.yamlマニフェストを作成します。apiVersion: apps/v1 kind: Deployment metadata: name: vllm-gemma-deployment spec: replicas: 1 selector: matchLabels: app: gemma-server template: metadata: labels: app: gemma-server ai.gke.io/model: gemma-4-e4b-it ai.gke.io/inference-server: vllm examples.ai.gke.io/source: user-guide spec: containers: - name: inference-server image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4 resources: requests: cpu: "4" memory: "20Gi" ephemeral-storage: "20Gi" nvidia.com/gpu: "1" limits: cpu: "4" memory: "20Gi" ephemeral-storage: "20Gi" nvidia.com/gpu: "1" command: ["python3", "-m", "vllm.entrypoints.api_server"] args: - --model=$(MODEL_ID) - --host=0.0.0.0 - --port=8000 - --tensor-parallel-size=1 - --enable-log-requests - --enable-chunked-prefill - --enable-prefix-caching - --enable-auto-tool-choice - --generation-config=auto - --tool-call-parser=gemma4 - --dtype=bfloat16 - --max-num-seqs=16 - --max-model-len=32768 - --gpu-memory-utilization=0.95 - --reasoning-parser=gemma4 - --trust-remote-code env: - name: LD_LIBRARY_PATH value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64 - name: MODEL_ID value: google/gemma-4-E4b-it volumeMounts: - mountPath: /dev/shm name: dshm volumes: - name: dshm emptyDir: medium: Memory nodeSelector: cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000 cloud.google.com/gke-gpu-driver-version: latest --- apiVersion: v1 kind: Service metadata: name: llm-service spec: selector: app: gemma-server type: ClusterIP ports: - protocol: TCP port: 8000 targetPort: 8000次のようにマニフェストを適用します。
kubectl apply -f vllm-4-E4b-it.yamlこの例では、vLLM オプション
--max-model-len=32768を使用してコンテキスト ウィンドウを 32K に制限しています。コンテキスト ウィンドウのサイズを大きくする場合(最大 128K)は、マニフェストとノードプールの構成を調整して GPU 容量を増やします。
Gemma 4 26B-A4B-it
次の手順に沿って、Gemma 4 26B-A4B 指示チューニング済みモデルをデプロイします。
次の
vllm-4-26b-a4b-it.yamlマニフェストを作成します。apiVersion: apps/v1 kind: Deployment metadata: name: vllm-gemma-deployment spec: replicas: 1 selector: matchLabels: app: gemma-server template: metadata: labels: app: gemma-server ai.gke.io/model: gemma-4-26b-a4b-it ai.gke.io/inference-server: vllm examples.ai.gke.io/source: user-guide spec: containers: - name: inference-server image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4 resources: requests: cpu: "20" memory: "80Gi" ephemeral-storage: "80Gi" nvidia.com/gpu: "1" limits: cpu: "20" memory: "80Gi" ephemeral-storage: "80Gi" nvidia.com/gpu: "1" command: ["python3", "-m", "vllm.entrypoints.api_server"] args: - --model=$(MODEL_ID) - --host=0.0.0.0 - --port=8000 - --tensor-parallel-size=1 - --enable-log-requests - --enable-chunked-prefill - --enable-prefix-caching - --enable-auto-tool-choice - --generation-config=auto - --tool-call-parser=gemma4 - --dtype=bfloat16 - --max-num-seqs=16 - --max-model-len=16384 - --gpu-memory-utilization=0.95 - --reasoning-parser=gemma4 - --trust-remote-code env: - name: LD_LIBRARY_PATH value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64 - name: MODEL_ID value: google/gemma-4-26B-A4B-it volumeMounts: - mountPath: /dev/shm name: dshm volumes: - name: dshm emptyDir: medium: Memory nodeSelector: cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000 cloud.google.com/gke-gpu-driver-version: latest --- apiVersion: v1 kind: Service metadata: name: llm-service spec: selector: app: gemma-server type: ClusterIP ports: - protocol: TCP port: 8000 targetPort: 8000次のようにマニフェストを適用します。
kubectl apply -f vllm-4-26b-a4b-it.yamlこの例では、vLLM オプション
--max-model-len=16384を使用してコンテキスト ウィンドウを 16K に制限しています。コンテキスト ウィンドウのサイズを大きくする場合(最大 128K)は、マニフェストとノードプールの構成を調整して GPU 容量を増やします。
Gemma 4 31B-it
次の手順に沿って、Gemma 4 31B 指示チューニング済みモデルをデプロイします。
次の
vllm-4-31b-it.yamlマニフェストを作成します。apiVersion: apps/v1 kind: Deployment metadata: name: vllm-gemma-deployment spec: replicas: 1 selector: matchLabels: app: gemma-server template: metadata: labels: app: gemma-server ai.gke.io/model: gemma-4-31b-it ai.gke.io/inference-server: vllm examples.ai.gke.io/source: user-guide spec: containers: - name: inference-server image: us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:gemma4 resources: requests: cpu: "22" memory: "100Gi" ephemeral-storage: "80Gi" nvidia.com/gpu: "1" limits: cpu: "22" memory: "100Gi" ephemeral-storage: "80Gi" nvidia.com/gpu: "1" command: ["python3", "-m", "vllm.entrypoints.api_server"] args: - --model=$(MODEL_ID) - --host=0.0.0.0 - --port=8000 - --tensor-parallel-size=1 - --enable-log-requests - --enable-chunked-prefill - --enable-prefix-caching - --enable-auto-tool-choice - --generation-config=auto - --tool-call-parser=gemma4 - --dtype=bfloat16 - --max-num-seqs=16 - --max-model-len=16384 - --gpu-memory-utilization=0.95 - --reasoning-parser=gemma4 - --trust-remote-code env: - name: LD_LIBRARY_PATH value: ${LD_LIBRARY_PATH}:/usr/local/nvidia/lib64 - name: MODEL_ID value: google/gemma-4-31B-it volumeMounts: - mountPath: /dev/shm name: dshm volumes: - name: dshm emptyDir: medium: Memory nodeSelector: cloud.google.com/gke-accelerator: nvidia-rtx-pro-6000 cloud.google.com/gke-gpu-driver-version: latest --- apiVersion: v1 kind: Service metadata: name: llm-service spec: selector: app: gemma-server type: ClusterIP ports: - protocol: TCP port: 8000 targetPort: 8000次のようにマニフェストを適用します。
kubectl apply -f vllm-4-31b-it.yamlこの例では、vLLM オプション
--max-model-len=16384を使用してコンテキスト ウィンドウを 16K に制限しています。コンテキスト ウィンドウのサイズを大きくする場合(最大 128K)は、マニフェストとノードプールの構成を調整して GPU 容量を増やします。
検証
Deployment が利用可能になるまで待ちます。
kubectl wait --for=condition=Available --timeout=1800s deployment/vllm-gemma-deployment実行中の Deployment のログを表示します。
kubectl logs -f -l app=gemma-serverDeployment リソースによって Gemma モデルデータがダウンロードされます。この処理には数分かかることがあります。出力は次のようになります。
... ... (APIServer pid=1) INFO: Started server process [1] (APIServer pid=1) INFO: Waiting for application startup. (APIServer pid=1) INFO: Application startup complete.
Hugging Face デプロイが使用可能になったら、モデルを操作するためにポート転送を設定します。
Managed Lustre からファインチューニングされた Gemma をデプロイする
Google Cloud Managed Lustre インスタンスにすでに保存されているファインチューニング済み Gemma モデル(Gemma 3 27B など)をサービングするには、対応する PersistentVolumeClaim(PVC)を vLLM コンテナにマウントする必要があります。
前提条件
Lustre インスタンスに接続する既存の PVC が GKE クラスタにあることを確認します。この例では、PVC の名前は gemma-lustre-pvc です。
既存のインスタンスの PVC と PersistentVolume(PV)を作成する方法については、既存の Managed Lustre インスタンスにアクセスするをご覧ください。
手順
次の YAML マニフェストを
vllm-lustre-gemma.yamlとして保存します。この例では、Deployment は Lustre PVC を/dataにマウントし、そのローカルパスからモデルの重みを読み込むように vLLM に指示します。apiVersion: apps/v1 kind: Deployment metadata: name: vllm-gemma-lustre spec: replicas: 1 selector: matchLabels: app: gemma-server template: metadata: labels: app: gemma-server spec: containers: - name: vllm image: vllm/vllm-openai:latest command: ["python3", "-m", "vllm.entrypoints.openai.api_server"] args: - --model=/data/gemma-3-27b - --tensor-parallel-size=1 resources: limits: nvidia.com/gpu: "1" volumeMounts: - name: model-weights mountPath: /data volumes: - name: model-weights persistentVolumeClaim: claimName: gemma-lustre-pvc nodeSelector: cloud.google.com/gke-accelerator: nvidia-l4 cloud.google.com/gke-gpu-driver-version: latestマニフェストを GKE クラスタに適用します。
kubectl apply -f vllm-lustre-gemma.yaml
検証
Lustre ボリュームからモデルが正常に読み込まれたことを確認するには、vLLM 起動シーケンスの Pod ログを確認します。
kubectl logs -l app=gemma-server
モデルをサービングする
このセクションでは、モデルを操作します。モデルが完全にダウンロードされたことを確認してから、次に進んでください。
ポート転送をセットアップする
次のコマンドを実行して、モデルへのポート転送を設定します。
kubectl port-forward service/llm-service 8000:8000
出力は次のようになります。
Forwarding from 127.0.0.1:8000 -> 8000
curl を使用してモデルを操作する
このセクションでは、デプロイした Gemma 4 指示チューニング済みモデルを基本的なスモークテストによって検証する方法を説明します。他のモデルの場合は、gemma-4-e4b-it をモデル名に置き換えます。
この例では、Gemma 4 E4B の指示チューニング済みモデル(テキストのみの入力)をテストする方法を示します。
新しいターミナル セッションで、curl を使用してモデルとチャットします。
curl http://127.0.0.1:8000/v1/chat/completions \
-X POST \
-H "Content-Type: application/json" \
-d '{
"model": "google/gemma-4-26B-A4B-it",
"messages": [
{
"role": "user",
"content": "Why is the sky blue?"
}
],
"chat_template_kwargs": {
"enable_thinking": true
},
"skip_special_tokens": false
}'
出力は次のようになります。
{
"id": "chatcmpl-be75ccfcbdf753d1",
"object": "chat.completion",
"created": 1775006187,
"model": "google/gemma-4-26B-A4B-it",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The short answer is a phenomenon called **Rayleigh scattering**.\n\nTo understand how it works, you have to look at three things: sunlight, the Earth's atmosphere, and how light travels.\n\n### 1. Sunlight is a Rainbow\nAlthough sunlight looks white to us, it is actually made up of all the colors of the rainbow (red, orange, yellow, green, blue, indigo, and violet). Light travels as **waves**, and each color has a different wavelength:\n* **Red light** travels in long, lazy, wide waves.\n* **Blue and violet light** travel in short, choppy, tight waves.\n\n### 2. The Atmosphere is an Obstacle Course\nEarth's atmosphere is filled with gases (mostly nitrogen and oxygen). As sunlight travels through the atmosphere, it strikes the molecules of these gases. \n\nBecause the gas molecules are very small, they affect the colors differently based on their wavelength:\n* The **long waves** (reds and yellows) pass through the atmosphere mostly straight, without hitting much. They are like large ocean waves that roll right over small pebbles.\n* The **short waves** (blues and violets) strike the gas molecules and get scattered in every direction. They are like small ripples that hit a pebble and splash everywhere.\n\nBecause this blue light is being scattered in every direction by the air, when you look up, your eyes are catching that scattered blue light coming from every part of the sky.\n\n### 3. Why isn't the sky violet?\nIf violet light has an even shorter wavelength than blue light, you might wonder why the sky doesn't look purple. There are two main reasons:\n1. **The Sun's output:** The Sun emits much more blue light than violet light.\n2. **Human Biology:** Human eyes are much more sensitive to blue than to violet. Our eyes interpret the scatter of mixed blue and violet light simply as pale blue.\n\n---\n\n### Bonus: Why are sunsets red?\nWhen the sun is setting, it is much lower on the horizon. This means the sunlight has to travel through a much **thicker** layer of the atmosphere to reach your eyes. \n\nBy the time the light gets to you, the blue light has been scattered away completely로. Only the long-wavelength colors—the reds, oranges, and pinks—are able to make it through that thick layer of air without being scattered away, creating the beautiful colors of a sunset.",
"refusal": null,
"annotations": null,
"audio": null,
"function_call": null,
"tool_calls": [],
"reasoning": "\"Why is the sky blue?\"\nScience/Physics (Atmospheric scattering).\nExplain the phenomenon clearly, accurately, and engagingly.\n\n * Sunlight (white light) is made of a spectrum of colors (ROYGBIV).\n * Earth's atmosphere is filled with gases (nitrogen, oxygen) and particles.\n * Rayleigh Scattering: Shorter wavelengths (blue/violet) scatter more easily than longer wavelengths (red/yellow) when hitting small gas molecules.\n * The human eye's sensitivity: Why isn't it violet?\n\n A good scientific explanation should follow a logical flow:\n * *Direct Answer:* The core mechanism (Rayleigh Scattering).\n * *The Components:* Sunlight and the Atmosphere.\n * *The Mechanism:* How light interacts with gas molecules.\n * *The Wavelength Factor:* Comparing colors.\n * *The \"Wait, why not violet?\" question:* Addressing human perception.\n * *Bonus/Related concept:* Why sunsets are red.\n\n * Use the term **Rayleigh Scattering**.\n * Summarize: Its how sunlight interacts with the Earth's atmosphere.\n\n * Sunlight looks white, but it's actually a mix of all colors (the rainbow).\n * Each color travels as a different wavelength. Red = long/lazy waves; Blue/Violet = short/choppy waves.\n\n * The atmosphere is mostly Nitrogen and Oxygen.\n * When sunlight hits these tiny gas molecules, the light gets scattered in all directions.\n\n * Blue light travels in shorter, smaller waves.\n * Because these waves are small, they strike the gas molecules more frequently and get scattered more easily than the longer red/yellow waves.\n * Result: When you look up, your eyes are catching this \"scattered\" blue light coming from every direction.\n\n * *Technically*, violet light has an even shorter wavelength than blue, so it scatters *even more*. Why isn't the sky violet?\n * Two reasons: 1. The Sun emits more blue light than violet light. 2. Human eyes are much more sensitive to blue than violet.\n\n * Briefly mention sunsets to provide a complete picture.\n * At sunset, light travels through *more* atmosphere. The blue is scattered away completely, leaving only the long red/orange waves to reach your eyes.\n\n * *Tone Check:* Is it too academic? Use analogies (like waves in water or skipping stones) if needed, but keep it concise.\n * *Clarity:* Ensure the distinction between wavelength and scattering is clear."
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": 106,
"token_ids": null
}
],
"service_tier": null,
"system_fingerprint": null,
"usage": {
"prompt_tokens": 21,
"total_tokens": 1122,
"completion_tokens": 1101,
"prompt_tokens_details": null
},
"prompt_logprobs": null,
"prompt_token_ids": null,
"kv_transfer_params": null
}
(省略可)Gradio のチャット インターフェースでモデルを操作する
このセクションでは、指示チューニング済みモデルを操作できるウェブチャット アプリケーションを作成します。わかりやすくするため、このセクションでは 4B-it モデルを使用したテスト方法についてのみ説明します。
Gradio は、chatbot のユーザー インターフェースを作成する ChatInterface ラッパーを含む Python ライブラリです。
チャット インターフェースをデプロイする
Cloud Shell で、次のマニフェストを
gradio.yamlとして保存します。google/gemma-4-E4B-itは、デプロイで使用した Gemma 4 モデル名に変更します。apiVersion: apps/v1 kind: Deployment metadata: name: gradio labels: app: gradio spec: replicas: 1 selector: matchLabels: app: gradio template: metadata: labels: app: gradio spec: containers: - name: gradio image: us-docker.pkg.dev/google-samples/containers/gke/gradio-app:v1.0.7 resources: requests: cpu: "250m" memory: "512Mi" limits: cpu: "500m" memory: "512Mi" env: - name: CONTEXT_PATH value: "/v1/chat/completions" - name: HOST value: "http://llm-service:8000" - name: LLM_ENGINE value: "openai-chat" - name: MODEL_ID value: "google/gemma-4-E4B-it" - name: DISABLE_SYSTEM_MESSAGE value: "true" ports: - containerPort: 7860 --- apiVersion: v1 kind: Service metadata: name: gradio spec: selector: app: gradio ports: - protocol: TCP port: 8080 targetPort: 7860 type: ClusterIP次のようにマニフェストを適用します。
kubectl apply -f gradio.yamlDeployment が利用可能になるまで待ちます。
kubectl wait --for=condition=Available --timeout=900s deployment/gradioCloud Shell で、次のコマンドを実行します。
kubectl port-forward service/gradio 8080:8080これにより、Cloud Shell から Gradio サービスへのポート転送が作成されます。
Cloud Shell タスクバーの右上にある [
ウェブでプレビュー] ボタンをクリックします。[ポート 8080 でプレビュー] をクリックします。ブラウザで新しいタブが開きます。
Gradio のチャット インターフェースを使用して Gemma を操作します。プロンプトを追加して [送信] をクリックします。
Empty reply from serverというメッセージが表示された場合は、コンテナがモデルデータのダウンロードを完了していない可能性があります。モデルがサービス提供の準備ができていることを示すConnectedというメッセージがないか、再度 Pod のログを確認します。Connection refusedが表示された場合は、ポート転送が有効であることを確認します。Google Cloud コンソールで、[デプロイされるモデル] ページに移動します。
特定のデプロイの詳細(指標、ログ、ダッシュボードなど)を表示するには、リスト内のモデル名をクリックします。
モデルの詳細ページで、[オブザーバビリティ] タブをクリックして、次のダッシュボードを表示します。プロンプトが表示されたら、[有効にする] をクリックして、クラスタの指標収集を有効にします。
- [インフラストラクチャの使用量] ダッシュボードには、使用率の指標が表示されます。
- [DCGM] ダッシュボードには、DCGM 指標が表示されます。
- vLLM を使用している場合は、[モデルのパフォーマンス] ダッシュボードが使用可能になり、vLLM モデルのパフォーマンスの指標が表示されます。
チャット インターフェースを使用する
問題のトラブルシューティング
モデルのパフォーマンスをモニタリングする
モデルのオブザーバビリティ指標のダッシュボードを表示する手順は次のとおりです。
Cloud Monitoring の vLLM ダッシュボード統合で指標を表示することもできます。これらの指標は、事前設定されたフィルタを使用することなくすべての vLLM デプロイで集計されます。
Cloud Monitoring でダッシュボードを使用するには、GKE クラスタで Google Cloud Managed Service for Prometheus を有効にする必要があります。これにより、vLLM から指標が収集されるようになります。vLLM はデフォルトで Prometheus 形式の指標を公開するため、追加のエクスポーターをインストールする必要はありません。Google Cloud Managed Service for Prometheus を使用したモデルからの指標の収集については、Cloud Monitoring のドキュメントで vLLM のオブザーバビリティ ガイダンスをご覧ください。
クリーンアップ
このチュートリアルで使用したリソースについて、Google Cloud アカウントに課金されないようにするには、リソースを含むプロジェクトを削除するか、プロジェクトを維持して個々のリソースを削除します。
デプロイされたリソースを削除する
このガイドで作成したリソースについて Google Cloud アカウントに課金されないようにするには、次のコマンドを実行します。
gcloud container clusters delete CLUSTER_NAME \
--location=CONTROL_PLANE_LOCATION
次の値を置き換えます。
CONTROL_PLANE_LOCATION: クラスタのコントロール プレーンの Compute Engine の リージョン。CLUSTER_NAME: クラスタの名前。
次のステップ
- GKE の GPU の詳細を確認する。
- GitHub のサンプルコードを表示し、他のアクセラレータ(A100 GPU や H100 GPU など)で Gemma と vLLM の使用方法を確認する。
- Autopilot で GPU ワークロードをデプロイする方法を学習する。
- Standard で GPU ワークロードをデプロイする方法を学習する。
- vLLM の GitHub リポジトリとドキュメントを確認する。
- Vertex AI Model Garden を確認する。
- GKE プラットフォームのオーケストレーション機能を使用して、最適化された AI / ML ワークロードを実行する方法を確認する。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2026-05-21 UTC。