TL;DR
Mistral 7B is a language model with 7 billion parameters. The paper reports that it beats Llama 2 13B on nearly every benchmark it tested, and matches or beats Llama 1 34B on most of them, with the clearest gains in math and code. It gets its speed and memory savings from two attention changes: grouped-query attention, which makes decoding cheaper, and sliding window attention, which caps how much past each token has to look at.
Where you'll see it: in the released 7B base model and its instruction-tuned chat variant, both under the Apache 2.0 license, and in the two attention mechanisms the architecture section explains.
The problem
Bigger language models score higher, but they cost more to run. The paper's introduction frames the goal as balancing high performance with efficiency, because scale raises both computational cost and inference latency, and that raises the barrier to deploying a model in practice.
Two costs dominate at inference time. The first is attention itself. In vanilla attention, every token looks at every earlier token, so the work grows quadratically with sequence length. The second is memory. The paper's Figure 1 caption says the memory for keys and values grows linearly with the number of tokens, which means long prompts and large batches compete for the same cache. Less cache means smaller batches and lower throughput. A model that is cheap at both is useful even if it is not the largest.
Key idea
Keep a 7B model, but change how attention is computed and stored so that memory and time stop growing as fast as the context does. Three pieces do this.
- Grouped-query attention shares key and value heads across groups of query heads. The cache is smaller, so decoding reads less memory per token.
- Sliding window attention lets each token attend to at most previous positions in each layer. Compute per layer is bounded by , not by the whole sequence.
- A rolling buffer cache exploits the fixed window. Because old keys and values can be overwritten once they fall out of the window, the cache has a fixed size of entries.
The window alone would seem to hide distant tokens. The trick is that the layers stack. Information moves forward by up to positions per layer, so after layers a token can be influenced by something up to positions back.
flowchart LR A[Layer 1: each token sees W earlier positions] --> B[Layer 2: each token sees W positions of layer-1 states] B --> C[Layer k: information reaches up to k times W back]
The method
Architecture
The paper says Mistral 7B is based on the transformer architecture and that, compared with Llama, it introduces a few changes. The architectural details the paper spells out are the sliding window attention, the rolling buffer cache, and pre-fill with chunking. The paper's Table 1 lists the main model dimensions. Grouped-query attention is credited to the GQA paper, and the introduction says it speeds up inference and reduces decoding memory, which allows larger batches and higher throughput.
Sliding window attention
Write for the hidden state at position in layer . In the paper's formulation, attends to the previous layer's hidden states at positions between and . Unrolling this recursion, can draw on input tokens as far back as positions. For a window of , the paper states a theoretical attention span of about 131K tokens at the last layer. That number equals , so it implies 32 layers.
The window is a theoretical span, not a hard cutoff on what the model can use. Information that leaves the window directly can still reach the prediction through the layers above it.
For speed, the paper reports that for a sequence length of 16K with , changes to FlashAttention and xFormers give a 2x speed improvement over a vanilla attention baseline. See FlashAttention for the kernel idea behind that change.
Rolling buffer cache
Because attention only reaches back in each layer, the cache of keys and values needs only slots. The key and value for position go to slot . When position passes , it overwrites the entry from position , which is no longer needed for direct attention. The paper says this cuts cache memory by 8x on a 32K-token sequence without hurting quality.
Here is a small trace with . Positions 0 to 3 fill slots 0 to 3. Position 4 writes to slot , overwriting position 0. Position 5 writes to slot 1, overwriting position 1. The cache always holds the four most recent positions, and its size never grows.
Pre-fill and chunking
When the prompt is known in advance, its keys and values can be computed in one pass and stored, instead of generating the prompt token by token. A very long prompt can be split into chunks. The paper suggests using the window size as the chunk size. For each chunk, the attention has two parts: a causal mask over the chunk itself, and a sliding-window mask over the cache of earlier positions. Tokens older than the window are masked out of both parts.
Instruction tuning
The paper fine-tunes the base model on instruction datasets that are publicly available on Hugging Face. It says no proprietary data or training tricks were used. The text describes a simple, preliminary fine-tune and does not describe a preference-tuning step. This contrasts with the human-feedback pipeline in InstructGPT, which the paper does not claim to reproduce.
Guardrails
The paper introduces an optional system prompt that asks the model to be careful, respectful and truthful. With that prompt, the paper reports that the model declined 100% of 175 unsafe prompts. It also describes using the instruct model as a content moderator by asking it to classify prompts and answers into categories such as illegal activity, hateful content and unqualified advice. On the paper's balanced set of adversarial and standard prompts, the self-reflection prompt gives a precision of 99.4% and a recall of 95.6%, counting acceptable prompts as positives.
Results
The paper re-runs every benchmark with its own evaluation pipeline, so the comparison is fair within the paper. Table 2 gives the base-model numbers. The table below shows Mistral 7B minus Llama 2 13B, computed from Table 2.
| Benchmark | Llama 2 13B | Mistral 7B | Difference |
|---|---|---|---|
| MMLU | 55.6% | 60.1% | +4.5 |
| HellaSwag | 80.7% | 81.3% | +0.6 |
| WinoGrande | 72.9% | 75.3% | +2.4 |
| PIQA | 80.8% | 83.0% | +2.2 |
| ARC-Easy | 75.2% | 80.0% | +4.8 |
| ARC-Challenge | 48.8% | 55.5% | +6.7 |
| Natural Questions | 29.0% | 28.8% | -0.2 |
| TriviaQA | 69.6% | 69.9% | +0.3 |
| HumanEval | 18.9% | 30.5% | +11.6 |
| MBPP | 35.4% | 47.5% | +12.1 |
| MATH | 6.0% | 13.1% | +7.1 |
| GSM8K | 34.3% | 52.2% | +17.9 |
The largest gaps are in math and code, and the smallest in knowledge-heavy tasks. The paper's own explanation for the knowledge result is that the model has fewer parameters, which limits how much knowledge it can store. In Table 2, Code-Llama 7B still beats Mistral 7B on MBPP (52.5% against 47.5%) and is slightly ahead on HumanEval (31.1% against 30.5%). The paper describes Mistral 7B as approaching Code-Llama's coding performance rather than matching it.
The paper also compares against "equivalent model sizes" of the Llama 2 family. It says Mistral 7B on reasoning, comprehension and MMLU performs like a Llama 2 model more than three times its size, but only about 1.9 times its size on knowledge benchmarks.
For the chat model, the paper reports a human preference test. As of October 6, 2023, outputs from Mistral 7B Instruct were preferred 5020 times, against 4143 for Llama 2 13B Chat. That is a 54.8% share of decided comparisons. The paper's Table 3 reports MT-Bench scores, saying the instruct model beats all 7B models and is comparable to 13B chat models; the human evaluation is the independent llmboxing.com comparison.
Why it mattered
The paper's own claims about impact are modest and specific. It says the goal is to help the community build more affordable, efficient and high-performing models for practical applications. It releases the weights under Apache 2.0, ships a reference implementation, and says the model is easy to deploy on AWS, GCP or Azure with the vLLM server and SkyPilot, and easy to use through Hugging Face.
The conclusion makes a scientific point. The paper argues that language models may compress knowledge more than previously thought. It also argues that scaling laws have so far been studied in two dimensions, model capability and training cost, when the problem is three-dimensional, adding inference cost. On that view, a smaller model that is cheap to serve can be the better choice.
Reading guide
Read the paper in this order. Each step names the prerequisite lessons it leans on.
- Section 1, Introduction. Needs Attention Mechanism for the idea of attention cost, and Grouped-Query Attention and Sliding Window Attention as named in the abstract.
- Section 2, Architectural details. Needs Sliding Window Attention for the window, its reach and the rolling cache, FlashAttention for the speed claim, and Language Model for what the model predicts.
- Section 3, Results. Needs Language Model for what the benchmarks measure. Read Table 2 with the difference table above in mind.
- Section 4, Instruction finetuning. Needs Training Language Models to Follow Instructions with Human Feedback only as context for what the paper does not do.
- Section 5, Guardrails. Needs no further lesson. It is a prompting and classification method built on the instruct model.
- Section 6, Conclusion. The three-dimensional argument about capability, training cost and inference cost.
Check yourself
QuestionWhat is the most a single sliding-window layer lets a token attend to, in the paper's formulation?Show answer
Each token attends to the previous layer's states at positions between and . That is at most positions, including the token itself. The paper calls the window size.
QuestionWith and 32 layers, what is the theoretical attention span at the last layer? How much smaller is a rolling cache than a full cache at 32768 tokens?Show answer
The span is , which the paper rounds to about 131K tokens. A full cache at 32768 tokens holds 32768 entries per layer. A rolling cache holds . The ratio is , matching the paper's eight-fold reduction.
QuestionWhy does grouped-query attention speed up decoding, and why does that matter for throughput?Show answer
During decoding, the model reads the cached keys and values for every token it generates. Grouped-query attention shares key and value heads across groups of query heads, so the cache is smaller and each step reads less memory. Smaller caches leave room for larger batches, and larger batches give more tokens per second, which the introduction names as the reason throughput matters.
QuestionUsing Table 2, by how much does Mistral 7B beat Llama 2 13B on GSM8K, and why is Natural Questions an exception?Show answer
The difference is percentage points. Natural Questions is an exception because Llama 2 13B scores 29.0% and Mistral 7B scores 28.8%, a difference of . The paper's text says Mistral beats Llama 2 13B "across all metrics", but its own table shows this one exception. The paper attributes the knowledge-benchmark result to the smaller parameter count.
QuestionA prompt is 100,000 tokens long, the window is 4096, and the model has 32 layers. Can the last token in theory be influenced by the first token?Show answer
Yes, in theory. The reach after 32 layers is , which is more than 100,000, so information from the first token can propagate through the layers. In practice the influence passes through many intermediate states, and the rolling cache means the model never stores more than keys and values per layer for direct attention.
Sources
- Jiang et al. (2023), Mistral 7B: https://arxiv.org/abs/2310.06825
- Ainslie et al. (2023), GQA, cited by the paper for grouped-query attention: https://arxiv.org/abs/2305.13245
- Touvron et al. (2023), Llama 2, the main comparison model: https://arxiv.org/abs/2307.09288