本地 vs Cloud 决策框架 + 自动路由(2026 综合)
2026 年 AI 工作流的真正问题不是"用哪个模型",而是"哪个任务值得哪个层级的智能"。Hybrid LLM 架构(本地 cheap + cloud SOTA)= 业界共识:节省 30-85% 成本,不牺牲质量(智能路由保 95% SOTA 性能)。
3 个核心数据:RouteLLM(ICLR 2025)85% 成本下降 / 95% GPT-4 性能 · LiteLLM production 节省 2-5x · 2026 年 37% 企业生产用 5+ 模型。
| 维度 | 本地 LLM 适合 | Cloud LLM 适合 |
|---|---|---|
| Context 长度 | < 8K tokens | > 16K tokens |
| 任务类型 | Mechanical / 重复 / 模板化 | Architectural / 创意 / reasoning |
| 复杂度 | 单文件 / ≤10 tool calls | 多文件 / >26 tool calls / 长 agent |
| 隐私 | 敏感代码 / 数据 / 内部 | 公开数据 / 通用知识 |
| 延迟要求 | 实时反馈(< 1s 启动) | 可接受网络(> 200ms) |
| QPS | 高 QPS 低复杂度 | 偶发关键决策 |
| 成本模型 | 固定(电费 + 硬件) | 按 token(可变) |
| 离线 | 必须 | 不必 |
"The goal is not replacement, it is orchestration." — Cloud.in
每个任务在 5 维上打分 → 决定路由
直接走本地
例:autocomplete (0,0,0,0,0 = 0)
混合:先本地,失败 fallback cloud
例:中等 agent 任务 (1,1,0,1,1 = 4)
直接 cloud
例:长 context 架构 (2,2,0,0,2 = 6+) 实际:
long-context reasoning (2,2,1,0,2 = 7)
| 任务 | Context | 复杂度 | 隐私 | 延迟 | 质量 | 总分 | 决策 |
|---|---|---|---|---|---|---|---|
| 代码 autocomplete | 0 | 0 | 0 | 0 | 0 | 0 | 本地 |
| 短文档总结(2K) | 0 | 0 | 0 | 0 | 0 | 0 | 本地 |
| Unit test 生成 | 0 | 0 | 0 | 1 | 0 | 1 | 本地 |
| 单文件 refactor | 0 | 1 | 0 | 1 | 0 | 2 | 本地 |
| 多文件 debug (8K) | 1 | 1 | 0 | 1 | 1 | 4 | 混合 |
| 架构 reasoning (12K) | 1 | 2 | 0 | 1 | 2 | 6 | 混合→cloud |
| 大型 codebase 分析 (32K) | 2 | 2 | 0 | 1 | 2 | 7 | Cloud |
| 内部代码 + 关键逻辑 | 1 | 2 | 0 | 1 | 2 | 6 | 本地(隐私 + 混合) |
| 工具 | 类型 | 部署 | 成本 | 路由方式 | 适用场景 |
|---|---|---|---|---|---|
| LiteLLM | OSS gateway | Self-host (Docker) | 免费(只付 provider) | 规则 / fallback | 生产 / 多 provider / 成本治理 |
| OpenRouter | Managed SaaS | 第三方 | 按 token | 内容自动 | 一键接入 400+ 模型 |
| Inworld Router | Managed + 智能 | 第三方 | 按 token | 内容分析智能 | 百万级 QPS 优化 |
| RouteLLM | 开源模型 | Self-host | 免费 | 训练路由器 | 极致成本优化(ICLR 2025) |
OpenRouter
managed,0 运维,一键接入 400+ 模型
LiteLLM
OSS,完整 fallback + cost tracking + 100+ providers
RouteLLM
UC Berkeley 论文,85% 成本下降 / 95% GPT-4 性能
Inworld Router
智能内容路由 + 20x 用户增长不烧钱
| 反模式 | 问题 | 修复 |
|---|---|---|
| One Model Default | 全用 Opus 4,简单任务也烧 SOTA 钱 | 用 router,按任务分流 |
| Offline-Only Dogma | 硬要全本地,长 context 任务慢 30s+ | 接受 cloud fallback |
| Cloud-Only Habit | 不优化本地潜力,高 QPS 烧钱 | 高 QPS 任务用本地 |
| No Context Strategy | 32K context 烧 Opus 4 ($25/M output) | Context Compaction 先做 |
model_list:
# 本地 - 廉价任务
- model_name: local-cheap
litellm_params:
model: ollama/qwen2.5-coder:7b
api_base: http://localhost:11434
# 本地 - 中等任务
- model_name: local-mid
litellm_params:
model: ollama/qwen3.6:35b-a3b-q4
api_base: http://localhost:11434
# Cloud - 高级任务
- model_name: cloud-sota
litellm_params:
model: anthropic/claude-sonnet-4.6
api_key: os.environ/ANTHROPIC_API_KEY
router_settings:
routing_strategy: simple-shuffle # 或 usage-based
num_retries: 2
timeout: 30
fallbacks:
- local-mid: [cloud-sota] # 本地失败 → cloud
- cloud-sota: [local-mid] # cloud 失败 → 本地
docker run -d \
-p 4000:4000 \
-v $(pwd)/config.yaml:/app/config.yaml \
-e ANTHROPIC_API_KEY=sk-ant-*** \
ghcr.io/berriai/litellm:main-latest \
--config /app/config.yaml
# 改 base URL 即可
import openai
client = openai.OpenAI(
base_url="http://localhost:4000", # 指向 LiteLLM proxy
api_key="anything", # LiteLLM 验证用
)
response = client.chat.completions.create(
model="local-cheap", # 或 "local-mid" / "cloud-sota"
messages=[{"role": "user", "content": "你的任务"}]
)
/global/spend/report + UI dashboard| 模型 | Input ($/1M) | Output ($/1M) | 等级 |
|---|---|---|---|
| GPT-4.1 nano | 0.10 | 0.40 | Cheap |
| GPT-4.1 mini | 0.40 | 1.60 | Cheap |
| Claude Haiku 4.5 | 1.00 | 5.00 | Mid |
| Claude Sonnet 4.6 | 3.00 | 15.00 | Mid |
| GPT-4.1 | 2.00 | 8.00 | SOTA |
| Claude Opus 4.6 | 5.00 | 25.00 | SOTA |
M5 Max 64GB ≈ $4,000
30W × 24h × 365 = 263 kWh/年 ≈ $35/年
~$1,300/年
< 2M tokens/day → self-host 便宜
> 2M tokens/day → cloud 便宜
| 优化层 | 节省 | 典型收益 | 难度 |
|---|---|---|---|
| Quantization (Q4/Q8) | Memory | 2-4x 内存,~50% 成本 | Low |
| Continuous Batching | GPU idle time | 3-10x 吞吐 | Low |
| PagedAttention (vLLM) | KV cache 浪费 | 24x 吞吐 | Low |
| Speculative Decoding | Decode latency | 2-5x 速度 | Medium |
| Context Compaction | Input tokens | 50-70% token 减少 | Low |
| Prompt Caching | 重复 prefill | 90% 延迟降低 | Low |
| Model Routing | 每请求成本 | 2-5x aggregate 节省 | Medium |
"A 60% reduction in tokens per task is a 60% cost reduction, regardless of per-token pricing." — Morph 2026
| 反模式 | 问题 | 修复 |
|---|---|---|
| One Model Default | 全用 Opus 4 / GPT-4,简单任务也烧 SOTA 钱 | 用 router,按任务分流 |
| Offline-Only Dogma | 硬要全本地,长 context 任务慢 30s+ | 接受 cloud fallback |
| Cloud-Only Habit | 不优化本地潜力,高 QPS 烧钱 | 高 QPS 任务用本地 |
| No Context Strategy | 32K context 烧 Opus 4 ($25/M output) | Context Compaction 先做 |
"One model cannot be optimal for all requests. Easy requests overpay. Hard requests sometimes underdeliver." — Alex Cloud Star
"No single model is best for everything. A model router is like an air traffic controller." — Swfte AI
"Just as modern infrastructure combines edge computing, on-prem systems, and cloud platforms, AI development workflows are evolving toward layered intelligence architectures." — Cloud.in
M5 Ultra / M6 Mac Mini 500GB RAM
→ 70B 模型本地能跑
Q4/Q3 量化 + MLX 优化
当前 MLX 2x GGUF
2027 年可能 3x
Claude 4.6 真 1M context
→ 重新定义 local/cloud 边界
Agent Harness 自带 router
Pi coding agent 已内置 harness 自定义
"Sonnet / Opus 4.0 等级模型在设备上可跑"
→ M5 Ultra / M6 Mac Mini 500GB RAM 是关键