LLM & Parallel Language Inference Datasheet v3.0¶
A causal autoregressive LLM is not a sentence generator. It is a machine that repeatedly transforms a sequence of vector states into a distribution over the next token.
1. Canonical computational graph¶
With cache:
The interface usually exposes only the logits → sampler stage. Everything else determines most of the model's capability and cost.
PART I — REPRESENTATION¶
2. Tokenizer¶
Fundamental variables¶
| Variable | Tag | What it controls |
|---|---|---|
| Vocabulary size \(V\) | MODEL |
dimensionality of the output distribution |
| Tokenization algorithm | MODEL |
sequence granularity |
| Special tokens | MODEL |
BOS/EOS/FIM/chat control |
| Chat template | MODEL/PIPE |
actual serialization of the conversation |
Physical relationship¶
For the same semantic information:
but a larger vocabulary increases LM-head/embedding cost and changes the statistical geometry of the tokens.
Failure surface¶
A correct model with the wrong chat template can look stupid, repetitive, or disobedient even when sampling is configured correctly.
3. Embeddings and the residual stream¶
Simplified initial input:
The residual stream passes through the blocks:
The exact architecture may be pre-norm or post-norm, use RMSNorm or LayerNorm, and employ different residual arrangements.
PART II — POSITION AND ATTENTION¶
4. RoPE¶
Rotary Position Embeddings apply position-dependent rotations to Q/K.
Conceptually:
Attention then becomes position-sensitive through the rotated inner product.
Associated knobs¶
- RoPE theta/base;
- frequency scaling;
- linear scaling;
- YaRN factors;
- original context length;
- extension factor.
Rule¶
Being able to allocate 128k tokens does not prove the model preserves equivalent quality at 128k.
5. Attention¶
For each layer:
where \(M\) contains the causal mask and any additional biases.
The attention equation applies per query head: head \(h\) uses \(Q_h\) and the shared \(K_{g(h)},V_{g(h)}\), where \(g(h)\) maps it to its KV head. For contiguous equal-sized GQA groups with zero-based indices, \(g(h)=\lfloor h/(n_q/n_{kv})\rfloor\); this grouping assumes \(n_q\) is divisible by \(n_{kv}\).
Typical shapes¶
6. MHA, GQA, MQA¶
Multi-Head Attention¶
Grouped-Query Attention¶
Multiple query heads share K/V.
Multi-Query Attention¶
Direct effect¶
Among other things, GQA/MQA are mechanisms for reducing persistent state during decode.
7. Multi-head Latent Attention — MLA¶
Instead of storing full K/V tensors per head, the architecture compresses states into smaller latents and reconstructs/projects them as needed.
Conceptually:
This reduces KV-cache pressure. DeepSeek-V3 is an important reference for this family.
Do not automatically apply the GQA KV formula to MLA models without checking the actual architecture/backend.
PART III — FFN AND MoE¶
8. Feed-Forward Network¶
A common gated formulation:
In modern Transformers, FFNs account for a large fraction of both parameters and memory traffic.
9. Mixture of Experts¶
One schematic routed-MoE variant is shown below. Router activation, normalization of selected weights, and shared experts depend on the architecture; this is not an exact specification of every MoE.
Router:
Selection:
Output:
Three mandatory numbers¶
| Metric | Meaning |
|---|---|
| \(N_{total}\) | stored parameters |
| \(N_{active}\) | parameters actually executed per token |
| \(k\) | experts selected per token |
Operational rule¶
but:
An MoE can be computationally “3B active” while still requiring storage equivalent to tens of billions of parameters.
PART IV — LOGITS¶
10. LM head¶
Final state:
Logits:
Before sampling, these are not yet probabilities.
Softmax:
PART V — LOGIT PROCESSING AND SAMPLING¶
11. Temperature¶
| Region | Mathematical effect |
|---|---|
| \(T<1\) | more concentrated distribution |
| \(T=1\) | original distribution |
| \(T>1\) | flatter distribution |
| \(T\to0\) | approaches argmax/greedy |
Temperature does not mean creativity. Creativity is an emergent correlate of changing the distribution.
12. Top-K¶
Keeps only:
and masks the rest.
It is an absolute cardinality limit on the support.
Caveat¶
A K=40 is equally rigid under a flat distribution and an extremely concentrated one. That makes it less adaptive than Min-P/Top-P.
13. Top-P / Nucleus¶
Sort probabilities in descending order and choose the smallest set \(S\) such that:
The support cardinality changes dynamically.
14. Min-P¶
Criterion:
If \(p_{max}=0.8\) and min_p=0.05:
In logit terms, before additional transformations:
The cutoff adapts to the model's confidence.
15. Typical sampling¶
Typical sampling favors tokens whose surprisal lies near the local entropy:
Tokens that are too predictable or too improbable may be removed if they are “atypical” relative to the distribution.
16. Top-N-Sigma¶
A family of filters that uses statistics of the logit/probability distribution to trim the tail with an adaptive threshold based on dispersion. This is backend-specific; document the concrete implementation before assuming equivalence with Min-P.
17. XTC¶
XTC aims to increase diversity by probabilistically removing some overly likely tokens under certain conditions. It is a support-shaping mechanism, not a mathematically equivalent substitute for temperature.
Treat it as BACKEND/INF, not as a universal property of LLMs.
18. Presence/Frequency penalties¶
Conceptual OpenAI-style form:
where:
- \(\alpha\): presence penalty;
- \(\beta\): frequency penalty;
- \(c_i\): token count over the relevant history.
19. Repetition penalty¶
Implementations vary; one common formulation modifies logits differently depending on their sign and whether the token appeared previously.
Do not treat it as merely “divide probability by X.” It is backend-specific.
Failure surface¶
An aggressive repetition penalty may punish:
- function words;
- necessary proper names;
- code syntax;
- legitimate structural patterns.
20. DRY — sequence, not token¶
DRY penalizes repetition of increasingly long sequences/n-grams. Conceptually, if a sequence extension has already occurred, the penalty grows with repeated length.
It is particularly useful when:
RP and long-form narrative benefit because stylistic loops often recur as entire phrases.
21. Adaptive-P¶
Modern llama.cpp implements a feedback sampler that maintains an EMA of the original probability of selected tokens and adjusts its target throughout generation.
Conceptually:
The sampler tries to select tokens near an adaptive target.
This differs from a static filter: the sampler has internal state.
22. Mirostat¶
A feedback-oriented controller designed to keep surprisal/perplexity near a target.
Principle:
Exact implementation depends on the version. Classify it as an adaptive controller, not merely “automatic temperature.”
PART VI — CONSTRAINED DECODING¶
23. Grammar / JSON Schema¶
At each step there is a set of lexically/syntactically valid tokens:
The sampler is constrained:
Important¶
Perfect JSON can still contain a fabricated argument or the wrong action.
PART VII — STATE AND COST¶
24. KV cache¶
For GQA/MHA:
It scales linearly with stored context.
“How much does +1k tokens cost?”¶
Do this calculation before choosing a context size.
25. Prefill and decode¶
Prefill¶
Processes the full prompt and builds the KV cache.
Decode¶
Repeats:
Latency per token grows with state size and architecture.
26. Context window: four different limits¶
- config maximum — the runtime accepts it;
- positional encoding range — RoPE/scaling can represent it;
- training distribution — the model actually saw it during training;
- effective context — information is genuinely used with useful quality.
Do not conflate the four.
PART VIII — REASONING AND BUDGET¶
27. Reasoning tokens / thinking budget¶
In models that externalize or internalize additional reasoning steps, generating more reasoning tokens adds sequential inference. At a fixed prompt and approximately stable average cost per generated token:
This is not a new form of attention mathematics; it is mainly a change in generation/training policy and token/computation budget.
Caveat¶
A larger reasoning budget does not guarantee monotonically better answers.
PART IX — COUPLING MATRIX¶
28. Main relationships¶
| Control ↑ | Entropy | Support | Repetition | KV | Latency | Comment |
|---|---|---|---|---|---|---|
| Temperature | ↑ | = | usually ↓ | = | ~ | may increase incoherence |
| Top-K | — | ↑ | may ↑ | = | ~ | absolute cutoff |
| More restrictive Top-P | ↓ | ↓ | may ↑ | = | ~ | cumulative adaptive cutoff |
| Higher Min-P | ↓ | ↓ | may ↑ | = | ~ | relative to top token |
| Rep penalty | variable | variable | ↓ lexical | = | ~ | may damage syntax |
| DRY | variable | variable | ↓ sequential | = | small | excellent against long loops |
| Context | — | — | variable | ↑ linear | ↑ | possible quality gain/loss |
| KV precision | ~ | = | = | ↑ with bits | may vary | accuracy/runtime dependent |
| Batch/parallel | — | — | — | ↑ | throughput ↑ | individual latency may rise |
PART X — MAPPING TO THE LOCAL STACK¶
29. SillyTavern¶
The UI should be understood as a control plane. It does not define the mathematics; it sends parameters to the backend.
Always verify:
- sampler order;
- which samplers the backend ignores;
- stop strings;
- context size;
- instruct/chat template;
- system prompt injection;
- grammar/JSON schema when applicable.
30. KoboldCpp / llama.cpp¶
As of 2026, the set includes, among others:
- penalties;
- DRY;
- top-n-sigma;
- top-k;
- typical;
- top-p;
- min-p;
- XTC;
- temperature;
- adaptive-p;
- grammar;
- quantized KV;
- speculative decoding.
Order is a backend/configuration property. Do not write “the universal order is X.”
31. LM Studio / Ollama¶
Treat them as frontends/runtimes with their own defaults. For technical benchmarking, hold constant:
- the same GGUF/checkpoint;
- the same template;
- the same context;
- the same samplers;
- the same seed;
- the same KV quantization;
- the same GPU offload.
Otherwise, comparing “model A vs B” becomes a comparison between different pipelines.
PART XI — EXPERIMENTAL PROTOCOL¶
32. Scientific sampling sweep¶
- Fix prompt/template/context/seed/backend/model.
- Record top logits/probabilities per token if possible.
- Change one control family at a time.
- Measure:
- entropy;
- support size;
- repetition rate;
- unique n-grams;
- task accuracy;
- subjective quality.
- Repeat across multiple seeds — one seed is a point, not a distribution.
PART XII — FAILURE DIAGNOSTICS¶
33. Symptom → hypothesis¶
| Symptom | Investigate first |
|---|---|
| repeated phrases | DRY / context injection / low entropy |
| strange synonyms | excessive rep penalty |
| incoherent text | temperature/support too open / model limit |
| truncated response | max tokens / EOS / stop strings |
| disobedience | template/system/conditioning before sampling |
| quality drops at long context | RoPE regime/effective context/KV precision |
| TPS collapses | context/KV/offload/bandwidth |
| invalid JSON | grammar/schema, not temperature alone |
34. Snapshot 2026¶
- DeepSeek-V3: 671B total, 37B active per token, MLA + DeepSeekMoE.
- Qwen3-Coder-Next: 80B total, ~3B active during inference, illustrating why total and active parameters must be separated.
- llama.cpp: modern sampling includes DRY, XTC, top-n-sigma, and adaptive-p in addition to classic top-k/top-p/min-p.
References¶
- llama.cpp sampler API — https://github.com/ggml-org/llama.cpp/blob/master/include/llama.h
- llama.cpp completion sampling docs — https://github.com/ggml-org/llama.cpp/blob/master/tools/completion/README.md
- llama.cpp CLI/runtime — https://github.com/ggml-org/llama.cpp/blob/master/tools/cli/README.md
- DeepSeek-V3 — https://arxiv.org/abs/2412.19437
- Qwen3-Coder-Next — https://arxiv.org/abs/2603.00729
PART XIII — PARALLEL / MASKED / DIFFUSION LANGUAGE MODELS¶
Transformer does not imply autoregression. From this point on, we drop the assumption that text can only advance as
token1 → token2 → token3.
Related: 01_GUT_GENERATIVE_AI_UNIFIED_ENGINEERING, 09_LOCAL_AI_INFERENCE_RUNTIME_DATASHEET.
35. Autoregressive factorization — baseline¶
Inference:
x1 -> x2 -> x3 -> ... -> xT
Position \(t+1\) does not exist before \(t\) has been decided.
Implications¶
- natural streaming;
- extremely efficient incremental KV;
- latency grows with output-token count;
- each prior error/decision becomes later conditioning.
36. Masked language modeling¶
Define mask \(M\subset\{1,\ldots,T\}\):
Unlike causal AR, a position can use context from both sides.
Iterative inference may begin with:
[MASK] [MASK] [MASK] [MASK] [MASK]
fill the highest-confidence positions, remask/refine, and repeat.
37. Discrete diffusion / iterative denoising¶
Corrupted text state:
The network learns a reverse transition:
Trajectory:
Here \(t\) is noise/refinement time, not textual position.
38. Parallel token prediction¶
If multiple positions are updated in one pass:
where \(U_k\) is the set of positions updated at iteration \(k\).
This breaks the identity:
that dominates causal LLMs.
39. Confidence-based unmasking¶
Each position has a confidence:
Choose the top positions:
The most confident positions are fixed first; uncertain ones remain masked.
Failure surface¶
A high-confidence error committed early can contaminate later refinement.
40. Remasking¶
A decision can be revised:
This is structurally different from pure AR, where an emitted token is normally irreversible without an external restart/edit loop.
Remasking enables self-correction inside the decode topology itself.
41. Blockwise generation¶
A compromise between AR and full-sequence iterative generation:
Within each block, multiple tokens can be refined in parallel.
This preserves some streaming/local causality while reducing the number of sequential steps.
42. Sequence length problem¶
AR does not need to know final length in advance; EOS decides.
Full-mask generation often needs to define/allocate a length:
Possible strategies:
- length predictor;
- overallocate + EOS/padding;
- blockwise growth;
- insertion/deletion transitions.
So “how many tokens should we generate?” becomes part of the state topology itself.
43. KV cache does not work the same way¶
Causal AR:
If earlier positions change during iterative refinement:
derived states may need to be recomputed/invalidated.
So AR's great runtime trick — cache the entire immutable prefix — loses part of its advantage.
This is central when comparing real-world speed.
44. Complexity model: AR¶
For \(T_{out}\) tokens:
with small passes and incremental KV.
45. Complexity model: iterative parallel¶
For \(K\) refinement steps:
The advantage appears when:
and the cost of each parallel pass does not erase the savings.
Therefore:
46. Throughput vs latency¶
AR can offer:
- excellent token streaming;
- low first-token latency after prefill;
- low parallelism along the output axis.
Iterative models can offer:
- more compute per iteration;
- worse natural streaming;
- much higher output parallelism;
- high aggregate throughput on massively parallel hardware.
The optimal architecture depends on hardware and serving regime.
47. Sampling in diffusion text¶
Do not assume temperature/top-p/min-p apply exactly as they do in AR.
Controls may instead act on:
- corruption/noise schedule;
- token proposal distribution;
- confidence threshold;
- remasking ratio;
- number of refinement steps;
- block size;
- guidance/conditioning strength;
- stochastic vs deterministic transitions.
Each implementation must be mapped to its actual equation.
48. Entropy schedule¶
A refinement schedule may reduce the number of unresolved positions. The marginal entropy of \(X^{(k)}\) is not generally monotone: a deterministic all-MASK state has zero entropy, while the generated text distribution can have positive entropy.
Any entropy diagnostic must specify its random variable and conditioning. Sharpening token-choice distributions too early can cause premature commitment; maintaining excessive uncertainty late in decoding can hinder convergence.
This is analogous to annealing, but the concrete implementation matters.
49. Editing advantage¶
Because the full sequence can be revisited:
it is natural to preserve surrounding context and regenerate internal regions.
AR usually needs FIM, rewrite, or another special mechanism to achieve the same effect.
50. Diffusion language model ≠ image diffusion copied literally¶
Text is discrete.
Typical image latent:
Text:
The corruption/reverse process must respect the discrete state or use specific embeddings/relaxations.
The correct analogy is iterative denoising, not “add Gaussian noise to a token ID.”
51. Snapshot: Mercury¶
Mercury/Mercury Coder demonstrated commercial-scale diffusion language models parameterized by Transformers that predict multiple tokens in parallel.
The most important conceptual point:
And the physical point:
not merely “tokens per pass.”
PART XIV — INFERENCE-TIME REASONING / TEST-TIME COMPUTE¶
52. A reasoning model is not a new architectural species¶
In most cases:
Do not create a separate ontology just because the output contains a reasoning trace.
53. Reasoning budget¶
If the model generates \(T_r\) intermediate tokens and \(T_a\) answer tokens:
For prompt length \(P\) and a full KV cache with fixed layout and precision:
Here \(c\) is the storage per cached token; caches with eviction or a sliding window use the number of retained tokens instead. Generation latency and energy are approximately linear in generated length only when average time and energy per generated token remain stable. Growing attention prefixes and changing execution regimes can invalidate that approximation.
Test-time compute buys search/reflection, not new parametric capacity.
54. Sampling + verifier loop¶
An alternative to one long chain:
or iterative search:
See 12_REWARD_VERIFIER_JUDGE_DATASHEET.
55. Updated map of language-model families¶
Language Foundation Models
├─ Causal autoregressive
│ ├─ dense
│ ├─ MoE
│ └─ hybrid attention/SSM
├─ Masked / bidirectional encoders
├─ Iterative / diffusion / parallel generation
├─ Embedding / retrieval encoders
├─ Rerankers / cross-encoders
└─ Reward / verifier / judge models
The last three have their own datasheets because the output/objective changes, not merely the decoding method.
Additional references¶
- Mercury: Ultra-Fast Language Models Based on Diffusion — https://arxiv.org/abs/2506.17298
- Reward/verifier topology — 12_REWARD_VERIFIER_JUDGE_DATASHEET
- Runtime comparison AR vs iterative text — 09_LOCAL_AI_INFERENCE_RUNTIME_DATASHEET