論文解説
Mistral 7B
- 課題 大規模言語モデルは性能を高めるためにモデルの規模を大きくしますが、計算コストと推論の遅延が増え、デプロイが難しくなります。Mistral 7Bは、7Bパラメータの規模で高い性能と効率を両立することを目標としています。
- 手法 Grouped-query attentionにより推論中のメモリ要求を減らし、sliding window attentionにより長いシーケンスの計算量とキャッシュのコストを抑えています。
- 結果 論文は、Mistral 7BがLlama 2 13Bをすべての指標で上回り、複数のベンチマークでLlama 1 34Bも上回ったと報告しています。Instructモデルは、MT Benchで6.84 ± 0.07を記録しています。
モデルの規模とデプロイコストの衝突
言語モデルは性能を高めるためにモデルの規模を大きくする傾向があります。しかし、この方法は計算コストと推論の遅延を同時に増やすため、実際のサービスへのデプロイの障壁になります。Mistral 7Bは、この状況に対して、7Bパラメータ規模のモデルで高い性能と効率を両立することを目標とするモデルとして紹介されています。
この目標のため、論文は2つのアテンション設計を組み合わせています。1つは、キーと値のヘッドを共有して推論中のメモリ要求を減らすgrouped-query attention(GQA)です。もう1つは、各トークンが近い範囲のトークンだけに注意を向けるsliding window attention(SWA)です。以降の節では、SWAが長いシーケンスのコストをどう減らすか、そしてそのコスト削減がキャッシュ管理とどう結びつくかを順に追っていきます。
Sliding Window Attentionの情報伝達の仕組み
Sliding Window Attention(SWA)では、各レイヤーの位置iにある隠れ状態が、前のレイヤーの位置i−Wからiまでの状態にだけ注意を向けます。1つのレイヤーが直接見られる範囲は、W個のトークンに固定されます。ただし、この演算を複数のレイヤーに積み重ねると、情報はレイヤーを通るたびにWずつ先へ伝わるため、k個のレイヤーの後には最大でW×kトークンの距離まで情報が届きます。図1のキャプションは、この原理をW=3の例で示しています。論文は、W=4096の場合、最後のレイヤーの理論上のアテンション範囲は約131Kトークンであると説明しています。

Figure 1 : Sliding Window Attention. The number of operations in vanilla attention is quadratic in the sequence length, and the memory increases linearly with the number of tokens. At inference time, this incurs higher latency and smaller throughput due to reduced cache availability. To alleviate this issue, we use sliding window attention: each token can attend to at most W tokens from the previous layer (here, W = 3). Note that tokens outside the sliding window still influence next word prediction. At each attention layer, information can move forward by W tokens. Hence, after k attention layers, information can move forward by up to k × W tokens.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの2ページ目から図の部分を抽出しています。この設計が必要な理由は、vanilla attentionのコスト構造にあります。図1のキャプションによると、vanilla attentionの演算量はシーケンス長に対して二次的に増え、メモリはトークン数に比例して増えます。推論時にキャッシュの容量が減ると、遅延は大きくなり、スループットは小さくなります。SWAは各レイヤーのアテンション範囲をWに制限することで、このコストを減らしつつ、複数のレイヤーを通してより遠い情報まで伝わるようにします。
この構造は、Table 1の設定とあわせて示されています。表にはwindow_size 4096とcontext_len 8192が含まれており、Mistral 7Bはこの条件でSWAを使う構造として説明されています。

Table 1 : Model architecture.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの2ページ目から図の部分を抽出しています。固定サイズのキャッシュとプロンプトのチャンク処理
Rolling Buffer Cacheは、SWAの固定されたアテンション範囲を使って、キャッシュサイズをWに制限します。時点iのキーと値は、キャッシュの\(i \bmod W\)の位置に保存されます。そのため、iがWより大きくなると古い値が上書きされ、キャッシュサイズはそれ以上増えません。図2は、W=4の場合にこの動作を示しています。

Figure 2 : Rolling buffer cache. The cache has a fixed size of W = 4. Keys and values for position i are stored in position i mod W of the cache. When the position i is larger than W , past values in the cache are overwritten. The hidden state corresponding to the latest generated tokens are colored in orange.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの3ページ目から図の部分を抽出しています。Pre-fill and Chunkingは、生成の前にわかっているプロンプトの(k, v)キャッシュをあらかじめ埋める方法です。トークンは1つずつ生成しなければなりませんが、プロンプトは事前に与えられているため、先にキャッシュへ入れておくことができます。プロンプトが長い場合は、ウィンドウサイズをチャンクサイズとして、複数のチャンクに分けて処理します。各チャンクでは、キャッシュに対するアテンションとチャンク内のアテンションを合わせて計算します。図3は、3つ目のチャンク'the dog go to'では、チャンク内にはcausal maskが、キャッシュにはスライディングウィンドウが適用され、ウィンドウの外にある過去のトークンは参照しない構造を示しています。

Figure 3 : Pre-fill and chunking. During pre-fill of the cache, long sequences are chunked to limit memory usage. We process a sequence in three chunks, “The cat sat on”, “the mat and saw”, “the dog go to”. The figure shows what happens for the third chunk (“the dog go to”): it attends itself using a causal mask (rightmost block), attends the cache using a sliding window (center block), and does not attend to past tokens as they are outside of the sliding window (left block).
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの3ページ目から図の部分を抽出しています。論文は、32kトークンのシーケンスでは、このキャッシュによりキャッシュメモリの使用量が8x減り、モデルの品質には影響しないと報告しています。この数値は32kトークンのシーケンスに対する結果であり、他の長さでの削減量はこの解説では扱っていません。
16Kシーケンスでの推論速度
SWAの効率は、FlashAttentionとxFormersに加えた変更によって、実際の速度として確認されます。論文は、16Kシーケンス長とW=4096の条件では、この変更により、vanilla attentionのベースラインより2xの速度向上が出ると報告しています。
この結果は、その条件で測定した速度の比較です。同じ数値を別のシーケンス長や別のハードウェアにそのまま当てはめることは、この解説の範囲を超えます。前述のキャッシュの削減と合わせて見ると、SWAの効果は、演算速度とメモリ使用量という2つの面に現れています。
Llamaシリーズのベースラインとのベンチマーク比較
Mistral 7Bは、Llama 2 7B、Llama 2 13B、Llama 1 34B、Code-Llama 7Bと比較されています。図4は複数のベンチマークでこの比較を示しており、キャプションでは、すべてのモデルを同じ評価パイプラインで再評価したと説明されています。その結果、Mistral 7Bは、Llama 2 13Bをすべての指標で上回り、Llama 1 34Bも大半のベンチマークで上回りました。特にコード、数学、推論のベンチマークで優位性が際立っています。

Figure 4 : Performance of Mistral 7B and different Llama models on a wide range of benchmarks. All models were re-evaluated on all metrics with our evaluation pipeline for accurate comparison. Mistral 7B significantly outperforms Llama 2 7B and Llama 2 13B on all benchmarks. It is also vastly superior to Llama 1 34B in mathematics, code generation, and reasoning benchmarks.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの4ページ目から図の部分を抽出しています。表2の数値では、MMLU(5-shot)のスコアはMistral 7Bが60.1%、LLaMA 2 13B Pretrainedが55.6%でした。GSM8K(8-shot, maj@8)のスコアはMistral 7Bが52.2%、LLaMA 2 13B Pretrainedが34.3%でした。この比較は同じ評価設定で再実行された値であり、表の値は上記の設定とあわせて読む必要があります。

Table 2 : Comparison of Mistral 7B with Llama. Mistral 7B outperforms Llama 2 13B on all metrics, and approaches the code performance of Code-Llama 7B without sacrificing performance on non-code benchmarks.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの4ページ目から図の部分を抽出しています。コードの性能では、Mistral 7BのHumanEvalスコアは30.5%で、Code-Llama 7Bは31.1%でした。論文では、Mistral 7Bは、コード以外のベンチマークの性能を犠牲にすることなく、Code-Llama 7Bのコード性能に近づいていると説明されています。
モデル規模あたりの効率と知識ベンチマークの限界
論文は、Llama 2系列の同等のモデル規模を計算して、Mistral 7Bのコストあたりの性能を比較しています。推論、読解、STEM推論のうち、MMLUでは、Mistral 7Bの性能が3倍より大きいLlama 2モデルで期待される性能と同程度に現れています。
知識ベンチマークでは、圧縮率が1.9xと低く報告されています。著者らは、この低い圧縮率は、パラメータ数が限られているため保存できる知識の量が制限されることが原因である可能性があると解釈しています。図5のキャプションも、知識ベンチマークではMistral 7BがLlama 2 13Bと同程度だと説明しています。

Figure 5 : Results on MMLU, commonsense reasoning, world knowledge and reading comprehension for Mistral 7B and Llama 2 (7B/13B/70B). Mistral 7B largely outperforms Llama 2 13B on all evaluations, except on knowledge benchmarks, where it is on par (this is likely due to its limited parameter count, which limits the amount of knowledge it can compress).
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの5ページ目から図の部分を抽出しています。公開インストラクションデータで作ったMistral 7B – Instruct
Mistral 7B – Instructは、Hugging Faceのリポジトリにある公開のインストラクションデータセットを使って、ベースモデルをファインチューニングして作られました。論文では、独自データや特別な学習手法は使っていないと述べられており、このモデルは、ベースモデルを簡単にファインチューニングできることを示す簡単なデモとして扱われています。
チャットの評価であるMT Benchでは、Mistral 7B – Instructのスコアは6.84 +/- 0.07です。同じ表では、Llama 2 13B Chatは6.65、WizardLM 13B v1.2は7.2です。論文は、Mistral 7B – Instructがすべての7Bモデルより高く、13B – Chatモデルと同程度だと説明しています。この結果は13B系列のモデルの中での最高点を意味するものではなく、上の表の比較範囲の中で読む必要があります。

Table 3 : Comparison of Chat models. Mistral 7B – Instruct outperforms all 7B models on MT-Bench, and is comparable to 13B – Chat models.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの4ページ目から図の部分を抽出しています。Table 4には、6.84 ± 0.07が10回の反復による公式MT Benchの平均と標準偏差だと明記されています。Llama 2 13B – Chatの6.65は、参考用の公式結果として併記されています。

Table 4 : System prompts. Mean official MT Bench score over 10 iterations with standard deviation for Mistral 7B – Instruct. For reference, Llama 2 13B – Chat reports official results of 6.65.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの5ページ目から図の部分を抽出しています。人間による選好評価
論文は、Mistral 7B – InstructとLlama 2 13B – Chatを、独立した人間による評価で比較しています。評価はllmboxing.comで行われ、参加者は質問と、匿名の2つのモデルの応答を見て、好ましい応答を選びます。図6は、量子物理学の本の推薦に関する質問で、2つの応答の違いを例として示しています。

Figure 6 : Human evaluation of Mistral 7B – Instruct vs Llama 2 13B – Chat Example. An example of human evaluation from llmboxing.com. The question asks for recommendations of books in quantum physics. Llama 2 13B – Chat recommends a general physics book, while Mistral 7B – Instruct recommends a more relevant book on quantum physics and describes in the contents in more detail.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの7ページ目から図の部分を抽出しています。2023年10月6日時点で、Mistral 7Bの出力は5020回、Llama 2 13Bの出力は4143回選ばれました。この値は選好された回数であり、この評価は、そのプラットフォームの質問と参加者の集合から得られた結果として読む必要があります。
システムプロンプトで調整するガードレール
システムプロンプトは、モデルに指示の範囲内で答えるよう促す方法です。論文では、安全で敬意があり誠実な回答を求め、偏ったものや有害な内容を避けるよう指示するシステムプロンプトが示されています。ユーザーはこのプロンプトをオンとオフに切り替えることができ、それによって有用性とガードレールの強さの間にあるParetoカーブ上の地点を選べます。
Table 4のMT Benchの値は、システムプロンプトがない場合は6.84 ± 0.07、Mistral system promptでは6.58 ± 0.05、Llama 2 system promptでは6.38 ± 0.07です。これらの値は、同じ表に報告された値どうしでのみ比較すべきです。
安全性の評価は、175個の安全ではないプロンプトの集合で行われています。推奨のシステムプロンプトを使うと、モデルは有害な質問の100%に対して、適切に回答を拒否します。Table 5の例では、Mistral 7B – Instructは、Linuxのプロセスを終了する方法に正しく答え、Llama 2 13B – Chatは回答を拒否しています。論文では、この質問について、システムプロンプトをオフにすると両方のモデルが正しく答えると述べられています。

Table 5 : Comparison between Mistral and Llama system prompts. Mistral provides the right answer whereas Llama 2 declines to answer to the question How to kill a linux process.
出典 · CC BY 4.0 · Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed · Mistral 7B · 論文の図を引用 · 元のPDFの6ページ目から図の部分を抽出しています。自己内省に基づくコンテンツ分類
Mistral 7B – Instructは、コンテンツレビュアーとしても使えます。論文では、自己内省プロンプトを設計し、モデルにユーザーのプロンプトや生成された回答が許容できる内容か、それとも違法行為、憎悪・ハラスメント・暴力的な内容、資格のない専門的助言などのカテゴリーに当たるかを分類させています。ユーザーは後から、自分の利用目的に合うカテゴリーを選んでフィルタリングできます。
評価には、人手でキュレーションされたバランスの取れた敵対的プロンプトと、標準的なプロンプトのデータセットが使われています。許容できるプロンプトを陽性とみなすと、precisionは99.4%、recallは95.6%です。この結果は、著者らが構築したデータセットで得られたものであり、他のデータに対する分類性能にそのまま一般化できるわけではありません。
評価の範囲と残る疑問
論文のベンチマーク評価は、著者らが再実行した評価パイプラインで行われました。論文では、Llama 2の論文と比べて2つの評価方法が異なると述べられています。MBPPでは人手で検証されたサブセットが使われ、TriviaQAではWikipediaの文脈は与えられていません。そのため、この違いがあるベンチマークのスコアは、Llama 2の論文の報告値と同じ条件で読んではいけません。
また、知識ベンチマークの低い圧縮率は、前述のパラメータ数の制約と関係しています。ガードレールの結果は175個の安全ではないプロンプトの集合から、自己内省による分類の結果は著者らが構築したデータセットから、人間による評価は1つのプラットフォームの質問と応答から得られたものです。これらの結果が、他の利用環境での安全性や品質を代表することを示す根拠は、この解説の範囲にはありません。
論文情報
- 著者
- Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed
- 学会・ジャーナル
- arXiv · プレプリント
- 公開日
- 2023年10月10日
- 登録日
- 2026年10月20日
- 更新日
- 2023年10月10日
- バージョン
- v1
- arXiv
- 2310.06825
- カテゴリ
- cs.CL · cs.AI · cs.LG
- ライセンス
- CC BY 4.0
- 掲載内容
- 論文情報・解説・論文の図
この解説は、Refivuの韓国語解説をAIで翻訳したものです。不正確な翻訳や誤りが含まれる可能性があります。論文と図の利用条件は各出典に従います。
アブストラクト
We introduce Mistral 7B v0.1, a 7-billion-parameter language model engineered for superior performance and efficiency. Mistral 7B outperforms Llama 2 13B across all evaluated benchmarks, and Llama 1 34B in reasoning, mathematics, and code generation. Our model leverages grouped-query attention (GQA) for faster inference, coupled with sliding window attention (SWA) to effectively handle sequences of arbitrary length with a reduced inference cost. We also provide a model fine-tuned to follow instructions, Mistral 7B -- Instruct, that surpasses the Llama 2 13B -- Chat model both on human and automated benchmarks. Our models are released under the Apache 2.0 license.
この論文を引用
Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, William El Sayed (2023). Mistral 7B. arXiv:2310.06825v1. https://arxiv.org/abs/2310.06825v1
BibTeX
@misc{jiang2023mistral,
title = {{Mistral 7B}},
author = {Albert Q. Jiang and Alexandre Sablayrolles and Arthur Mensch and Chris Bamford and Devendra Singh Chaplot and Diego de las Casas and Florian Bressand and Gianna Lengyel and Guillaume Lample and Lucile Saulnier and Lélio Renard Lavaud and Marie-Anne Lachaux and Pierre Stock and Teven Le Scao and Thibaut Lavril and Thomas Wang and Timothée Lacroix and William El Sayed},
year = {2023},
eprint = {2310.06825},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2310.06825v1}
}