gke-inference
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGKE AI/ML Inference
GKE AI/ML 推理
This reference covers deploying AI/ML inference workloads on GKE using Google's
Inference Quickstart (GIQ) and best practices for LLM serving.
MCP Tools:,apply_k8s_manifest,get_k8s_resource,get_k8s_logs,get_k8s_rollout_status,describe_k8s_resource. CLI-only:list_k8s_eventsgcloud container ai profiles *
本参考文档介绍如何使用Google的推理快速入门(GIQ)在GKE上部署AI/ML推理工作负载,以及LLM服务的最佳实践。
MCP工具:、apply_k8s_manifest、get_k8s_resource、get_k8s_logs、get_k8s_rollout_status、describe_k8s_resource。 仅支持CLI:list_k8s_eventsgcloud container ai profiles *
When to Use
适用场景
- Deploy an AI model (Llama, Gemma, Mistral, etc.) to GKE
- Generate optimized Kubernetes manifests for inference
- Select GPU/TPU accelerators for model serving
- Configure autoscaling for LLM inference
- 将AI模型(Llama、Gemma、Mistral等)部署到GKE
- 生成用于推理的优化Kubernetes清单
- 为模型服务选择GPU/TPU加速器
- 为LLM推理配置自动扩缩容
Prerequisites
前提条件
- A golden path GKE Autopilot cluster (GPU workloads are supported via ComputeClasses and NAP)
- CLI authenticated
gcloud - Sufficient GPU/TPU quota in the target region
- 一个符合最佳路径的GKE Autopilot集群(GPU工作负载通过ComputeClasses和NAP支持)
- CLI已完成认证
gcloud - 目标区域有足够的GPU/TPU配额
Workflow
工作流程
1. Discovery: Find Models and Hardware
1. 发现:查找模型与硬件
bash
undefinedbash
undefinedList all supported models
列出所有支持的模型
gcloud container ai profiles models list --quiet
gcloud container ai profiles models list --quiet
Find valid accelerator/server combinations for a model
查找模型对应的有效加速器/服务器组合
gcloud container ai profiles list --model=<MODEL_NAME> --quiet
gcloud container ai profiles list --model=<MODEL_NAME> --quiet
Example: what can run Gemma 2 9B?
示例:哪些资源可以运行Gemma 2 9B?
gcloud container ai profiles list --model=gemma-2-9b-it --quiet
undefinedgcloud container ai profiles list --model=gemma-2-9b-it --quiet
undefined2. Generate Manifest
2. 生成清单
bash
gcloud container ai profiles manifests create \
--model=<MODEL_NAME> \
--model-server=<SERVER> \
--accelerator-type=<ACCELERATOR> \
--target-ntpot-milliseconds=<NTPOT> --quiet > inference.yamlParameters:
- : Model ID (e.g.,
--model,gemma-2-9b-it)llama-3-8b - : Inference server (
--model-server,vllm,tgi,triton)tensorrt-llm - : GPU/TPU type (
--accelerator-type,nvidia-l4,nvidia-tesla-a100)nvidia-h100-80gb - : Target Normalized Time Per Output Token (optional, for latency optimization)
--target-ntpot-milliseconds
Example:
bash
gcloud container ai profiles manifests create \
--model=gemma-2-9b-it \
--model-server=vllm \
--accelerator-type=nvidia-l4 \
--target-ntpot-milliseconds=50 --quiet > inference.yamlbash
gcloud container ai profiles manifests create \
--model=<MODEL_NAME> \
--model-server=<SERVER> \
--accelerator-type=<ACCELERATOR> \
--target-ntpot-milliseconds=<NTPOT> --quiet > inference.yaml参数说明:
- :模型ID(例如:
--model、gemma-2-9b-it)llama-3-8b - :推理服务器(
--model-server、vllm、tgi、triton)tensorrt-llm - :GPU/TPU类型(
--accelerator-type、nvidia-l4、nvidia-tesla-a100)nvidia-h100-80gb - :目标归一化输出令牌耗时(可选,用于延迟优化)
--target-ntpot-milliseconds
示例:
bash
gcloud container ai profiles manifests create \
--model=gemma-2-9b-it \
--model-server=vllm \
--accelerator-type=nvidia-l4 \
--target-ntpot-milliseconds=50 --quiet > inference.yaml3. Review and Deploy
3. 审核与部署
bash
undefinedbash
undefinedReview for placeholders (HF tokens, PVCs)
审核清单中的占位符(HF令牌、PVC等)
cat inference.yaml
cat inference.yaml
Deploy
部署
kubectl apply -f inference.yaml
kubectl apply -f inference.yaml
Monitor
监控
kubectl get pods -w
kubectl logs -f <POD_NAME>
> Some models require Hugging Face tokens. Create a Kubernetes Secret and
> reference it in the manifest.kubectl get pods -w
kubectl logs -f <POD_NAME>
> 部分模型需要Hugging Face令牌。请创建Kubernetes Secret并在清单中引用它。GPU ComputeClass for Inference
用于推理的GPU ComputeClass
For Autopilot clusters, create a ComputeClass to target GPU nodes:
yaml
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: l4-inference
spec:
priorities:
- machineFamily: g2
gpu:
type: nvidia-l4
count: 1
minCores: 4
minMemoryGb: 16对于Autopilot集群,创建ComputeClass以指定GPU节点:
yaml
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: l4-inference
spec:
priorities:
- machineFamily: g2
gpu:
type: nvidia-l4
count: 1
minCores: 4
minMemoryGb: 16Accelerator Selection Guide
加速器选择指南
| Accelerator | Best For | Memory | Relative Cost |
|---|---|---|---|
| NVIDIA T4 | Budget inference, | 16 GB | Lowest |
| : : lightweight legacy : : : | |||
| : : models : : : | |||
| NVIDIA L4 (G2) | Small-medium model | 24 GB | Low |
| : : inference, video, : : : | |||
| : : graphics : : : | |||
| NVIDIA RTX PRO 6000 | Multimodal AI, | 96 GB | Medium |
| : (G4) : high-fidelity 3D, : : : | |||
| : : fine-tuning : : : | |||
| Cloud TPU v5e | Cost-effective | Varies | Medium |
| : : transformer inference : : : | |||
| Cloud TPU v5p | High-performance | Varies | High |
| : : training : : : | |||
| Cloud TPU v6e | High-efficiency next-gen | 32 GB/chip | Medium-High |
| : (Trillium) : training & serving : : : | |||
| Cloud TPU v7x | Ultra-scale inference & | 192 GB/chip | High |
| : (Ironwood) : agentic workflows : : : | |||
| NVIDIA A100 | Large model inference, | 40/80 GB | High |
| : : enterprise ML : : : | |||
| NVIDIA H100 / H200 | Frontier model training, | 80/141 GB | Highest |
| : : high throughput : : : | |||
| NVIDIA B200 (A4) | Blackwell-scale | 192 GB | Highest |
| : : training, FP4 precision : : : | |||
| NVIDIA GB200 (A4X) | Rack-scale AI (Grace | Massive | Highest |
| : : Blackwell Superchip) : : : |
| 加速器 | 适用场景 | 内存 | 相对成本 |
|---|---|---|---|
| NVIDIA T4 | 低成本推理、轻量级遗留模型 | 16 GB | 最低 |
| NVIDIA L4 (G2) | 中小型模型推理、视频、图形处理 | 24 GB | 低 |
| NVIDIA RTX PRO 6000 (G4) | 多模态AI、高保真3D、微调 | 96 GB | 中等 |
| Cloud TPU v5e | 高性价比Transformer推理 | 可变 | 中等 |
| Cloud TPU v5p | 高性能训练 | 可变 | 高 |
| Cloud TPU v6e (Trillium) | 高效下一代训练与服务 | 32 GB/芯片 | 中高 |
| Cloud TPU v7x (Ironwood) | 超大规模推理与智能代理工作流 | 192 GB/芯片 | 高 |
| NVIDIA A100 | 大型模型推理、企业级ML | 40/80 GB | 高 |
| NVIDIA H100 / H200 | 前沿模型训练、高吞吐量 | 80/141 GB | 最高 |
| NVIDIA B200 (A4) | Blackwell级训练、FP4精度 | 192 GB | 最高 |
| NVIDIA GB200 (A4X) | 机架级AI(Grace Blackwell超级芯片) | 超大容量 | 最高 |
Autoscaling LLM Inference
LLM推理自动扩缩容
GPU-based autoscaling
基于GPU的自动扩缩容
Use custom metrics for GPU utilization:
yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: llm-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: llm-server
minReplicas: 1
maxReplicas: 10
metrics:
- type: Pods
pods:
metric:
name: gpu_duty_cycle
target:
type: AverageValue
averageValue: "80"使用自定义指标监控GPU利用率:
yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: llm-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: llm-server
minReplicas: 1
maxReplicas: 10
metrics:
- type: Pods
pods:
metric:
name: gpu_duty_cycle
target:
type: AverageValue
averageValue: "80"Best practices for inference autoscaling
推理自动扩缩容最佳实践
- Use DCGM metrics: Golden path enables DCGM monitoring for GPU utilization metrics
- Set appropriate minReplicas: At least 1 for always-on serving; 0 for batch/on-demand
- Tune scale-down delay: LLM model loading is slow; use longer stabilization windows
- Consider queue depth: Scale on pending requests rather than pure GPU utilization for latency-sensitive workloads
- 使用DCGM指标:最佳路径已启用DCGM监控以获取GPU利用率指标
- 设置合适的minReplicas:持续服务至少设为1;批处理/按需服务可设为0
- 调整缩容延迟:LLM模型加载速度较慢,请使用更长的稳定窗口
- 考虑队列深度:对于延迟敏感型工作负载,根据待处理请求数而非单纯GPU利用率进行扩缩容
Optimization Tips
优化技巧
- Quantization: Use quantized models (GPTQ, AWQ) to reduce GPU memory and increase throughput
- Batching: Configure model server batch size for throughput vs latency trade-off
- Tensor parallelism: Split large models across multiple GPUs within a node
- KV cache optimization: Tune in vLLM for KV cache allocation
--gpu-memory-utilization
- 量化:使用量化模型(GPTQ、AWQ)减少GPU内存占用并提高吞吐量
- 批处理:配置模型服务器的批处理大小,平衡吞吐量与延迟
- 张量并行:将大型模型拆分到节点内的多个GPU上
- KV缓存优化:在vLLM中调整参数以优化KV缓存分配
--gpu-memory-utilization
Troubleshooting
故障排查
| Issue | Cause | Fix |
|---|---|---|
| Invalid | Unsupported tuple | Re-run `gcloud container ai |
| : model/accelerator : : profiles list : | ||
| : combination : : --model=<MODEL>` : | ||
| GPU quota exceeded | Regional quota limit | Request quota increase or |
| : : : try a different region : | ||
| OOM on GPU | Model too large for | Use larger GPU, enable |
| : : accelerator : quantization, or use tensor : | ||
| : : : parallelism : | ||
| Slow cold start | Large model loading from | Use local SSD for model |
| : : registry : caching; pre-pull images : |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 无效的模型/加速器组合 | 不支持的组合 | 重新运行 |
| GPU配额不足 | 区域配额限制 | 请求增加配额或尝试其他区域 |
| GPU内存不足(OOM) | 模型超出加速器内存容量 | 使用更大的GPU、启用量化或使用张量并行 |
| 冷启动缓慢 | 从镜像仓库加载大型模型 | 使用本地SSD缓存模型;预拉取镜像 |