Skip to content

Predicted-latency routing on TPU

Use this guide when output lengths vary by orders of magnitude (agent tool loops, long-horizon coding, reasoning-heavy decode) and request counts or token heuristics misjudge load: a replica decoding one very long trace looks idle by request count while it stalls new prefills. The router runs online-trained xgboost sidecars that predict each request's TTFT and TPOT on every candidate pod from live state, routes on the predictions and can enforce per-request SLOs. It replaces the optimized baseline's static peakPrefillThroughput gate, which needs offline calibration per TPU and model. Skip it for heterogeneous pools: the predictor assumes every pod has the same hardware shape. Chapter 21 covers the SLO signals it produces.

Prerequisites

  • GKE TPU node pools for one configuration (both community, INFRA_PROVIDER=gke):

    ACCELERATOR_TYPE Model in the guide's table Layout
    tpu/v6 Qwen/Qwen3-32B 2 replicas x 8 chips (2x4, TP=8)
    tpu/v7 Qwen/Qwen3-32B 2 replicas x 4 chips (2x2x1, TP=8)

    The TPU overlays reuse the optimized-baseline model servers unchanged (40,960-token native context). On TPU7x the optimized baseline's tpu/v7 overlay serves Qwen/Qwen3.5-397B-A17B-FP8, so read the served model from /v1/models after step 3 and set MODEL to it. - A CPU node pool with nodes of at least 32 vCPUs (for example n2-standard-32): the router pod's four containers (epp, envoy-proxy, training-server, prediction-server-1) request 18 vCPUs and 24 GiB together. - The repository, CRDs, namespace and Secret from the quickstart, steps 1 to 3.

Steps

1. Choose a scheduling mode and set the environment

SLO_AWARE Values file Trains Behavior
false (default) router/predicted-latency.values.yaml ttft (end-to-end latency) Routing only; works with streaming and non-streaming clients
true router/predicted-latency-slo.values.yaml ttft and tpot Enforces x-llm-d-slo-ttft-ms and x-llm-d-slo-tpot-ms; every request must be sent with "stream": true
export REPO_ROOT=$(realpath $(git rev-parse --show-toplevel))
export GUIDE_NAME=predicted-latency-routing
export NAMESPACE=llm-d-predicted-latency
export MONITORING=false
export MONITORING_VALUES=
export SLO_AWARE=false
export ACCELERATOR_TYPE=tpu/v6 # tpu/v6 or tpu/v7
export MODEL_SERVER=vllm
export INFRA_PROVIDER=gke
export MODEL=Qwen/Qwen3-32B
source ${REPO_ROOT}/guides/env.sh
export ROUTER_BASE_VALUES="${REPO_ROOT}/guides/recipes/router/base.values.yaml"
export ROUTER_VALUES="${REPO_ROOT}/guides/${GUIDE_NAME}/router/predicted-latency.values.yaml"
# SLO_AWARE=true: .../router/predicted-latency-slo.values.yaml

Check: ls ${ROUTER_VALUES} finds the file.

2. Deploy the router

helm install ${GUIDE_NAME} \
  ${ROUTER_STANDALONE_CHART} \
  -f ${ROUTER_BASE_VALUES} \
  ${MONITORING_VALUES} \
  -f ${ROUTER_VALUES} \
  -n ${NAMESPACE} --version ${ROUTER_CHART_VERSION}

Both values files enable the predictor sidecars (router.latencyPredictor.enabled: true) and select pods labelled llm-d.ai/guide=optimized-baseline.

Check: kubectl get pods -n ${NAMESPACE} shows the EPP pod Running with all four containers ready.

3. Deploy the model servers and send a request

kubectl apply -n ${NAMESPACE} \
  -k ${REPO_ROOT}/guides/${GUIDE_NAME}/modelserver/${ACCELERATOR_TYPE}/${MODEL_SERVER}/${INFRA_PROVIDER}/
export IP=$(kubectl get service ${GUIDE_NAME}-epp -n ${NAMESPACE} -o jsonpath='{.spec.clusterIP}')
kubectl run curl-test --rm -i --restart=Never \
  --image=${CURL_TEST_IMAGE} \
  --namespace="${NAMESPACE}" \
  --env="IP=${IP}" \
  --env="MODEL=${MODEL}" \
  -- /bin/sh -c 'curl -sS -X POST "http://${IP}/v1/completions" -H "Content-Type: application/json" -d "{\"model\": \"${MODEL}\", \"prompt\": \"How are you today?\"}"'

Check: a non-streaming JSON completion returns with "object":"text_completion". If the predictor is unreachable the router silently falls back to heuristics and requests still succeed, so step 4 is the real check.

4. Train the predictor and confirm it is used

Send 200 requests, 10 at a time, with output lengths from 16 to 128 tokens:

kubectl run traffic-test --rm -i --restart=Never \
  --image=${CURL_TEST_IMAGE} \
  --namespace="${NAMESPACE}" \
  --env="IP=${IP}" \
  --env="MODEL=${MODEL}" \
  -- /bin/sh -c 'for i in $(seq 1 200); do
      curl -sS -o /dev/null -w "%{http_code}\n" -X POST "http://${IP}/v1/completions" \
        -H "Content-Type: application/json" \
        -d "{\"model\": \"${MODEL}\", \"prompt\": \"Request ${i}: explain how an LLM router picks a model server.\", \"max_tokens\": $((16 * (i % 8 + 1)))}" &
      [ $((i % 10)) -eq 0 ] && wait
    done | sort | uniq -c'

EPP_POD=$(kubectl get pods -n ${NAMESPACE} -o name | grep "^pod/${GUIDE_NAME}-epp-" | head -1 | cut -d/ -f2)
kubectl get --raw "/api/v1/namespaces/${NAMESPACE}/pods/${EPP_POD}:8000/proxy/metrics" \
  | awk '/^training_samples_count\{model="ttft"/ {ttft += $NF} /^training_samples_count\{model="tpot"/ {tpot += $NF} END {printf "training samples: ttft=%d tpot=%d\n", ttft, tpot}'
kubectl get --raw "/api/v1/namespaces/${NAMESPACE}/pods/${EPP_POD}:8001/proxy/status"; echo

Check: 200 200 from the traffic loop; roughly 175 to 190 ttft training samples (10% are held out as a test set; tpot stays 0 in routing-only mode); the prediction server's last_model_load advances after the traffic. "is_ready": true alone proves nothing: at startup it serves a placeholder model that predicts about 10 ms for everything, replaced once a model has 10 samples, within about 40 s. With MONITORING=true, llm_d_epp_request_predicted_ttft_seconds_count grows with llm_d_epp_request_ttft_seconds_count:

kubectl get --raw "/api/v1/namespaces/${NAMESPACE}/services/${GUIDE_NAME}-epp:9090/proxy/metrics" \
  | grep -E '^llm_d_epp_request_(predicted_)?(ttft|tpot)_seconds_count' || true

5. Optional: send a request with SLOs (SLO_AWARE=true)

kubectl run slo-test --rm -i --restart=Never \
  --image=${CURL_TEST_IMAGE} \
  --namespace="${NAMESPACE}" \
  --env="IP=${IP}" \
  --env="MODEL=${MODEL}" \
  -- /bin/sh -c 'curl -sS -N -o /dev/null -w "HTTP %{http_code}\n" -X POST "http://${IP}/v1/completions" \
    -H "Content-Type: application/json" \
    -H "x-llm-d-slo-ttft-ms: 2000" \
    -H "x-llm-d-slo-tpot-ms: 100" \
    -d "{\"model\": \"${MODEL}\", \"prompt\": \"Explain the difference between prefill and decode.\", \"max_tokens\": 128, \"stream\": true}"'

When no pod is predicted to meet the SLOs, a sheddable request (priority below 0, set through an InferenceObjective named in x-llm-d-inference-objective) is rejected at admission; priority 0 or above goes to the pod with the smallest predicted deficit. Strip client-supplied x-llm-d-* and x-slo-* headers at your authenticated ingress and inject authoritative ones.

Check: HTTP 200.

6. Watch it under load

llm_d_epp_request_predicted_ttft_seconds should converge with llm_d_epp_request_ttft_seconds after warm-up, and llm_d_epp_request_slo_violation_total should stay near zero except under real saturation (Q07 in Observability).

Check: predictions and actuals track each other over a rolling window.

7. Clean up

kubectl delete -n ${NAMESPACE} -k ${REPO_ROOT}/guides/${GUIDE_NAME}/modelserver/${ACCELERATOR_TYPE}/${MODEL_SERVER}/${INFRA_PROVIDER}
helm uninstall ${GUIDE_NAME} -n ${NAMESPACE}
kubectl delete namespace ${NAMESPACE}

Check: the namespace is gone.

Troubleshooting

Symptom Cause Fix
Prediction metrics empty Prediction server unreachable; router uses a heuristic score Sidecar readiness, PREDICTION_SERVER_URL, predicted-latency-producer errors in the EPP logs
Constant predictions right after start Placeholder model Send traffic until 10 samples per model; wait up to 40 s
Predicted and actual TTFT drift apart streamingMode does not match the traffic, or the workload changed Use the matching values file
High TPOT SLO violations at low QPS streamingMode: false, so TPOT is not trained SLO-aware values file and streamed requests
Router pod Pending No CPU node with 32 vCPUs Add such a node pool
Test requests fail with a model error on TPU7x MODEL differs from the served model Set MODEL from /v1/models

References