본문 바로가기

LLM

SGLang Attention Backend 완전 비교 — Triton, FlashInfer, FA3, TRTLLM

반응형

SGLang으로 서버 띄울 때 이 파라미터를 보게 돼요.

python -m sglang.launch_server \
  --model-path Qwen/Qwen3.5-9B-Instruct \
  --attention-backend ???  # 뭘 써야 하지?

옵션이 여러 개예요.

triton
flashinfer
fa3 (flashattention3)
trtllm_mha
trtllm_mla
fa4 (최신)

각각이 뭔지, 언제 써야 하는지 정리할게요.


백엔드가 뭔가

Attention 계산을 어떤 커널(저수준 GPU 코드)로 처리할지 결정하는 거예요.

SGLang 서버
    ↓
Attention Backend 선택
    ↓
┌──────────────────────────────────────┐
│ Triton    │ FlashInfer │ FA3 │ TRTLLM │
│ (범용)    │ (서빙 특화) │(H100)│(Blackwell)│
└──────────────────────────────────────┘
    ↓
GPU에서 실제 Attention 계산

같은 모델이라도 백엔드에 따라 처리량과 레이턴시가 달라져요.


1. Triton 백엔드

뭔가: OpenAI가 만든 Python-like GPU 프로그래밍 언어인 Triton으로 작성된 커널이에요.

python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.3-70B-Instruct \
  --attention-backend triton

특징:

장점:
✅ 가장 넓은 GPU 호환성 (거의 모든 NVIDIA GPU)
✅ 커스터마이징 쉬움 (Python-like 문법)
✅ AMD GPU 지원 가능성 있음
✅ 디버깅/수정 용이
✅ 안정적 (검증된 백엔드)

단점:
❌ FA3, FlashInfer 대비 처리량 낮음
❌ H100 하드웨어 기능 완전 활용 못함

언제 써야 하나:

✅ 구형 GPU (A10G, V100, RTX 3090)
✅ AMD GPU
✅ 커스텀 Attention 변형 구현할 때
✅ 디버깅 중
✅ 안정성이 최우선일 때

2. FlashInfer 백엔드

뭔가: LLM 서빙에 특화된 고성능 Attention 커널 라이브러리예요. University of Washington + NVIDIA 공동 개발이에요.

python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.3-70B-Instruct \
  --attention-backend flashinfer

핵심 기술:

Block-Sparse Row (BSR) 형식:
→ KV Cache의 다양한 레이아웃 (Paged, Radix, Tree)을
  하나의 통합된 형식으로 표현
→ 여러 요청의 다양한 시퀀스 길이를 효율적으로 처리

JIT (Just-In-Time) 커널 생성:
→ 실행 시점에 하드웨어에 최적화된 커널 자동 생성
→ RoPE 등 연산과 Attention을 퓨전 가능

Load-Balanced Dynamic Scheduler:
→ 요청 길이가 들쭉날쭉해도 GPU 균등 활용
→ 스큐드(skewed) 배치에서 FA 대비 2배 높은 효율

성능:

Llama 3 8B, H100 기준 Triton 대비:
Inter-Token Latency: 29~69% 감소
TTFT: 21% 감소
GPU 대역폭 활용률: 45% → 70~83%

특징:

장점:
✅ 서빙 워크로드에서 Triton보다 빠름
✅ 길이가 다양한 배치에서 특히 강함
✅ MQA, GQA, MLA 모두 지원
✅ CUDA Graph 호환 (저레이턴시)
✅ Speculative Decoding 지원

단점:
❌ 처음 실행 시 JIT 컴파일 시간 (몇 초)
❌ FA3보다는 느린 경우 있음
❌ NVIDIA GPU 전용

언제 써야 하나:

✅ A100 GPU
✅ 요청 길이가 다양한 일반 서빙
✅ 멀티턴 대화 (길이 편차 큼)
✅ DeepSeek 같은 MLA 아키텍처
✅ vLLM 대비 성능 올리고 싶을 때

3. FA3 (FlashAttention 3) 백엔드

뭔가: Tri Dao가 만든 FlashAttention 3를 SGLang에 통합한 백엔드예요.

python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.3-70B-Instruct \
  --attention-backend fa3

핵심:

H100 전용 최적화:
- Tensor Core 비동기 실행
- TMA (Tensor Memory Accelerator) 활용
- Warp-Specialization으로 계산/메모리 이동 겹침
- FP8 지원

성능:
H100에서 740 TFLOPS (이론 최대의 75%)
FA2 대비 1.5~2.0배 빠름

SGLang 0.4.6부터 기본 백엔드 (H100에서)

장점:
✅ H100에서 최고 처리량
✅ 대용량 배치에서 특히 강함
✅ 긴 컨텍스트(1M+) 처리 최적
✅ FP8 지원

단점:
❌ H100/A100만 완전 지원
❌ 구형 GPU에서는 FA2로 폴백
❌ FlashInfer보다 짧은 시퀀스 Decode 느릴 수 있음

언제 써야 하나:

✅ H100 GPU (필수)
✅ 긴 컨텍스트 (32K+) 처리
✅ 대용량 배치 (batch size 크게)
✅ 훈련/파인튜닝 병행 서빙
✅ Speculative Decoding V2 사용 시

4. TRTLLM 백엔드 (trtllm_mha / trtllm_mla)

뭔가: NVIDIA TensorRT-LLM의 Attention 커널을 SGLang에서 사용하는 백엔드예요.

# MHA (Multi-Head Attention) — 일반 모델
python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.3-70B-Instruct \
  --attention-backend trtllm_mha

# MLA (Multi-head Latent Attention) — DeepSeek
python -m sglang.launch_server \
  --model-path deepseek-ai/DeepSeek-V3 \
  --attention-backend trtllm_mla \
  --enable-mla

특징:

장점:
✅ Blackwell GPU (B100, GB10) 지원
✅ NVIDIA 공식 최적화 커널
✅ SM100 아키텍처 전용 최적화
✅ DeepSeek MLA 특화 (trtllm_mla)

단점:
❌ Blackwell 전용 (구형 GPU 미지원)
❌ 설정 복잡
❌ trtllm_mha는 Speculative Decoding 제한 있음

언제 써야 하나:

✅ Blackwell GPU (B100, H200, GB10)
✅ DeepSeek V3/R1 (trtllm_mla 사용)
✅ FP4 양자화와 함께 쓸 때

# DeepSeek + Blackwell 최적 조합
python -m sglang.launch_server \
  --model-path nvidia/DeepSeek-R1-FP4 \
  --tp 8 \
  --attention-backend trtllm_mla \
  --prefill-attention-backend fa4 \
  --quantization modelopt_fp4

5. FA4 백엔드 (최신)

뭔가: Blackwell GPU용 FlashAttention 4예요. Prefill에서 주로 사용해요.

# Prefill에만 FA4, Decode에는 다른 백엔드
python -m sglang.launch_server \
  --model-path nvidia/DeepSeek-R1-FP4 \
  --prefill-attention-backend fa4 \
  --attention-backend trtllm_mla

현재는 Prefill 전용으로 Decode와 혼합해서 써요.


Hybrid Attention — Prefill과 Decode 분리

SGLang은 Prefill과 Decode에 다른 백엔드를 쓸 수 있어요.

# Prefill: FA4 (빠른 입력 처리)
# Decode: TRTLLM MLA (빠른 토큰 생성)
python -m sglang.launch_server \
  --model-path nvidia/DeepSeek-R1-FP4 \
  --prefill-attention-backend fa4 \
  --attention-backend trtllm_mla

전체 비교 정리

백엔드 GPU 지원 처리량 레이턴시 특화

Triton 거의 모든 NVIDIA 중간 중간 범용, 커스텀
FlashInfer A100+ 높음 낮음 다양한 시퀀스 길이
FA3 H100 매우 높음 낮음 긴 컨텍스트, 대배치
TRTLLM MHA Blackwell 최고 최저 일반 모델
TRTLLM MLA Blackwell 최고 최저 DeepSeek
FA4 Blackwell 최고 - Prefill 전용

GPU별 추천 백엔드

V100, T4, RTX 30xx:
→ --attention-backend triton

A10G, A30:
→ --attention-backend flashinfer

A100:
→ --attention-backend flashinfer
   (또는 fa3, 큰 차이 없음)

H100:
→ --attention-backend fa3 (기본값)
   대화형: flashinfer가 더 나을 수도 있음

H200, B100, Blackwell:
→ --attention-backend trtllm_mha
   DeepSeek: --attention-backend trtllm_mla

실전 설정 예시

# 일반 서빙 (A100, H100)
python -m sglang.launch_server \
  --model-path Qwen/Qwen3.5-9B-Instruct \
  --attention-backend flashinfer \
  --port 30000

# 긴 컨텍스트 서빙 (H100)
python -m sglang.launch_server \
  --model-path meta-llama/Llama-3.3-70B-Instruct \
  --attention-backend fa3 \
  --context-length 131072 \
  --port 30000

# DeepSeek 서빙 (H100)
python -m sglang.launch_server \
  --model-path deepseek-ai/DeepSeek-V3 \
  --attention-backend trtllm_mla \
  --enable-mla \
  --tp 8 \
  --port 30000

# 구형 GPU 안정 서빙
python -m sglang.launch_server \
  --model-path Qwen/Qwen3.5-9B-Instruct \
  --attention-backend triton \
  --port 30000

# 벤치마크로 직접 비교
python -m sglang.bench_latency \
  --model meta-llama/Meta-Llama-3-8B \
  --batch-size 32 \
  --input 512 \
  --output 128 \
  --attention-backend flashinfer

python -m sglang.bench_latency \
  --model meta-llama/Meta-Llama-3-8B \
  --batch-size 32 \
  --input 512 \
  --output 128 \
  --attention-backend fa3

📌 관련 글

SGLang PD 분리 배포

 

SGLang PD 분리 배포 완전 가이드 — Prefill/Decode 분리로 처리량 5배 올리기

LLM 추론에는 두 단계가 있어요.Prefill (프리필):- 입력 프롬프트 전체를 처리- 연산 집약적 (Compute-bound)- KV 캐시 생성- 보통 수백~수천 토큰을 한 번에 처리Decode (디코드):- 토큰을 하나씩 생성- 메모

cell-devlog.tistory.com

SGLang 서빙 완전 가이드

 

SGLang 서빙에 대한 모든 것 — 설치부터 프로덕션까지 완전 가이드

2026년 현재 오픈소스 LLM 추론 엔진 중 실질적인 업계 표준은 SGLang이에요.xAI(Grok), NVIDIA, AMD, LinkedIn, Cursor, Oracle Cloud, Google Cloud, AWS가 프로덕션에 사용 중이고, 전 세계 40만 개 이상의 GPU에서 매일

cell-devlog.tistory.com

 

반응형