Attention 모드¶
개요¶
RBLN vLLM은 Full Attention, Sliding-Window Attention(SWA), Multi-head Latent Attention(MLA)을 지원합니다.
- Full Attention은 attention mask가 허용하는 모든 컨텍스트 토큰을 참조합니다.
- Sliding-Window Attention(SWA)은 모델에 설정된 윈도우 내의 토큰만 참조합니다.
- Multi-head Latent Attention(MLA)은 key와 value의 압축된 latent 표현을 KV 캐시에 저장하고, MLA backend를 사용합니다.
Full Attention에서는 vllm과 transformers(optimum) model implementation 모두 다음 두 가지 계산 방식을 지원합니다.
- Naive Attention은 요청당 KV 캐시 블록 하나를 사용합니다. 유효한 토큰에 대해 attention score를 계산하고 softmax를 적용한 뒤, 그 가중치를 value 행렬(V)에 곱합니다.
- Flash Attention은 각 요청의 KV 캐시를 파티션 단위로 처리하고, online softmax를 사용해 파티션별 계산 결과를 합칩니다.
vllm model implementation¶
Full Attention¶
Full attention 레이어는 causal masking으로 각 query가 참조할 수 있는 토큰을 제한합니다.
커널 선택¶
- Naive Attention은
block_size== max_model_len이고 해당 레이어에 attention sink가 없을 때 사용합니다. - Flash Attention은
block_size < max_model_len이거나 해당 레이어에 attention sink가 있을 때 사용합니다.
block_size는 아래 지원 범위 내에서 2의 거듭제곱이어야 합니다.
| 장치 | Naive / Flash Attention |
|---|---|
| Rebel100™ | 512–16,384 토큰 |
예시¶
아래 예시는 block_size를 조정해 Naive Attention과 Flash Attention을 선택하는 방법을 보여줍니다. MLA를 사용하지 않는 모델의 attention sink가 없는 full attention 레이어에 적용되며, <MODEL_ID>는 사용할 모델 ID로 바꿉니다.
FP8 KV cache
Naive Attention은 FP8 KV cache를 지원하지 않습니다.
Sliding-Window Attention(SWA)¶
Sliding-Window Attention 레이어는 모델에 설정된 윈도우 내의 토큰만 참조합니다.
적용 예시는 GPT-OSS-120B recipe에서 확인할 수 있습니다.
Multi-head Latent Attention(MLA)¶
MLA는 key와 value의 압축된 latent 표현을 KV 캐시에 저장하며, Dense와 Sparse 두 형태가 있습니다. DeepSeek-V3.2는 Sparse MLA를 사용합니다.
FP8 KV cache
FP8 KV cache는 Sparse MLA에서만 지원합니다.
transformers(optimum) model implementation¶
transformers(optimum) 구현은 RBLN Optimum으로 컴파일한 모델을 사용합니다. RBLN Optimum은 컴파일 시 모델의 attention 설정을 결정합니다.
미리 컴파일된 모델은 rbln_config.json에 기록된 attention 설정을 그대로 사용합니다.
Full Attention¶
커널 선택¶
엔진 시작 시 모델을 컴파일할 때 full attention 레이어에 적용되는 Naive/Flash 선택 조건은 다음과 같습니다.
- Naive Attention은
block_size== max_model_len일 때 사용합니다. - Flash Attention은
block_size < max_model_len이고max_model_len % block_size == 0일 때 사용합니다.
block_size는 아래 지원 범위 내에서 2의 거듭제곱이어야 합니다. 지원 범위는 장치와 attention 방식에 따라 다릅니다.
| 장치 | Naive Attention | Flash Attention |
|---|---|---|
| ATOM™ | 최대 32,768 토큰 | 1,024–32,768 토큰 |
| Rebel100™ | 최대 16,384 토큰 | 1,024–16,384 토큰 |
풀링 모델과 인코더-디코더 모델은 Naive Attention을 사용하며, block_size == max_model_len이어야 합니다. block_size를 생략하면 자동으로 max_model_len으로 설정됩니다. Qwen3 백본 기반 풀링 모델은 예외입니다. Flash Attention을 사용하려면 위 조건을 충족하는 block_size를 명시적으로 지정해야 합니다.
예시¶
아래 예시는 엔진 시작 시 모델을 컴파일할 때 block_size를 조정해 Naive Attention과 Flash Attention을 선택하는 방법을 보여줍니다. Flash Attention 예시는 이를 지원하는 모델에만 사용할 수 있으며, <MODEL_ID>는 사용할 모델 ID로 바꿉니다.
Sliding-Window Attention(SWA)¶
Sliding-Window Attention 레이어는 모델에 설정된 윈도우 내의 토큰만 참조합니다.