Does asking for top-k logprobs add real compute cost per token, or only bytes on the wire?
Explain what happens at the model head when a caller requests top-k logprobs per token. Identify what is essentially free, what genuinely costs something, and how that cost scales with k and with streaming.
Logprobs are near-free on the GPU because the softmax already exists; the real cost is bytes on the wire, JSON serialization per token, and amplified streaming latency.
Imagine a chef who already chops twenty vegetables for every dish but only puts five on the plate. If you ask to see all twenty, the chopping work was already done; the only extra effort is wrapping the extras and shipping a heavier box to your table. That is what logprobs feel like at the model head. Every time the model picks the next word, it has already produced a probability score for every possible candidate word whether you ask for them or not. Pulling out the top few is a quick partial sort. What actually costs something is packing those extra (word, score) pairs into JSON for every single streamed word and sending a fatter package over the network. The bigger your k, the heavier each package, and on a word-by-word stream that adds up to real bandwidth and packaging time.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: softmax already exists + top-k is a free sort + payload grows linearly in k + streaming amplifies serialization + practical guidance on when to disable.
Real products, models, and research that use this idea.
- OpenAI Chat Completions exposes top_logprobs up to 20 and bills logprobs at an output-token-equivalent rate on most tiers, reflecting the serialization and wire load.
- Anthropic Claude Opus 4.7 and Sonnet 4.6 surface logprobs through a per-token logprobs field in streamed responses, with the same per-event payload growth pattern.
- Together AI and Fireworks both document logprobs as a payload-cost feature and recommend keeping k small on streaming endpoints for latency reasons.
- DeepSeek V4 API returns logprobs but advises non-streaming or batched delivery when k exceeds 5, citing serialization overhead per SSE event.
- Calibration tools like Inspect AI and EleutherAI's lm-eval-harness use logprobs only at evaluation time precisely because the cost profile is wrong for production serving.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhere exactly does the top-k extraction happen, and is it on the GPU or the CPU?
QHow does speculative decoding interact with logprobs requests?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Saying logprobs cost extra GPU compute because the model has to 'compute probabilities for every token.' It already does. The softmax is part of every forward pass; logprobs are a free side effect.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.