Open-Source & Local LLMs
The model
- An open-weight model ships its weights as a download. Its license, not the word open, says what you may do.
- Memory is weights plus KV cache plus overhead. The KV cache grows with context and with every user.
- Decode reads every weight for each token, so memory bandwidth sets its speed and batching is nearly free.
- Pick the runtime by concurrency. Ollama and llama.cpp serve one user. vLLM and SGLang batch many users.
- Every runtime speaks the OpenAI-compatible API, so switching is mostly a base URL change.
Open models & licenses
what you can download, and what you may do with itOpen-weight, open source, proprietary
TrapMost models called open source are only open-weight. Llama's weights are free to download, but its license adds use limits.
Read a model license
TrapCustom licenses reach your fine-tunes. A Llama fine-tune's name must start with Llama.
Self-host or hosted API
when owning the GPU pays offSelf-host or use a provider
TipStart hosted. The weights are open, so you can move the same model in-house later without rewriting prompts.
TrapOwned GPUs only save money while they stay busy. An idle GPU bills the same.
Cost per million tokens
TrapMeasure tokens per second yourself, at your p95 latency target. A vendor's peak number is higher than you'll get.
Run a model locally
one user, one machineOllama, llama.cpp and LM Studio
ollama run llama3.2export OPENAI_BASE_URL=http://localhost:11434/v1 llama-server -m model.gguf -ngl 32 --port 8080TipOllama ships each model with its chat template and defaults, so you don't format prompts by hand.
TrapAll three are built for one user. llama-server batches requests, but its throughput stays flat as load grows.
GGUF files
Q4_K_M means a 4-bit k-quant, medium size.TrapGGUF is for inference only. You convert to it from Hugging Face weights, and you never train in it.
Asked in interviews
AskedWhat is GGUF, and where does it fit?Fix slow local responses
load_duration, prompt_eval_duration and eval_duration in Ollama's response.ollama ps100% GPU is healthy. A CPU/GPU split is slow.OLLAMA_FLASH_ATTENTION=1 OLLAMA_KV_CACHE_TYPE=q8_0 ollama serveTrap100% CPU on a GPU machine means the GPU lacked free VRAM, or the runtime never found it.
Asked in interviews
AskedHow would you troubleshoot slow responses from a local LLM?On-device inference
TipYou gain privacy, offline use and no per-token bill.
VRAM & KV cache math
will it fit, and for how many usersVRAM to load a model
Q4_K_M about 0.6.Trap4-bit isn't exactly 0.5 bytes. Files also store scales and keep some tensors at higher precision.
Asked in interviews
AskedHow do you estimate how much VRAM a model needs just to load it?The KV cache
TrapQuantizing the weights doesn't shrink the KV cache. It stays FP16 by default.
Shrink the KV cache
vllm serve <model> --kv-cache-dtype fp8vllm serve <model> --max-model-len 32768TrapKV compression fails at long context first. Test quality on your longest prompts.
Dense vs mixture-of-experts
vllm serve <moe-model> --enable-expert-parallel --data-parallel-size 8TipOn one GPU, llama.cpp can keep attention on the GPU and the experts in system RAM.
Pick a model size
TipStart one size above your guess, then step down until quality breaks. The last size that passed wins.
Asked in interviews
AskedHow do you pick a model size for a given task and hardware budget?Quantization
fewer bits per weight, for memory and speedWhat quantization does, and how far to go
Q4_K_M, unless your eval set shows a real drop.lm_head at higher precision.TrapQuality holds to about 4 bits, then drops fast. Code and math show the damage before chat does.
GGUF, AWQ, GPTQ or FP8
vllm serve <model> --quantization fp8FP8. It needs Hopper, Ada or newer.TrapFP8 only halves memory. A 70B model still needs two large cards.
Prompts, sampling & JSON
get the output you asked forInstruct models and chat templates
-instruct or -it in the name.apply_chat_template with add_generation_prompt=True .TipChat endpoints apply the template for you. Raw completion endpoints don't.
TrapWrong turn markers fail quietly. The model ignores the system prompt, runs past its stop, or breaks tool calls.
Sampling settings
0 for extraction, 0.7 for chat. Set it first.top_p at 0.9 to 0.95 or top_k at 40.TrapTemperature 0 is greedy, not reproducible. Batch size and kernel order can still change the output.
Reliable JSON and tool calls
response_format in vLLM or a GBNF grammar in llama.cpp.vllm serve <model> --enable-auto-tool-choice --tool-call-parser hermestool_choice to required or a named tool.TrapA valid shape isn't correct content. Still validate the values, and retry on failure.
Open reasoning models
vllm serve <model> --reasoning-parser deepseek_r1max_tokens and the context limit. Thinking can run thousands of tokens.TrapFollow the vendor's sampling settings. Greedy decoding tends to loop.
Serve many users
batch requests on a GPU serverPick a runtime
TrapDon't judge by one request. llama.cpp looks fine alone, then time to first token climbs as users queue.
Stand up an OpenAI-compatible server
/v1/chat/completions and /v1/models, with OpenAI's request and response shapes.vllm serve <model> --served-model-name gpt-4o-mini --api-key local-keyexport OPENAI_BASE_URL=http://localhost:8000/v1 export OPENAI_API_KEY=local-key curl -H "Authorization: Bearer local-key" localhost:8000/v1/models TipCompatible means the same shape, not every feature. Tool calls, structured output and logprobs vary by runtime.
Trap/ needs a chat template. Pass --chat-template if the model ships none.
Continuous batching and PagedAttention
Each letter is a request in one of two batch slots. Static batching leaves a slot idle until the longest request ends. Continuous batching refills it at once.
TrapKV-cache memory caps the batch, not compute.
Prefix caching
vllm serve <model> --enable-prefix-cachingOn by default in vLLM V1.TrapIt matches from token 0. One changed character early invalidates everything after it.
Latency or throughput
vllm serve <model> --tensor-parallel-size 2 --max-num-seqs 16vllm serve <model> --max-num-seqs 256 --gpu-memory-utilization 0.95vllm serve <model> --enable-chunked-prefillTrapFrequent preemptions mean you pushed the batch too far. Each evicted request gets recomputed.
Speculative decoding
TipIt's lossless. Verification keeps the output distribution the same, so only speed changes.
Asked in interviews
AskedWhat is speculative decoding, and when does it actually help?Fine-tunes & adapters
train on your data, then serve itFine-tune with LoRA or QLoRA
TrapFormat the examples in the model's chat template, and stop when a held-out eval stops improving.
Adapters or merged weights
vllm serve <base> --enable-lora --lora-modules sql=/adapters/sql TrapAn adapter only works on its exact base checkpoint, so pin that version.
Hot-swap LoRA adapters
VLLM_ALLOW_RUNTIME_LORA_UPDATING=True vllm serve <base> --enable-lora/v1/load_lora_adapter . Clients then send that name as model.vllm serve <base> --enable-lora --max-loras 4 --max-lora-rank 32TrapGuard the load endpoint. It reads any path you hand it.
Asked in interviews
AskedHow do you deploy and hot-swap multiple LoRA adapters at serving time?Scale across GPUs
split a model across GPUs and plan capacitySplit work across GPUs
vllm serve <model> --tensor-parallel-size 8vllm serve <model> --tensor-parallel-size 8 --pipeline-parallel-size 2TrapTP size must divide the attention head count. PP needs enough requests to keep every stage busy.
Asked in interviews
AskedExplain tensor parallelism versus pipeline parallelism for multi-GPU serving. When do you use each?AskedWhy are prefill and decode so different, and how does that shape batching and hardware choices?AskedWalk me through disaggregated prefill and decode serving, and why frontier stacks separate them.Plan capacity and benchmark
vllm bench serve --model <model> --dataset-name random --request-rate 8TrapReplayed prompts hit the prefix cache and inflate results. Turn it off unless production shares prefixes.
Evaluate, ship & monitor
quality tests, rollouts and platform designTest a local model's quality
TrapA point or two of quality loss is fine. A 10% invalid-JSON rate is not.
Monitor a self-hosted model
curl -s localhost:8000/metrics TrapAlert on latency percentiles per phase, never on averages.
Pin and roll out model versions
vllm serve <model> --revision <hash> --served-model-name assistantTrapHub tags can move. A changed chat template alters output with no weight change.
Air-gapped deployment
export HF_HUB_OFFLINE=1 export TRANSFORMERS_OFFLINE=1 export DO_NOT_TRACK=1TrapBlock egress at each node. A runtime that retries a download passes staging, then hangs inside the gap.
Many models, many regions
TrapA router without offline evals quietly sends everything to the biggest model.
Nothing matches. Try a shorter word, or clear the search.
This sheet stays free. With Pro, you can:
- Every answer on this sheet. Read the full answer to all 55 questions it links, not just the 7 free ones.
- My sheet. The cards you star and the ones you miss in Quiz me, from every sheet, on one page to quiz and print.
- PDFs. Download this sheet and My sheet, laid out for A4, with every question a link to its answer.
- The rest of Pro. Every answer in the question library, and 1,000 AI credits a month.