Skip to content

Autoscale an llm-d pool

Use this guide to scale model-server replicas on what the router knows about demand, not on accelerator utilization, which reads high at any batch size on a decode-bound TPU. Every path below is a KEDA ScaledObject over a PromQL query of EPP or vLLM metrics; KEDA generates the HPA. The control loop, the signal choice and the SLO-aware control law are in chapter 21; code/ch21_operating/slo_check.py implements the law.

A closed loop read clockwise. On the left a blue box, Model server pods. An arrow labelled /metrics runs up and right into an amber EPP box at the top, whose second line is step 1, exposes metrics. Along the top: EPP to a grey Prometheus box, step 2 scrape; Prometheus to a grey KEDA box, ScaledObject, step 3 PromQL. Step 4, publish, runs down the right side from KEDA to a grey External Metrics API box. Along the bottom, right to left: External Metrics API to a grey HPA box, step 5 external metric; HPA to a grey Deployment box, step 5 desired replicas. An orange arrow labelled pod startup runs from Deployment up into Model server pods. A legend in the middle: a dark arrow, Takes seconds; an orange arrow, Takes minutes.

Every signal in this guide's step 1 runs through this one loop: a trigger query in the ScaledObject, the HPA that KEDA generates, and a pod start that takes minutes (Startup).

Prerequisites

  • A deployed optimized baseline (or P/D disaggregation for token-aware P/D) with router monitoring on, and Prometheus scraping the EPP (Observability, step 1).
  • KEDA installed. The SLO-aware guide installs 2.20.1; the others assume the platform's KEDA.
  • envsubst, jq and kubectl on your machine.
  • A measured cold start for your TPU pods (Startup): it sets the stabilization windows.

Steps

1. Pick the signal

Signal Scales on Per-replica target Needs
In-flight (default) llm_d_epp_inflight_requests 16 nothing beyond the stock EPP
Queue llm_d_epp_flow_control_queue_size plus llm_d_epp_request_running 1 queued, 16 running EPP flow control
Saturation (experimental) llm_d_epp_flow_control_pool_saturation 0.7 EPP flow control
Token-aware (experimental) llm_d_epp_inflight_tokens / peakPrefillThroughput, and vllm:kv_cache_usage_perc seconds of backlog; KV 0.8 one calibration on your TPU path
SLO-aware P90 TTFT and TPOT against the SLO band 0.40 to 0.55 recording rules, kube-state-metrics

The targets are the guides' examples on GPU. Drive representative load on your slice, find where another replica stops relieving demand, and put the threshold there.

Check: you can name the metric, its per-replica target and the SLO it protects.

2. In-flight, queue or saturation signal (KEDA with EPP metrics)

export REPO_ROOT=$(realpath $(git rev-parse --show-toplevel))
export NAMESPACE=llm-d-optimized-baseline
export MONITORING_NAMESPACE=llm-d-monitoring
export KEDA_NAMESPACE=keda
export MODEL=Qwen/Qwen3-32B
export TARGET_DEPLOYMENT=<release>-<accelerator>-vllm-decode   # read it: kubectl get deployment -n ${NAMESPACE}
export SCALEDOBJECT_NAME=optimized-baseline-keda-epp
export HPA_NAME=keda-hpa-optimized-baseline
export EPP_SERVICE=optimized-baseline-epp
export INFERENCE_POOL=optimized-baseline
export SIGNAL=inflight # inflight, queue, saturation
export ENV=existing
export OVERLAY_ROOT=${REPO_ROOT}/guides/workload-autoscaling/keda-epp/optimized-baseline
source ${REPO_ROOT}/guides/env.sh

The guide's example name is optimized-baseline-nvidia-gpu-vllm-decode; on TPU, use your decode Deployment's real name. For queue and saturation only, upgrade the router with the overlay's values, which enable flow control:

helm upgrade optimized-baseline \
  ${ROUTER_STANDALONE_CHART} \
  -f ${REPO_ROOT}/guides/recipes/router/base.values.yaml \
  -f ${REPO_ROOT}/guides/optimized-baseline/router/optimized-baseline.values.yaml \
  -f ${REPO_ROOT}/guides/recipes/router/features/monitoring.values.yaml \
  -f ${OVERLAY_ROOT}/router.values.yaml \
  -n ${NAMESPACE} --version ${ROUTER_CHART_VERSION}

On TPU7x, keep tpu-v7.values.yaml in that list too (Optimized baseline, step 1). Then start from one replica and apply the overlay for your signal:

kubectl scale deployment ${TARGET_DEPLOYMENT} -n ${NAMESPACE} --replicas=1
kubectl rollout status deployment/${TARGET_DEPLOYMENT} -n ${NAMESPACE} --timeout=15m
kubectl kustomize ${OVERLAY_ROOT}/overlays/k8s/${SIGNAL} | envsubst '$NAMESPACE $MODEL $TARGET_DEPLOYMENT $EPP_SERVICE $INFERENCE_POOL' | kubectl apply -f -

Review the overlay's scaledobject.yaml first: the Prometheus serverAddress and the AverageValue targets are edited in the file. If Prometheus needs a bearer token or mTLS, add a KEDA TriggerAuthentication (with GKE Managed Prometheus, follow the KEDA Prometheus authentication documentation for workload identity).

Check: the scaler is valid and the HPA receives metrics:

kubectl wait --for=condition=Ready scaledobject/${SCALEDOBJECT_NAME} -n ${NAMESPACE} --timeout=120s
kubectl get hpa ${HPA_NAME} -n ${NAMESPACE} -o jsonpath='{.status.currentMetrics}' | jq

currentMetrics is non-empty after a few polling intervals. Queries Q15 to Q18 in code/ch21_operating/promql.md are the trigger queries; run the one for your signal in Prometheus and confirm it returns a number.

3. Token-aware signal

The prefill trigger turns uncached in-flight prompt tokens into seconds of queue wait by dividing by the prefill velocity \(V_P\) (peakPrefillThroughput); the decode trigger acts at 80% KV occupancy. Calibrate \(V_P\) on your TPU serving path, idle, with CHUNK_SIZE equal to vLLM's --max-num-batched-tokens:

export TOPOLOGY=optimized-baseline   # or pd-disaggregation
export OVERLAY_ROOT=${REPO_ROOT}/guides/workload-autoscaling/keda-epp-token-aware/${TOPOLOGY}
GUIDE_NAME=${TOPOLOGY} \
NAMESPACE=${NAMESPACE} \
MODEL_NAME=${MODEL} \
CHUNK_SIZE=8192 \
${REPO_ROOT}/guides/recipes/router/calibration/calibrate.sh

It only prints the value. Put it in two places: prefix-cache-affinity-filter.parameters.peakPrefillThroughput in the guide's router values (then kubectl rollout restart -n ${NAMESPACE} deployment/${TOPOLOGY}-epp) and the / <V_P> divisor in the overlay's scaledobject.yaml. The shipped 15928 is Qwen3-32B on H100 at TP=2, and a P/D path measured 2696 on comparable hardware; no TPU figure is published. Choose the prefill threshold from your SLO: threshold = TTFT SLO minus uncached ISL / \(V_P\). Keep the EPP at one replica. Then, on generic Kubernetes, create the prometheus-token Secret as the token-aware guide shows and apply:

kubectl apply -k ${OVERLAY_ROOT}/k8s -n ${NAMESPACE}
kubectl wait --for=condition=Ready scaledobject --all -n ${NAMESPACE} --timeout=120s
kubectl get hpa -n ${NAMESPACE}

The decode trigger reads vllm:kv_cache_usage_perc, so the model servers must be scraped (the monitoring component, monitoring-pd for P/D), or it reads 0 forever.

Check: the ScaledObjects are Ready and Q19 and Q20 return numbers in Prometheus.

4. SLO-aware signal

export NAMESPACE=llm-d-optimized-baseline
export KEDA_VERSION=2.20.1
export SLO_DIR=${REPO_ROOT}/guides/workload-autoscaling/slo-aware
kubectl apply --server-side -f https://github.com/kedacore/keda/releases/download/v${KEDA_VERSION}/keda-${KEDA_VERSION}.yaml

Edit before applying: in scaledobject.yaml the target Deployment, namespace and Prometheus address (in scaleTargetRef and the three trigger queries); in prometheus-rule.yaml the SLO targets (3 s TTFT, 100 ms TPOT shipped), namespace and the labels your Prometheus ruleSelector picks up. Optionally add the predicted-latency-producer plugin (streamingMode: true) to the EPP; without it the rules fall back to the actual-latency histograms.

kubectl apply -f ${SLO_DIR}/kube-state-metrics.yaml
kubectl apply -f ${SLO_DIR}/prometheus-rule.yaml
kubectl apply -f ${SLO_DIR}/scaledobject.yaml

From that moment KEDA's HPA owns the replica count. The guide's warmup patch (slo-aware/decode-warmup-patch.yaml, a compile cache volume and a faster startupProbe) cut its pod-ready time from about 2 min 15 s to about 100 s on GPU; on TPU the same lever is the compile cache (Startup).

Check: kubectl get scaledobject,hpa -n ${NAMESPACE} lists both. Offline, run the law on a benchmark's per-request records:

python code/ch21_operating/slo_check.py --cpu-smoke
python code/ch21_operating/slo_check.py results.json --replicas 4

The smoke path ends cpu-smoke: OK; on real records the script exits 1 on an SLO breach.

5. Prove the loop closes

Generate bounded load from inside the cluster (standalone mode; in Gateway mode send to the Gateway instead):

kubectl run curl-load --rm -it \
  --image=curlimages/curl \
  --restart=Never \
  --namespace=${NAMESPACE} \
  --env=MODEL=${MODEL} \
  --env=EPP_SERVICE=${EPP_SERVICE} -- sh
# inside the pod:
cat > /tmp/request.json <<EOF
{
  "model": "${MODEL}",
  "prompt": "Write a detailed explanation of how continuous batching works.",
  "max_tokens": 256
}
EOF
seq 1 100 | xargs -P 16 -I{} \
  curl -sS --max-time 180 -o /dev/null -w '%{http_code}\n' \
    -X POST http://${EPP_SERVICE}/v1/completions \
    -H 'Content-Type: application/json' \
    --data-binary @/tmp/request.json

Watch from another terminal: kubectl get scaledobject,hpa -n ${NAMESPACE} -w and kubectl get deployment ${TARGET_DEPLOYMENT} -n ${NAMESPACE} -w. Queue and saturation stay near zero until a replica is really saturated; raise -P and max_tokens to exercise them.

Check: the signal rises, desired replicas rise, new replicas become ready (Q22, llm_d_epp_ready_endpoints), and the signal falls. Desired up but ready flat is actuation (TPU capacity, image, load); capacity landed and TTFT (Q01) did not recover means the wrong signal.

6. Share a fixed TPU budget across models (Kueue)

llm-d's Kueue rebalancing guide gives each model a ClusterQueue with a guaranteed floor in a shared cohort; replica pods wait at a scheduling gate until quota is free, idle models lend capacity and preemption reclaims it, while the HPAs stay untouched. Its examples account nvidia.com/gpu only; define a TPU resource flavor (google.com/tpu) and validate it before relying on it.

Check: over-budget demand shows as Pending pods with a quota message, not as failed requests.

7. Remove an autoscaler

# SLO-aware
kubectl delete -f ${SLO_DIR}/scaledobject.yaml -f ${SLO_DIR}/prometheus-rule.yaml --ignore-not-found=true

Deleting the ScaledObject hands replica control back at once. For the EPP-metric overlays, delete what kubectl kustomize ... | kubectl apply created by piping the same render to kubectl delete -f -.

Check: kubectl get hpa -n ${NAMESPACE} no longer lists the KEDA HPA.

Troubleshooting

Symptom Cause Fix
ScaledObject not Ready, or HPA targets <unknown> Trigger query does not resolve (auth, label, missing metric) Run the exact query in Prometheus; check ScalingActive with ValidMetricFound
Queue or saturation trigger always no data Flow control off Upgrade the router with the overlay values
Replicas race to maxReplicaCount on every step Warming pods serve nothing, signal stays high Scale-up stabilization near the measured TPU cold start, or the SLO-aware credit
Pool scales on someone else's traffic Trigger not pinned to namespace and pool Pin namespace and pool labels in every query
Token-aware prefill replicas never scale down Stale llm_d_epp_inflight_tokens from removed pods on EPP v0.10.0 or earlier Newer EPP image
Decode trigger reads 0 Model servers not scraped Apply the monitoring component
Load test pins maxReplicaCount Closed-loop clients Open-loop load at a fixed rate
HPA wants more replicas, pods Pending No free TPU slice of the right shape Capacity, not metrics; see Startup

References