llm-wiki wiki · sources 2026-06-13

原文:raw/llm-d-workload-variant-autoscaler-architecture-analysis.md · 仓库:https://github.com/llm-d/llm-d-workload-variant-autoscaler · 分析版本 HEAD 526ce85

一句话定位

llm-d-workload-variant-autoscaler 是面向分布式 llm-inference 的 Kubernetes 全局 autoscaler,核心对象是同一模型/InferencePool 下的多个 serving variant。它通过 Prometheus、gateway-api-inference-extension、KEDA/HPA、GPU inventory 和 scale target 状态,把“不同硬件/角色/成本的变体应该各扩多少副本”转成外部指标和 status。

核心架构图

┌──────────────────────────────────────────────┐
│ VariantAutoscaling CRD                       │
│ api/v1alpha1                                 │
│ modelID / min-max / variantCost / targetRef  │
└───────────────┬──────────────────────────────┘
                │ reconcile
┌───────────────▼──────────────────────────────┐
│ controller-runtime Manager                   │
│ cmd/main.go                                  │
│ - VariantAutoscaling reconciler              │
│ - HPA / KEDA ScaledObject reconciler         │
│ - InferencePool reconciler                   │
└───────┬─────────────┬──────────────┬─────────┘
        │             │              │
        │ target refs │ metrics      │ pool state
        ▼             ▼              ▼
┌────────────┐ ┌──────────────┐ ┌──────────────────────┐
│Deployment/ │ │ Prometheus   │ │ Gateway API          │
│StatefulSet/│ │ request rate │ │ InferencePool        │
│LWS scale   │ │ queue/cache  │ │ Endpoint / variants  │
└─────┬──────┘ └──────┬───────┘ └──────────┬───────────┘
      │               │                    │
      └───────────────▼────────────────────┘
                      │
┌─────────────────────▼────────────────────────┐
│ Saturation Engine                            │
│ internal/engines/saturation                  │
│ - replica metrics collector                  │
│ - capacity knowledge store                   │
│ - GPU inventory / limiter                    │
│ - queueing model analyzer                    │
│ - cost-aware optimizer                       │
└─────────────────────┬────────────────────────┘
                      │ desired optimized allocation
                      ▼
┌──────────────────────────────────────────────┐
│ Actuator / Metrics Emitter                   │
│ internal/actuator                            │
│ emits desired/current replica metrics        │
└───────────────┬──────────────────────────────┘
                │ external/custom metrics
        ┌───────▼────────┐
        │ HPA / KEDA     │
        │ scale subresource│
        └───────┬────────┘
                ▼
         Serving variants

模块分层

层 / 模块 职责
API 层 定义 VariantAutoscaling spec/status/conditions。
Manager 启动层 注册 K8s、Prometheus Operator、Gateway API Inference Extension、KEDA、LWS 等 scheme,组装 reconciler 和 engines。
Reconcile 层 解析 scale target、更新 conditions、读取 decision cache、patch status、watch workload 和 InferencePool。
Metrics 收集 采集 request rate、replica、queue/cache/capacity 相关指标。
优化引擎 维护 capacity store、GPU inventory、queueing/saturation analyzer、cost-aware optimizer。
执行动作 发出 desired/current replica 等指标供 HPA/KEDA 消费。

关键数据流

用户创建 VariantAutoscaling
        │
        ▼
Reconciler resolve scaleTargetRef + InferencePool/modelID
        │
        ├── 写 TargetResolved / MetricsAvailable / OptimizationReady conditions
        └── 注册 namespace / watched resources
        │
        ▼
Saturation Engine 周期采集 Prometheus + replica + GPU inventory
        │
        ├── 估算 variant capacity / saturation
        ├── 使用 queueing model 推断请求压力
        ├── 应用 GPU / budget / min-max 约束
        └── cost-aware optimizer 计算 desired allocation
        │
        ▼
DecisionCache / VariantAutoscaling status
        │
        ▼
Actuator 发出 desired replica metrics
        │
        ▼
HPA 或 KEDA 读取 external/custom metrics
        │
        ▼
Deployment / StatefulSet / LWS 副本数变化

设计决策与哲学