5 min read

How I self- LLMs

How I self- LLMs

A lot of people asked me how I host my LLMs, so I'm writing it all down in one place.

Where I run them

Mostly on serverless GPU platforms. Bare metal is fine too, but installing dependencies takes a lot of time and every fresh box means a longer cold start. Bare metal also bills by the hour, while serverless bills by the second. I won't name the provider, just look up the popular serverless GPU providers.

What I use

vLLM and SGLang for inference, almost always. I use Llama Stack sometimes, but rarely, because I get a bit less token throughput with it.

Terms you need to know

  • VRAM: GPU memory. Weights, KV cache and everything else has to fit in here.
  • VRAM bandwidth: how fast the GPU reads from VRAM. An H100 SXM does about 3.35 TB/s.
  • KV cache: the keys and values for every token so far, saved so the model doesn't recompute them for each new token.
  • TPS vs throughput: TPS is tokens/sec for one request. Throughput is tokens/sec for the whole server, all requests added up.
  • TTFT: time to first token, how long you stare at the screen before anything shows up.
  • TPOT: time per output token after the first one.
  • Throughput estimate from bandwidth: on a dense model every new token reads all the weights once, so max TPS for one request ≈ bandwidth ÷ model size in VRAM.
  • Cold start: time from "no machine running" to "first response". Most of it is downloading the model and loading it into VRAM.
  • Speculative decoding: a small fast model guesses the next few tokens and the big model checks them all in one pass, so you get more tokens per step with the same output. Types:
    • EAGLE: a small draft head that reads the big model's own hidden states.
    • DFlash: a block diffusion drafter that drafts a whole block of tokens in parallel. Works in vLLM and SGLang.
    • MTP: uses the model's own multi-token prediction heads, if it was trained with them (DeepSeek, some Qwen models).
    • N-gram: copies matching text from the prompt, so you don't need a draft model at all.
  • Attention and caching:
    • PagedAttention: stores KV cache in small fixed blocks, like OS memory pages, so very little VRAM goes to waste.
    • Prefix caching: when requests start the same way (same system prompt, say), it reuses that KV cache instead of computing it again.
    • FlashAttention: does attention in chunks inside the GPU's fast on-chip memory, so it's faster and uses less VRAM.
  • Prefill and decode: prefill chews through your whole prompt in one go and decides TTFT. Decode makes one token at a time and decides TPS.
  • Quantization: storing weights in fewer bits (16 → 8 → 4) so the model takes less VRAM and runs faster. You lose a bit of quality.
  • Dense vs MoE: dense uses every parameter for every token. MoE only wakes up a few experts per token, but you still need VRAM for all of them.
  • Continuous batching: new requests join the running batch and finished ones leave at every step, so nobody waits for the whole batch to finish.

How much VRAM do you need?

Say you want to load a 26B dense model. How much VRAM does it need, and how much goes to KV cache?

Rule of thumb: 1B params at 1 byte each (8-bit) is 1 GB. So weights in GB = params in billions × bits ÷ 8.

Quant Bytes per param Weights Left for KV cache on one H100 80GB
4-bit 0.5 13 GB ~55 GB
8-bit 1 26 GB ~42 GB
16-bit 2 52 GB ~16 GB
32-bit 4 104 GB doesn't fit, needs 2 GPUs

KV cache goes on top of that. vLLM doesn't ask how much KV cache you want. It takes 90% of VRAM by default (--gpu-memory-utilization 0.9, so 72 GB on an H100), loads the weights, keeps a few GB for activations and gives whatever's left to KV cache. That's the last column.

How much KV cache does one request need? Per token it's:

KV cache per token = 2 (K and V) × layers × KV heads × head dim × bytes per value

All of these are in the model's config.json (num_hidden_layers, num_key_value_heads, head_dim). Say our 26B model has 48 layers, 8 KV heads and head dim 128, with KV cache in FP16 (2 bytes):

2 × 48 × 8 × 128 × 2 = 196,608 bytes ≈ 0.2 MB per token

So a 4k-token request needs about 0.8 GB and a 32k one needs about 6.4 GB. KV cache precision is separate from weight quant, by the way, and --kv-cache-dtype fp8 cuts it in half.

For 8-bit weights and one 32k request: 26 + 6.4 + a few GB overhead ≈ 35 GB.

With the 4-bit version on an H100 I get around 200 TPS, which lines up with the bandwidth math: 3,350 GB/s ÷ 13 GB ≈ 258 TPS max for one request. With speculative decoding I get around 800 TPS. That beats the bandwidth limit because the big model checks several drafted tokens each time it reads the weights.

General formula

VRAM (GB) ≈ weights + KV cache + overhead

weights  = total params (B) × bits ÷ 8
KV cache = KV per token × context length × parallel requests
overhead ≈ 10-20% of weights (activations, CUDA graphs)

Dense: every token uses all the params, so the full size decides both VRAM and speed.

max TPS (one request) ≈ bandwidth ÷ weights

MoE: you still load every expert, so VRAM goes by total params. Speed goes by active params, since each token only reads the experts it gets routed to.

weights               = total params (B) × bits ÷ 8
max TPS (one request) ≈ bandwidth ÷ (active params (B) × bits ÷ 8)

Example: Qwen3-30B-A3B has 30B total and 3B active params. At 4-bit the weights take 15 GB, same as a 30B dense model, but each token only reads about 1.5 GB, so it's way faster. KV cache works the same as dense because it depends on the attention layers, not the experts.

Cut cold start with Run:ai Model Streamer

One tip for vLLM: loading the model into the GPU takes a lot of time, and that's most of your cold start. With vLLM's built-in loader it takes about 8 minutes to load the full model, which is a bit slow. With Run:ai Model Streamer it loads in about 30 seconds. Less cold start and profit.

pip install "vllm[runai]"
vllm serve <your-model> --load-format runai_streamer

On serverless you pay by the second, so that's 7.5 minutes you don't pay for on every cold start.

Batching: how many requests vLLM can serve in parallel

In layman terms, batching is how many requests vLLM can serve at the same time.

Decode is bottlenecked by memory bandwidth. Every step the GPU reads all the weights from VRAM anyway, and reading them once to make the next token for 50 requests costs almost the same as doing it for 1. So total throughput goes way up as you add requests, and each request only gets a little slower.

What stops you is KV cache space, since every request needs its own. With 8-bit weights we had ~42 GB left:

  • 4k-token requests (0.8 GB each): about 50 at once
  • 32k-token requests (6.4 GB each): about 6 at once

vLLM prints this on startup, something like Maximum concurrency for 32768 tokens per request: 6.5x. Once KV cache is full, new requests wait in the queue. PagedAttention helps a lot here, because less wasted KV cache means more requests fit.

Which one to pick

Use SGLang, vLLM or Llama Stack, whatever fits your needs. If you don't want this much headache, desktop apps like LM Studio, Unsloth Studio or Ollama are fine. They're not as optimized though, and you can't squeeze every bit of compute out of the GPU like you can with vLLM, especially when lots of requests come in at once.

Also, I'm looking for new opportunities right now. If you have something, get in touch.