关于 llmops-platform-engineering
面向构建和运营内部 LLM 平台的工程技能,供平台、应用和安全团队用于组织模型从实验到生产的流程。内容涵盖评估门禁、A/B 测试、Kubernetes 模型服务、治理和运维。
主要功能
- 01设计 LLM 平台控制面与数据面
- 02建立含评估门禁的 CI/CD 流程
- 03配置模型版本 A/B 测试
- 04部署 Kubernetes 模型服务
- 05设置治理、可观测性和成本分析
适用场景
- 01为团队搭建内部 LLM 平台
- 02在模型发布前执行质量与安全评估
- 03比较不同模型版本的表现
- 04管理模型推广与生产部署
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ bagelhole/ devops-security-agent-skills --skill llmops-platform-engineering安装后在 Claude Code 中输入/llmops-platform-engineering确认已加载。
详细介绍
LLMOps 平台工程
设计并运营内部大模型平台,在支持快速试验的同时,确保可靠性、成本和合规性。
适用场景
- 为团队构建内部平台,用于部署和管理由大模型驱动的功能
- 设计包含模型评估门禁的 CI/CD 流水线
- 搭建模型版本的 A/B 测试基础设施
- 创建基于 Kubernetes 的模型服务基础设施
- 建立模型晋级的治理工作流
前置条件
- 配备 GPU 节点池的 Kubernetes 集群(或云端推理 API 访问权限)
- 容器镜像仓库(Harbor、ECR、GCR 或 ACR)
- CI/CD 系统(GitHub Actions、GitLab CI 或 Argo Workflows)
- 可观测性技术栈(Prometheus + Grafana + OpenTelemetry)
- 模型注册表(MLflow 或自定义元数据存储)
预期成果
- 从试验到生产的标准化流程
- 通过质量和安全门禁实现安全的模型发布
- 用于推理、向量数据库和可观测性的可重复使用基础设施模块
- 明确平台、应用和安全团队之间的责任归属
参考架构
- 控制平面:模型注册表、提示词/版本目录、策略检查、评估流水线。
- 数据平面:推理网关、向量数据库、缓存、特征存储。
- 运维平面:遥测、告警、SLO 仪表板、成本分析。
- 安全平面:IAM 边界、密钥轮换、内容过滤器、审计日志。
模型晋级流水线
# .github/workflows/model-promotion.yaml
name: Model Promotion Pipeline
on:
workflow_dispatch:
inputs:
model_name:
description: "Model identifier"
required: true
model_version:
description: "Model version to promote"
required: true
target_env:
description: "Target environment"
required: true
type: choice
options: [staging, production]
jobs:
evaluate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run quality evaluation suite
run: |
python -m evals.run \
--model "${{ inputs.model_name }}:${{ inputs.model_version }}" \
--suite quality \
--output results/quality.json
- name: Run safety evaluation suite
run: |
python -m evals.run \
--model "${{ inputs.model_name }}:${{ inputs.model_version }}" \
--suite safety \
--output results/safety.json
- name: Run latency benchmark
run: |
python -m evals.benchmark \
--model "${{ inputs.model_name }}:${{ inputs.model_version }}" \
--concurrent-users 50 \
--duration 300 \
--output results/latency.json
- name: Gate check - quality
run: |
python -m evals.gate_check \
--results results/quality.json \
--threshold-file thresholds/quality.yaml
- name: Gate check - safety
run: |
python -m evals.gate_check \
--results results/safety.json \
--threshold-file thresholds/safety.yaml
- name: Gate check - latency
run: |
python -m evals.gate_check \
--results results/latency.json \
--threshold-file thresholds/latency.yaml
- name: Upload eval evidence
uses: actions/upload-artifact@v4
with:
name: eval-results-${{ inputs.model_version }}
path: results/
approve:
needs: evaluate
runs-on: ubuntu-latest
environment: ${{ inputs.target_env }}
steps:
- name: Record approval
run: |
echo "Approved by: ${{ github.actor }}"
echo "Model: ${{ inputs.model_name }}:${{ inputs.model_version }}"
echo "Target: ${{ inputs.target_env }}"
echo "Time: $(date -u +%Y-%m-%dT%H:%M:%SZ)"
deploy:
needs: approve
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy canary
run: |
kubectl set image deployment/${{ inputs.model_name }}-canary \
model=${{ inputs.model_name }}:${{ inputs.model_version }} \
-n ai-${{ inputs.target_env }}
- name: Wait for canary validation (15 min)
run: |
python -m canary.validate \
--deployment ${{ inputs.model_name }}-canary \
--namespace ai-${{ inputs.target_env }} \
--duration 900 \
--quality-threshold 0.85 \
--error-rate-threshold 0.02
- name: Promote to full rollout
run: |
kubectl set image deployment/${{ inputs.model_name }} \
model=${{ inputs.model_name }}:${{ inputs.model_version }} \
-n ai-${{ inputs.target_env }}
kubectl rollout status deployment/${{ inputs.model_name }} \
-n ai-${{ inputs.target_env }} --timeout=300s
评估门禁阈值
# thresholds/quality.yaml
gates:
groundedness:
metric: groundedness_score
min: 0.85
comparison: gte
task_success:
metric: task_success_rate
min: 0.90
comparison: gte
hallucination:
metric: hallucination_rate
max: 0.08
comparison: lte
regression:
metric: quality_delta_vs_baseline
min: -0.02
comparison: gte
description: "Must not regress more than 2% vs current production"
# thresholds/latency.yaml
gates:
p50_latency:
metric: latency_p50_ms
max: 800
comparison: lte
p95_latency:
metric: latency_p95_ms
max: 2000
comparison: lte
p99_latency:
metric: latency_p99_ms
max: 5000
comparison: lte
throughput:
metric: requests_per_second
min: 50
comparison: gte
A/B 测试配置
# ab-test-config.yaml
apiVersion: gateway.ai/v1
kind: ABTest
metadata:
name: model-comparison-q1
namespace: ai-production
spec:
duration: 7d
traffic_split:
control:
model: gpt-4o-2024-08-06
weight: 70
treatment:
model: gpt-4o-2025-01-15
weight: 30
metrics:
primary:
- task_success_rate
- user_satisfaction_score
secondary:
- latency_p95
- cost_per_request
- hallucination_rate
guardrails:
auto_rollback_if:
- metric: task_success_rate
threshold: 0.80
window: 1h
- metric: hallucination_rate
threshold: 0.15
window: 30m
assignment:
strategy: sticky_user
hash_key: user_id
Kubernetes 模型服务部署
# model-serving-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: llm-inference
namespace: ai-production
labels:
app: llm-inference
model: gpt-4o
version: "2025-01"
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: llm-inference
template:
metadata:
labels:
app: llm-inference
model: gpt-4o
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: llm-inference
containers:
- name: model
image: registry.internal/vllm-server:0.4.1
args:
- "--model=/models/current"
- "--tensor-parallel-size=1"
- "--max-model-len=8192"
- "--gpu-memory-utilization=0.90"
ports:
- containerPort: 8000
name: inference
- containerPort: 8080
name: metrics
resources:
requests:
cpu: "4"
memory: "16Gi"
nvidia.com/gpu: "1"
limits:
cpu: "8"
memory: "32Gi"
nvidia.com/gpu: "1"
readinessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 60
periodSeconds: 10
livenessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 120
periodSeconds: 30
volumeMounts:
- name: model-weights
mountPath: /models
readOnly: true
- name: config
mountPath: /etc/vllm
volumes:
- name: model-weights
persistentVolumeClaim:
claimName: model-weights-pvc
- name: config
configMap:
name: vllm-config
tolerations:
- key: nvidia.com/gpu
operator: Exists
effect: NoSchedule
nodeSelector:
gpu-type: a100
---
apiVersion: v1
kind: Service
metadata:
name: llm-inference
namespace: ai-production
spec:
selector:
app: llm-inference
ports:
- name: inference
port: 8000
targetPort: 8000
- name: metrics
port: 8080
targetPort: 8080
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: llm-inference-hpa
namespace: ai-production
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: llm-inference
minReplicas: 2
maxReplicas: 10
metrics:
- type: Pods
pods:
metric:
name: llm_queue_depth
target:
type: AverageValue
averageValue: "5"
- type: Pods
pods:
metric:
name: gpu_utilization_percent
target:
type: AverageValue
averageValue: "75"
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Pods
value: 2
periodSeconds: 120
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1
periodSeconds: 300
AI 服务的 CI/CD 设计
- 使用固定依赖项和模型哈希构建不可变容器。
- 按环境晋级:
dev -> stage -> prod。 - 以下情况应使部署失败:
- 回归评估结果低于基线,
- 安全测试结果超过风险阈值,
- p95 延迟超过 SLO 预算。
- 保存部署证据以供审计(提交 SHA、评估报告、审批人)。
运维 SLO
| 信号 | 目标 | 测量窗口 |
|---|---|---|
| 可用性 | 99.9% | 滚动 30 天 |
| p95 延迟 | < 1200ms | 5 分钟时间段 |
| 单次请求成本 | < $0.05 | 1 小时平均值 |
| 任务成功率 | > 90% | 滚动 24 小时 |
| 有据性 | > 85% | 滚动 24 小时 |
平台防护措施
- 强制执行租户配额和模型允许列表。
- 自动化流程必须使用结构化输出契约。
- 关键工作流默认采用低风险模型设置。
- 在生产环境中禁用不受限制的工具执行。
工具链(示例)
| 层 | 工具 |
|---|---|
| 编排 | Argo Workflows、GitHub Actions、Airflow |
| 模型注册表 | MLflow、自定义元数据数据库 |
| 网关 | LiteLLM、基于 Envoy 的 API 网关 |
| 可观测性 | OpenTelemetry + Prometheus + Grafana + Langfuse |
| 策略 | 使用 OPA/Rego 进行部署和运行时检查 |
| 评估 | RAGAS、自定义评估工具集、Promptfoo |
| 服务 | vLLM、TGI、Triton Inference Server |
故障排查
| 问题 | 诊断 | 解决方案 |
|---|---|---|
| 金丝雀发布未通过质量门禁 | 将评估结果与基线进行比较 | 调整模型配置或回滚版本 |
| 部署卡在发布过程中 | 检查 Pod 事件和资源配额 | 修正资源限制或确保节点可用 |
| A/B 测试未显示显著差异 | 验证流量分配和样本量 | 延长测试时间或提高实验组权重 |
| 模型冷启动过慢 | 模型权重下载量过大 | 使用预缓存的 PVC 或 init 容器 |
| 评估流水线不稳定 | 模型输出具有非确定性 | 将评估的 temperature 设为 0,并增加样本量 |
相关技能
- ai-pipeline-orchestration - 编排数据摄取和推理工作流
- agent-evals - 为发布构建评估门禁
- llm-gateway - 路由和控制 LLM 流量
- model-registry-governance - 模型生命周期和审批工作流
- ai-sre-incident-response - AI 专属事件响应
评论
支持 Markdown