
v1 causal mask 는 전체 하삼각. Longformer (Beltagy 2020), Mistral, Gemma 등은 sliding window: 각 토큰이 과거 개만 참조. 복잡도 .
즉 causal (j ≤ i) + band (최대 w개 뒤까지).
함수 sliding_window_mask(L, window_size) 를 완성하세요.
(L, L), dtype bool.mask[i, j] = True iff 0 ≤ i - j < window_size.힌트: i = np.arange(L)[:, None], j = np.arange(L)[None, :] → 벡터화.
| # | 이름 | 검증 |
|---|---|---|
| 1 | shape (L, L), bool | |
| 2 | 대각선 True | self-attention 허용 |
| 3 | 상삼각 False | causal 유지 |
| 4 | window=1 → identity | 대각만 True |
| 5 | window ≥ L → full tril | v1 causal 과 동일 |
| 6 | row i 의 True 개수 = min(i+1, w) | |
| 7 | 구체 좌표 검증 | M[5,2] 등 |
코드를 작성하고 Run 을 눌러보세요.