Sub topic 14
Serving Large Language Models and GPUs
Assume you know Kubernetes pods, Deployments, Services, YAML, and basic KServe InferenceService resources. You should also understand that a model server exposes an HTTP API and that a GPU is a schedulable Kubernetes resource.
Why LLM serving is different
A large language model (LLM) generates text one token at a time. Its weights may require many gigabytes of GPU memory. During generation, the server also stores attention data called the key-value cache, or KV cache, for each active request. Longer prompts and more simultaneous requests consume more memory.
An LLM runtime must therefore do more than load a file and answer a request. It may provide:
- GPU-aware loading and tensor parallelism.
- Continuous batching, which combines active requests between generated tokens.
- Token streaming.
- Limits for prompt length, output length, and concurrent requests.
- A protocol such as OpenAI-compatible HTTP or the V2 Open Inference Protocol.
KServe supplies the Kubernetes control plane around this runtime. The runtime still determines which model formats, request fields, quantization methods, and GPU types are supported.
Requesting a GPU
A predictor requests GPUs through Kubernetes resource limits. The NVIDIA device plugin must be installed on the cluster, and the node must have a compatible driver and GPU. Without these components, a manifest can be accepted while the pod remains pending.
apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
name: text-generator
spec:
predictor:
minReplicas: 1
maxReplicas: 2
model:
modelFormat:
name: huggingface
storageUri: s3://example-models/llama-model
resources:
requests:
cpu: "4"
memory: 16Gi
nvidia.com/gpu: "1"
limits:
cpu: "8"
memory: 32Gi
nvidia.com/gpu: "1"This manifest assumes that a compatible Hugging Face or vLLM serving runtime is installed and selected for the huggingface model format. The exact runtime configuration depends on the KServe distribution. Some installations use a ServingRuntime resource to define the container image and command explicitly.
The GPU request is also a scheduling constraint. Kubernetes places the pod only on a node with an available GPU. Node selectors and taints can further restrict placement:
nodeSelector:
accelerator: nvidia-a10
tolerations:
- key: nvidia.com/gpu
operator: Exists
effect: NoScheduleUse the labels and taints that exist in your cluster. Do not copy these values without checking the nodes.
Scaling and deployment choices
For interactive LLM traffic, keep at least one warm replica when latency matters. Scale-to-zero saves money but causes a cold start while the image, model, and GPU initialize. That delay can last minutes for a large model.
Concurrency is a useful first scaling signal, but it is incomplete. Two requests can have very different prompt lengths and output lengths. Measure request latency, tokens per second, queue time, GPU memory, and GPU utilization before choosing a target.
| Decision | Prefer this when | Main cost |
|---|---|---|
| One GPU per replica | The model fits on one GPU | Lower parallel capacity |
| Tensor parallelism | The model needs multiple GPUs | More complex placement and coordination |
| Quantization | Small memory footprint matters | Possible quality or compatibility loss |
| RawDeployment | You need predictable pod and networking behavior | Fewer serverless conveniences |
A typical request path
Confirm the runtime’s request format before testing. A V2 request commonly contains an inputs array, while an OpenAI-compatible runtime commonly expects fields such as model, messages, and stream. The URL and headers are runtime-specific even when KServe manages the service.
Operating an LLM service
Inspect scheduling and startup failures first:
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl get inferenceservice text-generatorLook for insufficient GPU capacity, incompatible CUDA drivers, model download failures, and out-of-memory errors. Set model and tokenizer revisions explicitly where the runtime supports it. This makes a rollout reproducible instead of silently downloading a changed model.
Use a canary revision when changing a model, prompt template, quantization setting, or runtime image. Send a small percentage of traffic to the new revision, compare latency and output quality, then promote it or return traffic to the previous revision.
Exercise
Why might an LLM predictor with minReplicas set to 0 provide poor user experience even when autoscaling works correctly?
Show answer
The first request must wait for a pod, GPU allocation, model download, and runtime initialization. Keep a warm replica when predictable latency is more important than the savings from scale-to-zero.