최신 LLM 은 과거 token 을 어떻게 덜 읽는가
0한눈에 보기
과거 token 을 무엇을 남기고, 무엇을 읽나 — 7 방식의 차이는 이 두 가지뿐이다.
아래 표 한 장이 이 문서의 요약이고, 나머지 절은 이 표의 근거다.
| 방식 | 남기는 것 (보관) | 읽는 것 (token 1 개 생성 시) | 모델 |
|---|---|---|---|
| 0.1.1Full | 과거 token 전부 | 전부 | GLM-4.7, Qwen3, Kimi K2 |
| 0.1.2Sliding window | 최근 w 개만, 나머지 버림 | 그 w 개 전부 | gpt-oss, Gemma, MiMo |
| 0.1.3Linear | token 은 안 남김 · 고정 크기 행렬 S 하나에 누적 요약 | S 하나 | Qwen3.5·3.6, Kimi K3 |
| 0.1.4DSA | 전부 | 점수 상위 k 개 token (위치 무관) | DeepSeek V3.2, GLM-5 |
| 0.1.5QSA | 전부 | 점수 상위 4 개 묶음 | Qwen3.8-Flash-Next |
| 0.1.6CSA | 4 개씩 합친 요약 칸 + 최근 원본 | 요약 칸 상위 k 개 + 최근 원본 | DeepSeek V4 |
| 0.1.7HCA | 128 개씩 합친 요약 칸 + 최근 원본 | 요약 칸 전부 + 최근 원본 | DeepSeek V4 |
▸ 상세 보기
0.5이 페이지의 출처 표기 — Gallery Raschka LLM Architecture Gallery 본문·그림, config.json HuggingFace 공개 설정값을 직접 읽은 것, Gallery에 없음 이해를 돕기 위해 내가 덧붙인 배경 설명 또는 계산.
1기초: attention 과 KV cache
새 token 하나를 만들 때마다 과거 모든 token 의 K/V (KV cache) 를 memory 에서 읽는다.
context 가 길수록 보관량과 읽기량이 token 수에 비례해 커진다.
▸ 상세 보기
Query / Key / Value
도서관 비유 대신 실제 계산으로 적는다 Gallery에 없음. 현재 token 의 hidden statex_t 에 행렬 3개를 곱해 q_t = x_t W_Q, k_t = x_t W_K, v_t = x_t W_V 를 만든다. 출력은 o_t = Σ_s softmax_s(q_t·k_s/√d) · v_s. 즉 과거 token s 마다 score q_t·k_s 를 구하고, score 가 큰 token 의 value 를 많이 섞는다.
| 비용 | 언제 | full attention 에서 | 줄이는 방법 |
|---|---|---|---|
| 1.4.1KV 보관량 | 계속 | layer × token × (K+V 폭) | 폭↓ GQA/MLA · 개수↓ SWA/linear/compress |
| 1.4.2decode 읽기량 | token 생성마다 | ∝ 현재 길이 t | SWA(window), sparse(top-k), compress |
| 1.4.3prefill 계산량 | prompt 처리 | ∝ t² | SWA, linear(∝ t), sparse(∝ t·k) |
2두 개의 축: 폭 vs 개수
KV 크기 = token 당 폭 × 보관 token 수.
폭은 GQA·MLA 가, 개수는 SWA·Linear·Sparse·Compress 가 줄인다.
| class | 무엇을 줄이나 | 과거 token 접근 | 대표 모델 (Gallery) |
|---|---|---|---|
| 2.1.1Full | 없음 (폭만 GQA/MLA) | 전부 직접 | GLM-4.7, Qwen3-235B, MiniMax M2.x, Kimi K2.x |
| 2.1.2Sliding window + global | local layer 의 보관·읽기 | local = 최근 w 개, global layer = 전부 | gpt-oss, Gemma 3/4, MiMo-V2, OLMo 3, Step 3.5 |
| 2.1.3Linear / recurrent hybrid | 대부분 layer 의 KV 자체 (0 B/token) | 고정 크기 state 로 요약 + 일부 attention layer | Qwen3-Next/3.5/3.6/3.8, Kimi Linear/K3, Ling, Nemotron |
| 2.1.4Learned sparse | 읽기량 (보관은 그대로) | indexer 가 고른 top-k token/block | DeepSeek V3.2, GLM-5/5.1/5.2, MiniMax M3, Hy4 |
| 2.1.5Sequence compression | 보관 개수 + 읽기량 | 여러 token 을 1 entry 로 합친 것 + 최근 window | DeepSeek V4-Flash/Pro, V4.1-Flash |
▸ 상세 보기
3같은 문장으로 비교: 무엇을 저장하고 무엇을 읽나
slider 를 움직이면 7 방식의 cache 칸이 동시에 바뀐다. 진한 칸 = 읽음, 점선 = 버림, 넓은 칸 = 요약.
오른쪽 막대 = 출력에 정답 "서울" 이 얼마나 들어갔나. 줄을 누르면 아래에 단계 설명.
▸ 상세 보기
4연산 한 단계씩: tensor 로 보기
새 token 하나가 들어올 때 실제로 도는 연산을 순서대로 보여준다: weight 곱 → 점수 벡터 → top-k → gather → softmax → 출력.
칸 = 숫자 하나 (진할수록 큰 값) · 굵은 테두리 = 고른 위치 · 점선 = 버린 줄 · 출력의 서/부 = 서울/부산.
열 = 6 차원 (철수·영희·서울·부산·사는곳·기능어). toy 라 W = I 로 두어 x 가 곧 k, v 다. 실제 모델은 W 가 학습된 행렬이고 차원이 128~512 Gallery에 없음.
5Mask 실험실: 어떤 과거를 읽는가
행 = 현재 token, 열 = 과거 token 으로 읽는 칸을 색칠한 표. §3·§4 와 같은 내용을 mask 로 본 것.
▸ mask 실험실 열기 (32 token, 방식·window·top-k 조절)
실제 설정
6Layer 안의 연산 순서: QKV proj 와 출력 사이
바깥 틀은 모두 RMSNorm → mixer → + residual → RMSNorm → FFN 으로 같다.
다른 건 mixer 가 cache 에 무엇을 남기느냐 (아래 표). 방식별 순서도는 접힌 칸에.
| 방식 | mixer 핵심 연산 | layer 당 cache | token t decode 에 읽는 것 |
|---|---|---|---|
| 6.0.1.1Full (GQA) | softmax(q·Kᵀ)·V | token 마다 K, V [Nkv, hd] | t 개 전부 |
| 6.0.1.2SWA | 같음 + window mask, sink | 최근 w 개 K, V | w 개 |
| 6.0.1.3Gated DeltaNet / KDA | S 갱신 → Sᵀq | S [Nv, dk, dv] + conv state (고정) | S 하나 |
| 6.0.1.4DSA / QSA / MiniMax | indexer → top-k → softmax | K, V(또는 MLA latent) 전부 + indexer key | indexer key 전부 + top-k 개 K, V |
| 6.0.1.5CSA / HCA | gated pooling → (top-k) → softmax | 최근 128 원본 + t/ratio 개 압축 entry (+ indexer) | 128 + 512 (CSA) 또는 128 + t/128 (HCA) |
▸ 상세 보기
docs/attention/src_code/). 상자 색: projection norm·RoPE 핵심 연산 gate cache 저장▸ 공통 decoder layer
6.1공통 decoder layer
▸ Full causal attention (GQA · Qwen3-Next gated attention)
6.2Full causal attention (GQA · Qwen3-Next gated attention)
6.2.24번째 token 을 prefill 할 때: q₄ 가 cache 의 k₁…k₄ 와 각각 내적 → softmax 로 확률 p₁…p₄ → o₄ = Σ pᵢ vᵢ. 과거는 압축되지 않고 token 별로 그대로 남아 있다. Qwen 의 gate 는 q_proj 가 head 마다 [q | gate] 를 같이 내고, attention 출력에 sigmoid(gate) 를 곱한다 (L277, L308).
▸ Sliding window (gpt-oss)
6.3Sliding window (gpt-oss)
6.3.2순서도는 full 과 같고 두 곳만 다르다. ① mask 가 kv_idx > q_idx − 128 인 key 만 허용 (masking_utils L101) ② cache 가 최근 127 token 만 유지 (cache_utils L261–264). sink 는 head 마다 learned logit 하나를 key 축 끝에 붙여 softmax 분모에만 넣고 버린다 (gpt-oss L251–259) — 읽을 token 이 없을 때 확률을 흘려보낼 자리.
▸ Linear attention: Gated DeltaNet (Qwen3-Next / 3.5 / 3.6)
6.4Linear attention: Gated DeltaNet (Qwen3-Next / 3.5 / 3.6)
exp(g_t) 만큼 줄이고 → S 로 k_t 의 value 를 예측 (Sᵀk_t) → 실제 v_t 와의 차이에 β 를 곱해 → k_t 방향에만 덮어쓴다. 출력은 o_t = Sᵀq_t (L561–568).q₄ 를 S 에 곱하면, q₄ 와 방향이 비슷한 k 로 저장됐던 value 가 섞여 나온다 (softmax 대신 내적 가중).6.4.3# qwen3_next_modeling_qwen3_next.py L558–568 (decode 1 token = 이 loop 1회)
S = S * exp(g_t) # decay: 전체를 조금 잊는다
kv_mem = (S * k_t[:, None]).sum(-2) # Sᵀ k_t : 지금 S 가 k_t 에 대해 기억하는 value
delta = (v_t - kv_mem) * beta_t # 새 value 와의 차이만
S = S + k_t[:, None] * delta[None] # k_t 방향에 덮어쓰기 (delta rule)
o_t = (S * q_t[:, None]).sum(-2) # Sᵀ q_t : 읽기▸ Prefill 은 token 별 loop 가 아니라 chunk 단위
6.5Prefill 은 token 별 loop 가 아니라 chunk 단위
chunk_size=64). chunk 안은 attention 처럼 64×64 행렬로 한꺼번에, chunk 사이는 S 만 넘긴다.solve_triangular L498)가 필요하다.torch_recurrent_gated_delta_rule). Kimi KDA 도 64 token 이하면 fused recurrent, 초과면 chunk kernel.| 항목 | Gated DeltaNet (Qwen3-Next) | KDA (Kimi Linear) | 근거 |
|---|---|---|---|
| 6.5.3.1short conv | q·k·v 를 concat 한 뒤 conv 1 번, 그 다음 split | q, k, v 각각 따로 conv | L674/706 · kimi L541–557 |
| 6.5.3.2decay g | −exp(A_log)·softplus(a+dt_bias), head 당 scalar | 같은 식, channel 마다 (low-rank f_a→f_b) | L721 · fla gate L27–55 |
| 6.5.3.3β | sigmoid(b) head 당 | sigmoid(b_proj(x)) head 당 | L719 · kimi L561 |
| 6.5.3.4출력 gate | rmsnorm(o)·silu(z) | rmsnorm(o)·sigmoid(g_b(g_a(x))) | L762 · kimi L596–598 |
| 6.5.3.5cache (layer 당) | conv state + S [Nv, dk, dv] fp32 | conv state ×3 + S [32,128,128] | cache_utils L1035–1046 |
▸ Learned sparse: DSA (DeepSeek V3.2 · GLM-5)
6.6Learned sparse: DSA (DeepSeek V3.2 · GLM-5)
6.6.2indexer 는 본 attention 과 따로 작은 q(64 head × 128)와 k(1 head × 128)를 만들고, score[t,s] = Σ_h w_h · relu(q_h·k_s) 로 2,048 개를 고른다 (L457–487). 공개 reference 는 본 attention score 를 다 구한 뒤 나머지에 −inf 를 더하는 방식이다 (L584–586, L601–602). cache 는 MLA latent [512]+[64] 와 indexer key fp8 [128].
| 변형 | DSA 와 다른 점 | 근거 |
|---|---|---|
| 6.6.3.1QSA (Qwen3.8-Flash-Next) | cache 에는 raw key 만. query 마다 4 개씩 묶어 평균 → LayerNorm → block 첫 위치 RoPE 를 새로 계산 → top-512 block + 미완성 꼬리. head weight 없음 | qwen4_exp L706–762 |
| 6.6.3.2MiniMax SA (M3) | relu 없이 q·k → 128-key block 안 max → 현재 block 강제 포함 → top-16 block, indexer head(=KV group) 마다 따로 선택. layer 0–2 는 dense | minimax_m3 L557–602 |
| 6.6.3.3IndexShare (GLM-5.2) | indexer 를 full layer 에서만 돌리고 다음 3 layer 는 선택 결과를 재사용 | config indexer_types |
▸ Compression: CSA / HCA (DeepSeek V4)
6.7Compression: CSA / HCA (DeepSeek V4)
kv = wkv(x) 와 점수 score = wgate(x) + ape[pos % ratio] 를 만든다 (L323).(pos+1) % 4 == 0, L344) 모아 둔 token 들의 score 를 channel 마다 softmax 해 kv 를 가중합 → entry 1 개 → RMSNorm → block 첫 위치 RoPE → fp8 → cache.wkv 출력(2×512)을 앞 절반·뒤 절반으로 나눠, C₂ 는 t₁–t₄ 의 앞 절반과 t₅–t₈ 의 뒤 절반 8 개를 channel 마다 softmax 가중합한다 code deepseek_v4_flash_model.py L307–352.▸ 한 표로: cache 에 무엇이 남나
6.8한 표로: cache 에 무엇이 남나
7폭 축: MHA → GQA → MLA
GQA 는 K/V head 를 여러 query 가 공유, MLA 는 K/V 를 512 차원으로 압축해 저장한다.
token 개수는 그대로라 긴 context 에서는 개수를 줄이는 방식이 따로 필요하다.
▸ 상세 보기
▸ 폭 축에 붙는 부가 기법
7.1폭 축에 붙는 부가 기법
| 기법 | 무엇 | KV 에 영향 | 모델 |
|---|---|---|---|
| 7.1.1.1Gated attention | SDPA 출력에 sigmoid gate 를 곱함: Y = (A ⊙ σ(XW_g)) W_o | 없음. 보관·계산량 그대로 | Qwen3-Next/3.5+, Trinity, Laguna, Hy4 |
| 7.1.1.2Cross-layer KV sharing | 뒤 layer 가 앞 layer 의 K/V 를 재사용 | KV 생산 layer 수↓ | Gemma 4 E2B/E4B, DeepSeek V4.1 (kv_source_layer_ids) |
| 7.1.1.3Unified K=V | K 와 V 를 한 tensor 로 | global layer 저장 ½ | Gemma 4 (attention_k_eq_v) |
| 7.1.1.4Attention budgeting | layer 마다 query head 수를 다르게 | 없음 (kv head 고정) | Laguna XS.2: full 48 q head / SWA 64 q head |
8Sliding window attention (SWA) + global
최근 w 개 (128~4,096) 만 남기고 나머지는 버린다. 몇 layer 마다 한 번 global layer 가 전체를 본다.
window 밖 정보는 그 global layer 로만 전달된다.
▸ 상세 보기
▸ 모델별 설정 (config.json 에서 직접 확인)
8.1모델별 설정 (config.json 에서 직접 확인)
| 모델 | local:global | window w | layer 배치 | 특이점 |
|---|---|---|---|---|
| 8.1.1.1gpt-oss-120b (2025-08) | 1:1 | 128 | sliding, full 교대 ×18 | attention sink (learned bias) Gallery에 없음 |
| 8.1.1.2Gemma 3 27B (2025-03) | 5:1 | 1,024 | 52 sliding + 10 global | Gemma 2 는 1:1, w 4096 Gallery |
| 8.1.1.3Xiaomi MiMo-V2-Flash (2025-12) | 5:1 | 128 | 40 sliding + 8 global | add_swa_attention_sink_bias: true |
| 8.1.1.4OLMo 3 32B (2025-11) | 3:1 | 4,096 | 48 sliding + 16 full | |
| 8.1.1.5Arcee Trinity Large (2026-01) | 3:1 | 4,096 | 45 sliding + 15 global | global layer 는 NoPE, gated attention |
| 8.1.1.6Step 3.5 Flash (2026-02) | 3:1 | 512 | 36 sliding + 12 full | SWA layer 96 q head / full 64 q head |
| 8.1.1.7Gemma 4 31B (2026-04) | 5:1 | 1,024 | 50 sliding + 10 full | global: K=V 통합, head_dim 512, partial RoPE 0.25 |
| 8.1.1.8Laguna XS.2 (2026-04) | 3:1 | 512 | 30 sliding + 10 full | per-layer q head 수 (48/64) |
| 8.1.1.9MiMo-V2.5-Pro 1.02T (2026-04) | 6:1 | 128 | 60 sliding + 10 global | 1M context |
8.1.2근거: docs/attention/configs/*.json 의 sliding_window, layer_types, hybrid_layer_pattern. Gemma 3 27B 는 config 접근이 막혀 Gallery 본문 값.
9Linear attention hybrid (Gated DeltaNet · KDA · Lightning · Mamba-2)
token 을 하나도 남기지 않고, 고정 크기 행렬 S 하나에 계속 덧써서 요약한다. window 에서 고르는 방식이 아니다.
S 는 세부를 흐리므로, 4 layer 중 1 layer 는 일반 attention 을 남겨 정확한 조회를 보완한다.
▸ 상세 보기
Linear attention 과 state
softmax 를 빼면o_t = Σ_s (q_t·k_s) v_s = (Σ_s v_s k_sᵀ) q_t 로 괄호 안을 미리 누적할 수 있다. 이 누적 행렬 S_t = S_{t-1} + v_t k_tᵀ (크기 d_v × d_k, 고정) 가 state 다. 새 token 은 S 를 한 번 갱신하고 S 에 q 를 곱하면 끝이라, 과거 token 개수와 무관하다 Gallery에 없음.
Delta rule 과 gate (Gated DeltaNet)
단순 누적은 state 가 계속 뒤섞여 오래된 내용을 못 지운다. Gated DeltaNet 은S_t = α_t · S_{t-1}(I − β_t k_t k_tᵀ) + β_t v_t k_tᵀ 로 갱신한다. α(decay gate)는 얼마나 잊을지, β(write 강도)는 k_t 위치에 있던 옛 값을 새 v_t 로 얼마나 덮어쓸지 정한다 Gallery · Hybrid Attention (수식 Gallery에 없음). KDA 는 α 를 head 당 scalar 가 아니라 feature channel 마다 따로 학습한다 Gallery.
▸ 모델별 hybrid 구성
9.1모델별 hybrid 구성
| 모델 | recurrent | attention | 비율 | state/layer (bf16) | KV/token |
|---|---|---|---|---|---|
| 9.1.1.1Qwen3-Next 80B-A3B (2025-09) | Gated DeltaNet ×36 | Gated GQA ×12 | 3:1 | 1 MiB | 24 KiB |
| 9.1.1.2Kimi Linear 48B (2025-10) | KDA ×20 | MLA ×7 | ≈3:1 | 1 MiB | 7.9 KiB |
| 9.1.1.3Qwen3.5 397B (2026-02) | Gated DeltaNet ×45 | Gated GQA ×15 | 3:1 | 2 MiB | 30 KiB |
| 9.1.1.4Ling 2.5 1T (2026-02) | Lightning ×70 | MLA ×10 | 7:1 | — | 11.2 KiB |
| 9.1.1.5Nemotron 3 Super (2026-03) | Mamba-2 ×40 | GQA ×8 | 5:1 | — | 8 KiB |
| 9.1.1.6Qwen3.6 / 3.8 27B (2026-04/08) | Gated DeltaNet ×48 | Gated GQA ×16 | 3:1 | 1.5 MiB | 64 KiB |
| 9.1.1.7Kimi K3 2.8T (2026-07) | KDA ×69 | Gated MLA (NoPE) ×24 | ≈3:1 | 3 MiB | 27 KiB |
| 9.1.1.8GLM-5.3-Flash 320B (2026-08) | KDA ×34 | MLA + DSA ×11 | 3:1 | 2 MiB | 11 KiB |
| 9.1.1.9Qwen3.8-Flash-Next 125B (2026-08) | Gated DeltaNet ×36 | QSA ×12 | 3:1 | 1.5 MiB | 24 KiB |
9.1.2state/layer = value head 수 × key dim × value dim × 2 byte (예: Qwen3.5 64 × 128 × 128 × 2 = 2 MiB) 계산. 실제 구현은 state 를 fp32 로 두는 경우가 많아 2배일 수 있다. Gallery 는 이 고정 state 를 KV/token 에서 제외한다.
10Learned sparse attention (DSA · IndexShare · QSA · MiniMax SA)
K/V 는 전부 보관하고, 작은 indexer 가 점수를 매겨 상위 2,048 개만 읽는다.
고르는 단위: DSA = token 1 개, QSA = 4 개 묶음, MiniMax = 128 개 묶음.
▸ 상세 보기
▸ DSA: lightning indexer + top-k
10.1DSA: lightning indexer + top-k
10.1.1# Gallery 의 pseudo code (DeepSeek V3.2)
# t = 현재 위치, s = 과거 위치, j = indexer head
I[t,s] = Σ_j w[t,j] · ReLU(q[t,j] · k[s]) # 모든 s 에 대해 (가벼움)
selected = top_k(I[t,:], k=2048)
output = MLA_attention(q_t, KV[selected]) # 2048 개만 (무거움)| 모델 | index_topk | indexer head × dim | 본체 | config 근거 |
|---|---|---|---|---|
| 10.1.2.1DeepSeek V3.2 (2025-12) | 2,048 | 64 × 128 | MLA 61 layer | index_topk, index_n_heads |
| 10.1.2.2GLM-5 / 5.1 (2026-02/04) | 2,048 | 32 × 128 | MLA 78 layer | index_topk |
| 10.1.2.3GLM-5.2 (2026-06) | 2,048 | 32 × 128 | MLA 78 + IndexShare | indexer_types = full×3, (shared×3, full)… |
| 10.1.2.4Tencent Hy4-preview (2026-08) | 2,048 | 32 × 128 | Gated MLA 78 + IndexShare | indexer_types |
| 10.1.2.5GLM-5.3-Flash (2026-08) | 2,048 | 32 × 128 | 11 MLA/DSA + 34 KDA | index_kpool: 4, always_select_tail |
▸ IndexShare: indexer 결과를 4 layer 가 공유
10.2IndexShare: indexer 결과를 4 layer 가 공유
▸ QSA 와 MiniMax Sparse Attention: block 단위 선택
10.3QSA 와 MiniMax Sparse Attention: block 단위 선택
| 항목 | DSA | QSA (Qwen3.8-Flash-Next) | MiniMax SA (M3) |
|---|---|---|---|
| 10.3.1.1선택 단위 | token 1개 | 4-token micro-block | 128-token block |
| 10.3.1.2block key | — | block 내 key 평균 → norm → RoPE(첫 위치) | sparse_score_type: max |
| 10.3.1.3예산 | 2,048 token | 512 block = 2,048 token + 현재 미완성 block | 16 block × 128 = 2,048 token + local block 1 |
| 10.3.1.4indexer | 32~64 head × 128 | 4 head × 128, kv head 1 | 4 head × 128 |
| 10.3.1.5적용 layer | 전 layer | 12 QSA (나머지 36 은 DeltaNet) | 57 layer (앞 3 layer 는 dense GQA) |
10.3.2근거: QSA 는 Gallery 본문 + indexer_budget 2048, indexer_compress_ratio 4. MiniMax SA 는 Gallery 에 설명 페이지가 없어 sparse_attention_config 값만 옮겼다 config.json. block score 를 max 로 뽑는다는 것 외의 동작은 미확인.
11Sequence compression (DeepSeek V4 CSA/HCA · V4.1 CSA2)
이웃 token 여러 개를 요약 칸 1 개로 합쳐 보관한다 (CSA 4→1, HCA 128→1) + 최근 128 개 원본.
CSA 는 요약 칸 중 상위 k 개, HCA 는 요약 칸 전부를 읽는다.
▸ 상세 보기
| V4-Flash layer | 개수 | compress_ratio | 읽는 것 | 보관 byte / 원본 token |
|---|---|---|---|---|
| 11.0.4.1SWA only (layer 0, 1) | 2 | 0 | 최근 128 | 0 (window 고정) |
| 11.0.4.2CSA (짝수 layer 2~42) | 21 | 4 | top-512 entry (= 2,048 원본 token) + 최근 128 | 1,024 / 4 = 256 |
| 11.0.4.3HCA (홀수 layer 3~41) | 20 | 128 | 전체 entry (L/128) + 최근 128 | 1,024 / 128 = 8 |
11.0.5근거: compress_ratios=[0,0,4,128,4,128,…,4,0] (마지막은 MTP), sliding_window 128, index_topk 512, head_dim 512, num_key_value_heads 1. 21×256 + 20×8 = 5,536 B = 5.4 KiB 로 Gallery 값과 일치 계산.
▸ V4.1-Flash: CSA2 + encoder-decoder
11.1V4.1-Flash: CSA2 + encoder-decoder
| CSA2 mode | 동작 (Gallery 그림 주석) | config |
|---|---|---|
| 11.1.2.1Full | global KV 와 sparse index 를 새로 만든다 | kv_source_layer_ids [2,8,14,20] |
| 11.1.2.2Reindex | KV 는 공유, sparse index 만 다시 계산 | index_source_layer_ids [2,8,…,36] |
| 11.1.2.3Reuse | KV 와 sparse index 모두 공유 | 나머지 layer |
| 11.1.2.4Candidate pool | 첫 decoder Full layer 가 후보 pool 을 만들고 이후 Reindex 가 계층적으로 고름 | candidate_topk_blocks 2048, block_size 8, index_topk 512 |
11.1.3compress ratio 는 encoder 2, decoder 1 (compress_ratios). Gallery 계산: (3 encoder cache / 2 + 1 decoder cache) × (512 KV + 128 indexer key) × 2 B = 3,200 B. tech report 는 FP4 로 890 B/token. candidate pool 의 정확한 선택 절차는 원 논문 미확인.
12Family 별 변천
DeepSeek: MLA → DSA → CSA/HCA · Qwen: GQA → Linear 3:1 → + QSA · GLM: GQA → DSA → Linear + DSA.
그림을 누르면 크게 열린다.
▸ 상세 보기
13보관량 vs 읽기량 계산기
context 길이별 보관 KV 와 decode 1 step 읽기량 (batch 1, bf16).
Gallery KV/token 과 달리 SWA window 와 sparse 읽기를 반영했다.
▸ 상세 보기
| 모델 | class | layer 구성 | 보관 KV | 1 step 읽기 | 고정 state |
|---|
13.5조건: batch 1, bf16, sequence 1개, layer 당 byte 는 configs/*.json 에서 계산하여 Gallery KV/token 과 대조. 계산식은 이 파일의 CALC 배열. † = 모델 최대 context (Gallery 값) 를 넘는 가정 셀.
14전체 106 모델 표
Gallery 106 모델의 attention 구성 (검색·분류 필터).
표는 접힌 칸에.
▸ 상세 보기
| # | 날짜 | 모델 | class | attention | layer mix | KV/token | context |
|---|
14.3원본: docs/attention/gallery_models.csv (Gallery 2026-09-28 수집). class 는 attention 문자열로 자동 분류, linear+sparse 조합은 linear 로 두고 "+sparse" 표시.
15정리와 한계
SWA 는 window 밖, Linear 는 세부, Sparse 는 놓친 token, Compress 는 요약 안 세부를 잃는다.
보고된 효율 수치는 모델 전체 비교이지 기법 단독 효과가 아니다.
| 방식 | 잃는 것 | 남는 비용 |
|---|---|---|
| 15.1.1SWA | local layer 는 window 밖을 직접 못 본다 | global layer 의 KV 는 t 에 비례 |
| 15.1.2Linear hybrid | state 가 고정 크기라 개별 token 을 정확히 못 꺼냄 | attention layer KV + 고정 state (수 MiB/layer) |
| 15.1.3Learned sparse | indexer 가 놓친 token | KV 전체 보관, indexer 가 모든 key 를 훑음 |
| 15.1.4Compression | 먼 과거의 token 단위 세부 | 압축 entry + window, indexer |
▸ 상세 보기
- 15.2
- 15.2.1Gallery 가 반복해 강조하는 한계: 효율 수치(V4 의 10%, Ling 의 3.5×, GLM-5.2 의 2.9×)는 모두 모델 전체 비교이고 attention 기법 단독 ablation 이 아니다 Gallery.
- 15.2.2DSA 의 목표는 dense 대비 품질 향상이 아니라 "sparse 로 바꿔도 덜 떨어지게" 하는 것 Gallery · DSA.
- 15.2.3MLA 는 약 100B 미만에서는 GQA 보다 tuning 이 어렵다는 의견이 있다 (Sarvam 30B GQA / 105B MLA) Gallery · MLA.
- 15.2.4Gallery에 없음 시스템 관점: sparse·compress 는 decode 읽기량을 2K~수K entry 로 고정하지만 KV 보관(sparse) 또는 indexer key 는 context 에 비례해 남는다. KV 를 CPU/CXL 등 느린 memory 로 내리는 설계에서는 "무엇을 보관하나" 와 "무엇을 load 하나" 를 분리해 볼 수 있다.
16용어와 출처
용어 한 줄 정의와 출처 링크.
▸ 상세 보기
| 용어 | 한 줄 |
|---|---|
| 16.1.1KV cache | 과거 token 의 Key/Value 를 layer 마다 저장한 것 |
| 16.1.2prefill / decode | prompt 전체를 한 번에 처리 / 이후 token 을 1개씩 생성 |
| 16.1.3GQA / MQA | 여러 query head 가 kv head 를 공유 (MQA = kv head 1개) |
| 16.1.4MLA | K/V 를 저차원 latent 로 압축해 저장 (DeepSeek-V2) |
| 16.1.5SWA | 최근 w token 만 보는 attention |
| 16.1.6Gated DeltaNet / KDA | delta rule 로 고정 크기 state 를 갱신하는 linear attention / 그 channel 별 decay 판 |
| 16.1.7Lightning Attention | Ling 이 쓰는 recurrent linear attention |
| 16.1.8Mamba-2 | state-space model, recurrent state 로 sequence 처리 |
| 16.1.9DSA | lightning indexer 로 top-k token 을 골라 attention |
| 16.1.10IndexShare | DSA 의 선택 결과를 다음 3 layer 가 재사용 |
| 16.1.11QSA | 4-token block 단위로 고르는 Qwen 의 sparse attention |
| 16.1.12CSA / HCA | 4→1 압축 + top-k / 128→1 압축 + dense |
| 16.1.13mHC | residual 을 여러 stream 으로 나눠 섞는 연결 방식 (attention 과 별개) |
| 16.1.14attention sink | 의미 없이 첫 token 등에 score 가 몰리는 현상, 또는 이를 흡수하는 learned bias |
- 16.2
- 16.2.1LLM Architecture Gallery (Raschka) — 모든 그림의 출처
- 16.2.2KV cache / token 계산법
- 16.2.3Hybrid Attention · DSA · CSA/HCA · QSA · IndexShare · SWA
- 16.2.4HF config.json 사본:
docs/attention/configs/(27개)