Skip to main content
CRUCIBLE
Legacy Reference Archive: This 44-chapter book reference has been distilled into Academy A01 (8 Executable Modules) with Tier-Adaptive Productive Failure, Kore/Puck voice, and live Firecracker labs.
Open Academy A01 →
COURSE 0 · SERVER BUILDING & LIFECYCLE MASTERY

Zero-to-Production Linux, Containers, Networking & Recovery

PROGRESS: 0 / 72 (0%)0/44L · 0Q · 0VM
CH 10 · PART III · AI, MCP, INFERENCE & PLATFORMS (CH 09–13) · 912 WORDS (5 MIN)

10 Model serving GPU sizing and performance

Write down model family, license, quality requirements, context lengths, expected output lengths, request arrival pattern, concurrency, privacy needs, latency target, and budget.

FULL WAR-ROOM →
INTERACTIVE AI & GPU BOUNDARY · CLICK ANY STAGE TO INSPECT

Production AI Stack: Gateway Budget -> Hybrid RAG ACL -> MCP Guard -> GPU KV-Cache

How production teams bound token spend, block cross-tenant retrieval leaks, and prevent CUDA OOM.

fetchescallsservesLLM GatewayTimeouts · Token CapsPre-Filtered RAGWHERE tenant_id = ?MCP Tool GuardAllowlist · SSRF BlockGPU KV-CacheTTFT · Admission Cap
SELECTED LAYER · LLM GATEWAY
Enforces per-tenant rate limits, strict request timeouts, and JSON schema validation around model calls.
Common failure: Unbounded LLM calls hanging API workers or running up runaway token invoices during retry storms.
$ curl -s http://127.0.0.1:8000/health

Outcome: decide whether to use hosted inference or operate a model server, then measure a candidate correctly. Prerequisites: application deployment, observability, and AI evaluation. Environment: a compatible local machine or explicitly budgeted GPU host. Status: specialist procedure; no external GPU allocation or paid inference is provisioned automatically.

Begin with the workload

Write down model family, license, quality requirements, context lengths, expected output lengths, request arrival pattern, concurrency, privacy needs, latency target, and budget. An interactive assistant and an overnight batch summarizer have different priorities. A throughput winner at heavy batching may be a poor low-latency choice.

Hosted inference transfers much infrastructure work to a provider but adds provider policy, availability, pricing, data handling, and rate-limit considerations. Self-hosting offers control but makes you responsible for hardware compatibility, model artifacts, security, capacity, and uptime. Include engineering and idle capacity in the comparison.

Estimate memory before renting hardware

A rough weight-memory estimate is parameter count multiplied by bytes per parameter. Seventy billion parameters at two bytes per parameter require about 140 billion bytes for weights alone. At one byte per parameter the rough weight storage halves. Quantization metadata, runtime workspaces, activations, and cache add overhead.

The KV cache grows with architecture, sequence length, and active requests. Long contexts at high concurrency can exhaust memory even when weights fit. A model that starts successfully may fail under the intended load. Calculate a preliminary budget, then measure peak memory with a representative workload and headroom.

GPU names alone are insufficient. Record VRAM capacity, accelerator count, interconnect, host memory, driver, runtime, engine version, and model format. Tensor parallelism distributes model work across devices and adds communication costs. Do not assume a model fits a single accelerator because a copied command says so.

Choose an engine experimentally

vLLM, SGLang, llama.cpp, and other serving systems target different hardware and workload tradeoffs. Ollama can be useful in local or controlled deployments; suitability depends on the contract rather than a blanket ban. Start with engines supporting your actual model and hardware, then compare measured behavior.

Use a versioned container or reproducible environment. Verify model license and access requirements. Download from a trusted source and record the exact artifact/version. Avoid executing arbitrary model repository code without review. Bind the first test server to loopback or a private interface, and place authenticated application controls in front of any public access.

A serving procedure

  1. Verify driver/runtime compatibility and available memory.
  2. Choose a supported small model for the first run and record its source.
  3. Install or run the selected versioned engine.
  4. Bind privately, set the model and context/concurrency limits, and start it.
  5. Verify readiness and one bounded generation request.
  6. Run a quality baseline and latency test.
  7. Increase load gradually while observing memory and errors.
  8. Record the configuration and shut down billable resources when finished.

Use the engine's current flags rather than copying an old universal command. For vLLM, begin with its [serving documentation](https://docs.vllm.ai/en/latest/serving/online_serving/). An API-compatible endpoint does not necessarily implement every feature or error behavior of another provider; test what your client uses.

Measure the right quantities

Time to first token measures the initial wait. Inter-token latency affects the reading experience after generation starts. End-to-end latency includes queueing and full output. Throughput counts completed work per unit time under a stated workload. Error rate, cancellation behavior, and quality belong in the same report.

Record prompt/output distributions, warm versus cold state, concurrency, request rate, sampling parameters, cache settings, and repetitions. A benchmark without these fields cannot support a general “engine A is faster” claim. Use the same model and comparable settings; explain any differences.

Optimization tradeoffs

Continuous batching can improve utilization by scheduling work across requests. Prefix caching can reuse work for shared prefixes, but benefit depends on reuse and eviction. Quantization reduces storage and compute requirements in some settings, with quality and compatibility tradeoffs to measure. Flash-attention implementations and hardware support vary.

Speculative decoding uses proposed tokens and verification to reduce generation cost or latency under suitable conditions. It is not limited in principle to temperature zero. Gains depend on method, acceptance, workload, and hardware; extra work can reduce performance in some regimes. Follow the selected implementation's supported combinations and benchmark them. [vLLM speculative decoding](https://docs.vllm.ai/en/latest/features/speculative_decoding/index.html) explains methods and limitations.

Tune one factor at a time. Retain a quality baseline and rollback configuration. Faster generation that violates the output contract is not an improvement. Avoid changing model, precision, engine, prompt, and concurrency simultaneously if you need to identify the cause of a result.

Cost and operational controls

Estimate monthly cost from provisioned time, utilization, storage, transfer, monitoring, and support effort. For hosted APIs, include both input and output tokens, retries, embeddings, and ancillary requests. Compare cost per successful task at the required quality, not just headline token prices.

Enforce admission limits and per-tenant budgets before accepting expensive work. Handle cancellation so abandoned requests do not consume unbounded compute. Scale-to-zero reduces idle compute but may add model-loading delay and storage/transfer costs. Keep a warm instance only when the latency benefit justifies its cost.

Exit exercise

Produce a benchmark report with exact versions, hardware, workload, quality results, latency percentiles, throughput, failure rate, peak memory, and cost assumptions. Compare two configurations and defend a choice. Demonstrate stopping the service and removing only the resources allocated for the test. This evidence is the qualification for operating a model server, not the act of renting a GPU.

ACTIVE-RECALL MASTERY CHECKPOINT · CH 10

Lock in what you just learned (3 quick questions)

PASS 2/3 FOR +30 XP
Q1.Before renting expensive GPU instances for LLM serving, what must you calculate first?
Q2.Why distinguish Time-To-First-Token (TTFT) from Inter-Token Latency (ITL / throughput) when benchmarking inference engines?
Q3.How does continuous batching and prefix caching (e.g. in vLLM) improve GPU unit economics?
Answered 0 / 3