使用 NVIDIA Dynamo 安装
本指南分步说明如何将 vLLM Semantic Router 与 NVIDIA Dynamo 集成。
关于 NVIDIA Dynamo
NVIDIA Dynamo 是面向大语言模型推理的高性能分布式推理平台。Dynamo 通过智能路由与缓存机制,帮助优化 GPU 利用率并降低推理延迟。
主要特性
- 分离式服务(Disaggregated Serving):Prefill 与 Decode 工作进程分离,更好利用 GPU
- KV 感知路由:将请求路由到具备相关 KV 缓存的工作进程,优化前缀缓存
- 动态扩缩容:Planner 组件按负载自动扩缩
- 多级 KV 缓存:GPU HBM → 系统内存 → NVMe,分层管理缓存
- 工作进程协调:etcd 与 NATS 用于分布式注册与消息队列
- 后端无关:支持 vLLM、SGLang、TensorRT-LLM 等后端
集成收益
将 vLLM Semantic Router 与 NVIDIA Dynamo 结合可获得:
- 双层智能:Semantic Router 在请求层做模型选择与分类;Dynamo 在基础设施层优化工作进程选择与 KV 缓存复用
- 智能模型选择:Semantic Router 理解内容并路由到合适模型;Dynamo 的 KV 感知路由器选择最优工作进程
- 双层缓存:语义缓存(请求级,Milvus)与 KV 缓存(token 级,Dynamo 管理)叠加,降低延迟
- 安全增强:PII 与越狱检测在请求到达推理工作进程前过滤
- 分离式架构:Prefill/Decode 分离与 KV 感知路由,降低延迟、提高吞吐
架构
本部署采用 分离式路由器部署 模式并 启用 KV 缓存,Prefill 与 Decode 工作进程分离以更好利用 GPU。
┌───────────── ────────────────────────────────────────────────────┐
│ CLIENT │
│ curl -X POST http://localhost:8080/v1/chat/completions │
│ -d '{"model": "MoM", "messages": [...]}' │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ ENVOY GATEWAY │
│ • Routes traffic, applies ExtProc filter │
└─────────────────────────────── ──────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ SEMANTIC ROUTER (ExtProc Filter) │
│ • Classifies query → selects category (e.g., "math") │
│ • Selects model → rewrites request │
│ • Injects domain-specific system prompt │
│ • PII/Jailbreak detection │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ DYNAMO FRONTEND (KV-Aware Routing) │
│ • Receives enriched request with selected model │
│ • Routes to optimal worker based on KV cache state │
│ • Coordinates workers via etcd/NATS │
└─────────────────────────────────────────────────────────────────┘
│ │
▼ ▼
┌───────────────────────────┐ ┌───────────────────────────┐
│ PREFILL WORKER (GPU 1) │ │ DECODE WORKER (GPU 2) │
│ prefillworker0 │──▶ decodeworker1 │
│ --worker-type prefill │ │ --worker-type decode │
└───────────────────────────┘ └───────────────────────────┘
部署模式
本指南部署 分离式路由器 且 启用 KV 缓存(frontend.routerMode=kv)。推荐该配置以获得最佳性能:KV 感知路由可在请求间复用已计算的 attention;Prefill/Decode 分离可最大化 GPU 利用率。
依据 NVIDIA Dynamo 部署模式,Helm Chart 支持两种模式:
聚合模式(默认)
工作进程 同时处理 Prefill 与 Decode。部署更简单,所需 GPU 更少。
# No workerType specified = defaults to "both"
helm install dynamo-vllm ./deploy/kubernetes/dynamo/helm-chart \
--namespace dynamo-system \
--set workers[0].model.path=Qwen/Qwen2-0.5B-Instruct \
--set workers[1].model.path=Qwen/Qwen2-0.5B-Instruct
- 工作进程在 ETCD 中注册为
backend组件 - 无
--is-prefill-worker标志 - 每个工作进程可处理完整推理请求
分离模式(高性能)
Prefill 与 Decode 工作进程分离,更好利用 GPU。
# Explicit workerType = disaggregated mode
helm install dynamo-vllm ./deploy/kubernetes/dynamo/helm-chart \
--namespace dynamo-system \
--set workers[0].model.path=Qwen/Qwen2-0.5B-Instruct \
--set workers[0].workerType=prefill \
--set workers[1].model.path=Qwen/Qwen2-0.5B-Instruct \
--set workers[1].workerType=decode
| Worker | 标志 | ETCD 组件 | 角色 |
|---|---|---|---|
| Prefill | --is-prefill-worker | prefill | 处理输入 token,生成 KV 缓存 |
| Decode | (无特殊标志) | backend | 生成输出 token,仅处理 decode 请求 |
分离模式下仅 Prefill 工作进程使用 --is-prefill-worker。Decode 工作进程使用默认 vLLM 行为(无特殊标志)。KV 感知前端 将 Prefill 请求路由到 prefill 工作进程,Decode 请求路由到 backend 工作进程。
前置条件
GPU 要求
本部署至少需要 3 块 GPU:
| 组件 | GPU | 说明 |
|---|---|---|
| Frontend | GPU 0 | Dynamo Frontend,KV 感知路由(--router-mode kv) |
| Prefill Worker | GPU 1 | 推理 Prefill 阶段(--worker-type prefill) |
| Decode Worker | GPU 2 | 推理 Decode 阶段(--worker-type decode) |
所需工具
开始前请安装:
NVIDIA 运行时配置(一次性)
将 Docker 默认运行时设为 NVIDIA:
# Configure NVIDIA runtime as default
sudo nvidia-ctk runtime configure --runtime=docker --set-as-default
# Restart Docker
sudo systemctl restart docker
# Verify configuration
docker info | grep -i "default runtime"
# Expected output: Default Runtime: nvidia
步骤 1:创建支持 GPU 的 Kind 集群
创建带 GPU 支持的本地 Kubernetes 集群,任选其一:
选项 1:快速设置(外部文档)
按官方 Kind GPU 文档快速创建:
kind create cluster --name semantic-router-dynamo
# Verify cluster is ready
kubectl wait --for=condition=Ready nodes --all --timeout=300s
GPU 支持见 Kind GPU 文档(extra mounts 与 NVIDIA device plugin 等)。
选项 2:完整 GPU 设置(E2E 流程)
与仓库 E2E 测试相同的流程,包含 Kind 内 GPU 所需的全部步骤。