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

Hardware-Aware Selective Scan

~14 min · scan, cuda, kernels, memory-hierarchy

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

Convolution 트릭 사라짐 — 이제 뭐?

Selectivity 가 convolution view 깼으니, Mamba 는 학습 중 parallel 할 새 방법 필요했어. 답은 hardware-aware selective scan: GPU memory hierarchy 에 맞춰 짠 parallel prefix-scan algorithm, 중간 state 를 fast on-chip SRAM 에 유지하고 안 그러면 runtime 을 dominate 할 slow HBM trip 회피.

이게 FlashAttention 과 같은 엔지니어링 철학. 두 논문 다 Tri Dao 그룹에서; 둘 다 "복잡한 sequence 연산이 modern GPU 를 실제 활용하게 어떻게 만들어?" 의 답. Selective scan kernel (`mamba_ssm.ops.selective_scan_interface`) 은 본질적으로 이걸 하는 수백 줄 CUDA: sequence tile, tile 을 SRAM 유지, 로컬에서 recurrence 수행, tile 당 final state 만 write back. 결과는 잘 구현된 attention kernel 에 비교 가능한 GPU utilization, 연산이 matmul 이 아닌 recurrence 인데도.

Architecture-level 단순화

Mamba 는 또 많은 architectural overhead 를 버렸어. 표준 Transformer block 은 block 당 attention sub-layer 와 MLP sub-layer 둘 다. Mamba block 은 SSM sub-layer 만 — separate MLP 없음. 내부 구조는 block 당 두 parallel branch: 한 branch 는 Conv1D 거치고 selective SSM; 다른 branch 는 SiLU-gated linear projection. 두 branch 가 elementwise combine, 다시 model dim 으로 project. layer 당 fewer parameter, fewer op, simpler graph.

실제 wall-clock 이득

Mamba 는 동등 quality 에서 Transformer 대비 5× 추론 throughput 보고, gap 이 더 긴 sequence 에서 넓어져 (Transformer attention 이 quadratic 부분이고, Mamba 의 토큰 당 cost 는 sequence length 에 constant 니까). 3B scale 에서, Mamba 는 parameter count 약 두 배인 Transformer 모델과 매치 또는 초과. 이게 그냥 FLOP-count 주장 아냐; hardware-aware kernel 덕에 FLOP advantage 가 wall clock 에 실제 나타남.

핵심: 효율적 algorithm 만으로 안 돼 — hardware-shaped 구현이 필요. SSM 이 2010 년대 second wind 받은 건 수학이 개선돼서가 아니라 (수십 년간 거기 있었어) 마침내 누가 kernel 을 짰기 때문이야.

External links

Exercise

selective_scan_interface.py source 읽어. CUDA 깊이 이해할 필요 없어 — 근데 Python wrapper 따라가서 코드가 non-CUDA path 로 fallback 할 수 있는 지점, 그 경우 뭘 잃을지 식별. (힌트: selective_scan_reftorch reference 구현은 수학적으로 동등하고 long sequence 에서 수백 배 느려.) 운동의 핵심은 Mamba 가 자기 kernel 에 가진 의존성을 tangible 하게 만드는 거야.

Progress

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

댓글 0

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

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