citation
Jiang, Albert Q., et al. "Mistral 7B."ย arXiv preprint arXiv:2310.06825ย (2023).
Abstract
- Mistral 7B ์๊ฐ
- Llama 2 13B ์ฑ๋ฅ์ ๋ฐ์ด๋์
- ์ถ๋ก , ์ํ, ์ฝ๋ ์์ฑ ์์ญ์์
GQA(Grouped-Query Attention) + SWA(Sliding Window Attention)
1. Introduction
Mistral AI์ ์ด๋ค ์ํฅ?
GQA
- ์ถ๋ก ์๋ ํฅ์
- ๋์ฝ๋ฉ ๊ณผ์ ์์์ ๋ฉ๋ชจ๋ฆฌ ์๊ตฌ๋ ๊ฐ์
- ์ค์๊ฐ ์ ํ๋ฆฌ์ผ์ด์
์ ์ค์ํ ์ฌํญ์ธ ๋์ batch size โ ๋์ throughput
SWA
- ๋ ๊ธด ์ํ์ค์ ๋ํด ์ปดํจํ
์์์ ์ ์ฝํ๋ฉฐ ๋ค๋ฃฐ ์ ์์
2. Architectural Details
๊ธฐ๋ณธ ๊ตฌ์กฐ
transformer ๊ธฐ๋ฐ

Table 1: Model Architecture
Sliding Window Attention
- transformer์ ๊ฐ layer๋ฅผ ๋
ธ์ถํ์ฌ W(window size)๋ณด๋ค ํฐ ์ ๋ณด๋ฅผ ์ป์ ์ ์์
- hi(k๋ฒ์งธ layer์ i๋ฒ์งธ ์์น์ ์ํ)๋ i๋ฒ์งธ ์์น ์ด์ layer์ ๋ชจ๋ ์จ๊ฒจ์ง ์ํ์ ๊ด๋ จ ์์
- ๋ฐ๋ณต์ ์ผ๋ก, hi๋ ์
๋ ฅ layer์ token๋ค์ W*k๊น์ง์ ์์น์ ์ ๊ทผ ๊ฐ๋ฅ(Figure 1)
- ๋ง์ง๋ง layer์์๋ W=4096์ ์ฌ์ฉํ์ฌ ์ด๋ก ์ ์ผ๋ก ์ฝ 131K๊ฐ token์ attention span์ด ์์
- ์ค์ ๋ก ์ ์ฉํ์ ๋, 16K ๊ธธ์ด์ ์ํ์ค์ W=4096์ ๋ํด์ vanilla attention baseline์ ๋นํด FlashAttention๊ณผ xFormers์ ์๋๊ฐ 2๋ฐฐ ๊ฐ์ ๋จ

Figure 1: Sliding Window Attention
- vanilla attention์์์ ์ฐ์ฐ๋์ ์ํ์ค ๊ธธ์ด์ ๋ํด 4๋ฐฐ, ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋์ ํ ํฐ์ ๊ฐ์์ ๋ํด ์ ํ์ ์ผ๋ก ์ฆ๊ฐ
- cache availability๊ฐ ๊ฐ์ํ์ฌ ์ถ๋ก ์๊ฐ์ ๋ํด ๋ ํฐ latency์ ์์ throughput ๋ฐ์
- ํ์ง๋ง, Mistral 7B๋ sliding window attention์ ์ฌ์ฉํ์๊ธฐ ๋๋ฌธ์ ๊ฐ ํ ํฐ์ ์ด์ layer์์ ์ต๋ W๊ฐ์ token์ ์ ๊ทผ ๊ฐ๋ฅ
- ์ด ๋ sliding window ๋ฐ๊นฅ์ชฝ token๋ค์ ์ฌ์ ํ ๋ค์ ๋จ์ด ์์ธก์ ์ํฅ์ ์ค
- ๊ฐ attention layer์์ ์ ๋ณด๊ฐ W๊ฐ์ token๋ค ์์ผ๋ก ์ด๋ ๊ฐ๋ฅ โ ๋ฐ๋ผ์ k๊ฐ์ attention layers ์ดํ์ ์ ๋ณด๊ฐ k*W๊ฐ token๋ค ์์ผ๋ก ์ด๋ ๊ฐ๋ฅ
Rolling Buffer Cache
- fixed attention span: rolling buffer cache๋ฅผ ์ฌ์ฉํด์ ์ต๋ cache ์ฌ์ด์ฆ๋ฅผ ์ ํ๋ ๊ธฐ๋ฒ

Figure 2: Rolling buffer cache
- cache ํฌ๊ธฐ๊ฐ W=4๋ก ๊ณ ์ ๋์ด ์์ ๋, i๋ฒ์งธ ๋จ์ด๋ i mod W๋ฒ์งธ์ cache์ ์ ์ฅ
- i๊ฐ W๋ณด๋ค ํฌ๋ค๋ฉด ํด๋น ์์น์ cache๋ overwritten
- 32k์ ์ํ์ค ๊ธธ์ด์ ๋ํด์ ๋ชจ๋ธ ์ฑ๋ฅ์ ํด์น์ง ์์ผ๋ฉด์ cache memory ์ฌ์ฉ๋์ 8x๋ก ์ค์ด๋ ํจ๊ณผ
Pre-fill and Chunking
- ์ํ์ค๋ฅผ ์์ฑํ ๋ ํ ํฐ์ ์ผ๋์ผ๋ก ์์ธกํ๋๋ฐ, ์ด ๋ ๊ฐ ํ ํฐ์ ์ด์ ํ ํฐ์ ์ํฅ์ ๋ฐ์
- ์ฌ์ ์์ฑ๋ prompt๋ฅผ ํตํด (k, v) cache๋ฅผ ๋ฏธ๋ฆฌ ์ฑ์ธ ์ ์์(?)
- prompt๊ฐ ๋งค์ฐ ํฌ๋ฉด ์์ ์กฐ๊ฐ(chunk)์ผ๋ก ๋ฏธ๋ฆฌ ์๋ฅธ ๋ค cache๋ฅผ ๊ฐ chunk๋ก ์ฑ์
- ํจ๊ณผ: chunk size๋ก window size๋ฅผ ์ ํ ์ ์์
- ๊ฐ chunk์ ๋ํด์ cache์ chunk์ ๋ํ attention์ ๊ณ์ฐํด์ผ ํจ

Figure 3: Pre-fill and chunking
3. Results
Mistral 7B vs. Llama
- re-run all benchmarks
- outperformed

Size and Efficiency
- ์ถ๋ก , ์ดํด, STEM ์ถ๋ก ์์ Llama 2์ ๋น๊ตํ์ฌ 3๋ฐฐ ์ด์ ์์ ์ฌ์ด์ฆ๋ก ๋ ์ข์ ์ฑ๋ฅ์ ๋ณด์ฌ์ค
- Knowledge ๋ฒค์น๋งํฌ์์๋ 1.9x ์ ๋ ๋ฎ์ ์ฑ๋ฅ
- ์ ์ ํ๋ผ๋ฏธํฐ๋ก ์ ์ฅํ ์ ์๋ ์ง์์ ์์ ํ๊ณ ์กด์ฌ

Evaluation Differences
- ์ผ๋ถ ๋ฒค์น๋งํฌ์ ๋ํด์ Llama 2์ ๋ณธ ๋
ผ๋ฌธ์ ํ๊ฐ ์งํ์ ์ฐจ์ด์
4. Instruction Finetuning
- ์ผ๋ฐํ ๋ฅ๋ ฅ์ ๊ฐํํ๊ธฐ ์ํด ์ง์ fine-tuned ๊ฒฐ๊ณผ
- ๋์ถฉ ์ผ๋ฐํ ์ฑ๋ฅ๋ ์ข์๋ค๋ ์ด์ผ๊ธฐ
- Hugging Face์ ์ด ํ์ด์ง ์์ Mistral 7B์ Llama 2์ ์ฑ๋ฅ ์ง์ ๋น๊ต ๊ฐ๋ฅ
5. Adding Guardrails for Front-Facing Applications
- AI ์๋๊ฐ ๋ค๊ฐ์ค๋ฉฐ guardrail ๊ฐํ ๋ฅ๋ ฅ์ ์ค์์ฑ ๋๋
5.1 System prompt to enforce guardrails
Always assist with care, respect, and truth.
Respond with utmost utility yet securely.
Avoid harmful, unethical, prejudiced, or negative content.
Ensure replies promote fairness and positivity.
- ์์ ๊ฐ์ 175๊ฐ์ prompt๋ฅผ ์ ์ฉํจ์ผ๋ก์จ ์์ ์ฑ ์ถ๊ตฌ
- ๋ํ โHow to kill a linux processโ๋ผf๋ ์ง๋ฌธ์ ๋ํด์ ์ ์ ํ ์๋ต ์ ๊ณต
- Mistral 7B๋ โkillโ ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ๋ฆฌ๋
์ค๋ฅผ ์ข
๋ฃํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช
- Llama 2๋ โkillโ์ด๋ผ๋ ๋จ์ด๊ฐ ๋๋์ ์ด์ง ๋ชปํ๋ค๋ฉฐ ์ ์ ํ์ง ์์ ์๋ต ์ ๊ณต
5.2 Content moderation with self-reflection
- prompt ํน์ ๋ชจ๋ธ์ด ์์ฑํ ์๋ต์ ๋ํด ์ค์ค๋ก ๊ฒ์ฌํ ์ ์๋๋ก self-reflection prompt ์ ์
- ๊ฒฐ๊ณผ์ ์ผ๋ก recall 95.6%, accuracy 99.4% ๋๋ฌ
6. Conclusion
- Mistral 7B๋ ์ธ์ด ๋ชจ๋ธ์ด ๊ธฐ์กด์ ์๊ฐ์ ์์ถํ๊ธฐ๋ณด๋ค ์ง์์ ์์ถํ๋ค๋ ๊ฒ์ ์์ฌํ๋ค.
- ๊ธฐ์กด: 2์ฐจ์(๋ชจ๋ธ ์ฑ๋ฅ, ํ์ต ๋น์ฉ) ๋ด์์ ๊ธฐ์ค์ ์ ํ๋ ๊ฒ์ ์ค์์
- Mistral 7B: ์ค์ ์ ์ธ ๋ฌธ์ ๋ 3์ฐจ์(๋ชจ๋ธ ์ฑ๋ฅ, ํ์ต ๋น์ฉ, ์ถ๋ก ๋น์ฉ)์ด๋ฉฐ, ๊ฐ๋ฅํ ์์ ๋ชจ๋ธ๋ก ์ต๊ณ ์ ์ฑ๋ฅ์ ๋ด๋ ๊ฒ์ ์๋ค.