C.W.K.
Stream
Lesson 01 of 05 · published

RetNet 이 뭐야

~13 min · retnet, retention, microsoft-research

Level 0Observer
0 XP0/50 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Retention — exponential decay 와 함께 recurrence

RetNet (Sun et al., 2023.7, arXiv:2307.08621, Microsoft Research Asia) 가 retention 메커니즘 도입, recurrence 또는 constrained 한 종류의 attention 으로 볼 수 있는 통합 primitive. 핵심 update 는 즐겁게 단순: s_n = γ · s_{n-1} + K_n^T · V_n, output o_n = Q_n · s_n. State s 는 SSM hidden state 와 정확히 같아 — fixed size, 모든 과거 토큰 요약.

Decay γ 가 디자인 선택. RetNet 은 γ 를 attention head 마다 fixed, 다른 head 가 다른 γ 값. γ ≈ 1 인 head 는 long memory 유지 (slow decay). γ ≈ 0 인 head 는 short memory 유지 (fast decay). 이게 자연스럽게 multi-scale memory hierarchy 만들어: 어떤 head 는 최근 과거에 attention, 다른 건 깊은 과거에, 다 parallel.

Positional encoding: xPos

RetNet 은 positional encoding 에 xPos 사용 — RoPE 와 밀접하게 관련된 complex-exponential rotation, retention 메커니즘의 recurrent 형태에 디자인됨. xPos 는 translation invariance 사주고 (모델이 absolute position 신경 안 쓰고, relative offset 만), recurrent computation 과 호환 유지. 개념적 level 에서는 별로 안 중요한데 구현 level 에서는 많이 중요한 종류의 detail.

왜 흥미로운가

수학적 깔끔함이 헤드라인. Retention 이 recurrence (per-token state update 로 쓸 수 있어) 이고 attention 이기도 (recurrent 형태가 exponential decay 가진 특정 종류의 attention matrix 로 unroll). 이 통합 — recurrence 와 attention 이 fundamentally 다르지 않고 continuum 위 점들이라는 — 이 RetNet 의 lasting intellectual 기여. linear-attention/SSM 쪽 이후 모든 architecture 가 이 통찰의 어떤 버전 흡수.

Code

RetNet retention update·python
# Per timestep n, given input x_n:
# Q_n, K_n, V_n produced from x_n by linear projections
# gamma is FIXED per-head (no input dependence — the key constraint)

# Recurrent form (constant memory at inference)
s_n = gamma * s_prev + K_n.transpose(-1, -2) @ V_n
o_n = Q_n @ s_n

# Parallel form (training): equivalent to attention with exponential-decay mask
# attn_mask[i, j] = gamma ** (i - j) for j <= i, else 0

External links

Exercise

Retention 연산을 PyTorch 에 parallel 과 recurrent 형태 둘 다로 구현, 작은 (1, 64, 8, 16) Q/K/V/gamma input 에서 동일 output 산출 확인. 같은 parameter 가 두 다른 evaluation pattern 아래 같은 output 내는 사실이 RetNet 한테 production flexibility 주는 핵심 속성이고 — 이 dual structure 안 가진 architecture 들에는 이 속성 carry over 안 함.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.