MultiHeadAttention — Transformer 의 심장. num_heads, key_dim 인자. self-attention 은 query=key=value 같은 것 넘기기. cross-attention 은 다른 거 (encoder-decoder).
LayerNormalization — Transformer 에서 BatchNorm 자리 차지. batch 통계 안 쓰고 *feature 차원* 평균/분산. inference 시 batch 1 이어도 안정. 보통 attention/FFN block 의 *전* (pre-norm) 또는 *후* (post-norm) 에 박혀.
백엔드 노트:
⚙️ Backend Note
Code
# Multi-head attention (Transformer key component)
layers.MultiHeadAttention(
num_heads=8, # Number of attention heads
key_dim=64, # Dimension of each head
flash_attention=True, # Enable Flash Attention (3.7+)
)