프로필

설정

불러오는 중…

← 홈

도움말·문의

자주 묻는 질문

어떤 기능에 로그인이 필요한가요?

공개 논문의 해설과 논문 정보, 모델 구조, 관련 논문, 용어는 로그인 없이 볼 수 있습니다. 논문 올리기, 내 보관함, 읽기 기록, 논문 평가, 관심 분야 추천, 메일과 알림은 로그인해야 쓸 수 있습니다.

PDF 파일로도 올릴 수 있나요?

논문은 arXiv나 DOI 링크로 올리고, 해설은 모두에게 공개됩니다. 출처와 이용 조건이 확인되지 않아 해설을 공개할 수 없는 논문은 올릴 수 없습니다. PDF 파일 올리기와 나만 보기는 구독 회원만 쓸 수 있고, 파일로 올린 논문은 나만 보기로만 저장합니다. 제목으로 공식 정보를 찾는 검색은 버튼을 누를 때만 합니다.

그림과 AI 해설은 정확한가요?

그림은 논문 원본만 쓰고 이용 허락이 확인된 것만 보여 줍니다. 해설은 AI가 쓴 글이라 틀릴 수 있습니다. 중요한 주장과 수치, 그림의 맥락은 원문 근거로 확인해 주세요.

저작권 문제를 알리고 싶어요.

이용 조건과 원문 출처는 논문 정보 탭에 있습니다. 문제가 있으면 ‘문의하기’에서 ‘논문 내용·그림·저작권’을 골라 논문 링크와 문제가 되는 부분, 권리를 확인할 수 있는 근거를 보내 주세요. 접수만으로 권리가 확정되거나 바로 삭제되지는 않습니다. 검토 결과는 ‘내 문의’에서 볼 수 있습니다.

비밀번호를 잊었어요.

이메일로 가입했다면 로그인 창의 비밀번호 찾기에서 인증한 이메일로 다시 설정할 수 있습니다. Google, 네이버, 카카오로 가입했다면 그 서비스에서 비밀번호를 바꿔 주세요.

문의할 때 무엇을 적어야 하나요?

어느 화면에서 무엇을 하다 생긴 문제인지 논문 링크와 함께 적어 주세요. 비밀번호, API 키, 인증 코드, 전화번호 같은 개인정보는 적지 마세요. 문의와 답변은 Refivu에 저장되고 ‘내 문의’에서 볼 수 있습니다.

회원탈퇴는 어떻게 하나요?

설정의 내 계정에서 회원탈퇴를 누르세요. 지워지는 내용을 확인하고 본인 확인을 마치면 탈퇴됩니다. 다른 요청은 ‘문의하기’에서 ‘계정’을 골라 남겨 주세요.

논문 해설

SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization

SageAttention2: 철저한 이상치 평활화와 스레드별 INT4 양자화를 통한 효율적인 어텐션

  • 연구 문제 기존 SageAttention은 INT8과 FP16 누적을 사용해 attention을 가속하지만, INT4와 FP8로 옮기면 정확도가 크게 떨어집니다.
  • 연구 방법 Q, K는 평활화 후 per-thread 단위로 INT4 양자화하고, P̃와 V는 FP8로 양자화하며, FP22 누적기의 오차는 two-level accumulation으로 보정합니다.
  • 주요 결과 SageAttention2는 RTX4090에서 FlashAttention2 대비 약 3배 빠르고, CogVideoX와 Llama3.1 등에서 end-to-end 지표 손실을 작게 유지한다고 보고합니다.

INT8 attention 가속의 한계

Attention은 시퀀스 길이에 대해 O(N²) 비용이 들기 때문에 효율적인 구현이 중요합니다. 기존 SageAttention은 Q, K를 INT8 per-block으로 양자화하고 P̃, V는 FP16으로 유지하며, FP16 accumulator를 사용해 P̃V를 계산합니다. 이 방식은 FlashAttention2보다 약 2배 빠르고 end-to-end 지표 손실이 작다고 보고되지만, INT8 Matmul은 INT4의 절반 속도에 그치고 FP16 accumulator 가속은 RTX4090과 RTX3090에서만 나타난다는 두 가지 약점이 있습니다. SageAttention2는 이 두 약점을 줄이기 위해 Q, K를 INT4로, P̃와 V를 FP8로 양자화하는 방향을 택합니다.

다만 INT4의 좁은 수치 범위와 FP8 누적기의 정밀도 문제 때문에 단순 양자화는 정확도를 크게 떨어뜨립니다.

Table 1: Speedup compared to matrix multiplication in FP16 with
an FP32 accumulator

Table 1 . Speedup compared to matrix multiplication in FP16 with an FP32 accumulator.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 3쪽에서 그림 영역을 추출했습니다.

Q 평활화와 per-thread INT4 양자화

SageAttention2는 INT4 QK^T를 위해 두 가지 기법을 씁니다. 첫째, Q의 블록별 평균 q̄_i를 빼 γ(Q_i)=Q_i−q̄_i를 만들고, K도 평균을 뺀 γ(K_j)를 사용합니다. 이때 Q_i K_j^T는 γ(Q_i)γ(K_j)^T+ΔS_ij+b로 분해되며, ΔS_ij=q̄_i γ(K_j)^T는 별도 GEMV로 계산해 더하고 b는 softmax 이후 영향이 없으므로 계산하지 않습니다. 둘째, per-block 양자화 대신 mma.m16n8k64 명령의 레이아웃에 맞춰 각 thread가 하나의 scale만 쓰도록 Q와 K를 묶는 per-thread 양자화를 씁니다. 저자들은 이 방식이 per-token 양자화에 가까운 정확도를 내면서 dot product 오버헤드를 늘리지 않는다고 설명합니다.

Figure 2: Typical examples of tensors’ data distribution in attention

Figure 2 .Typical examples of tensors’ data distribution in attention.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 4쪽에서 그림 영역을 추출했습니다.
Figure 3: Workflow of SageAttention2. 1 Smooth Q, K, V.
2 A GEMV to obtain ∆S. 3 Per-thread quantize Q, Kand per-
channel quantize V . 4 Perform the SageAttent…

Figure 3 . Workflow of SageAttention2. 1 Smooth Q, K, V. 2 A GEMV to obtain ∆S. 3 Per-thread quantize Q, Kand per- channel quantize V . 4 Perform the SageAttention2 kernel. 5 Correct the output.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 4쪽에서 그림 영역을 추출했습니다.
Figure 4: An example of per-thread quantization. The left figure shows the correspondence between the quantization scales and the tokens
in each GPU warp. The…

Figure 4 . An example of per-thread quantization. The left figure shows the correspondence between the quantization scales and the tokens in each GPU warp. The right figure shows the correspondence between quantization tokens and GPU threads in a MMA.m16n8k64 instruction, showing that each GPU thread only corresponds to one quantization scale inδ Q andδ K in dequantization.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 5쪽에서 그림 영역을 추출했습니다.
Figure 20: An example of quantized value distribution ofQbefore and after smoothingQ

Figure 20 .An example of quantized value distribution ofQbefore and after smoothingQ.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 22쪽에서 그림 영역을 추출했습니다.
Table 18: Overhead of per-thread quantization, smoothing Q, and
two-level accumulation techniques measured on L20 GPU

Table 18 .Overhead of per-thread quantization, smoothing Q, and two-level accumulation techniques measured on L20 GPU.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 23쪽에서 그림 영역을 추출했습니다.

FP8 P̃V와 FP22 누적기 보정

P̃V 계산에서는 P̃를 정적 scale δ_P=1/448로 E4M3 형식에 맞추고 V는 채널별로 양자화합니다. 저자들은 mma(f32.f8.f8.f32) 누적기가 실제로는 1 sign, 8 exponent, 13 mantissa bit를 갖는 FP22라고 보고합니다. 이 때문에 FP8 행렬곱 결과를 FP32 buffer에 옮기는 two-level accumulation을 씁니다. 블록별 R_ij=P̃_ij V_j를 FP22 누적기로 계산하고, 그 결과를 FP32 O_ij에 더합니다. 원문은 bk=64처럼 작은 블록에서 22비트 정밀도가 충분하다고 설명합니다. V 평활화는 채널 평균을 빼 값을 0 근처로 옮기는 선택적 기법이며, 평균은 최종 출력에 다시 더합니다.

Table 10: An accuracy example on real tensors ofCogvideoXmodel with or without smoothingV

Table 10 .An accuracy example on real tensors ofCogvideoXmodel with or without smoothingV.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 15쪽에서 그림 영역을 추출했습니다.

커널 정확도와 양자화 granularity 비교

커널 정확도는 CogVideoX의 실제 Q, K, V 텐서에서 여러 층의 평균과 최악 값으로 측정합니다. Table 4에서 Smooth Q+K는 CosSim 99.46%, Relative L1 0.0648, RMSE 0.0334를 보고하며 Smooth Q 단독과 Smooth K 단독보다 높은 정확도를 보입니다. Table 6의 양자화 granularity 비교에서는 per-thread가 CosSim 99.45%, Relative L1 0.0622, RMSE 0.0313으로 per-token과 거의 같고 per-block과 per-tensor보다 낫습니다. Table 7에서는 E4M3이 CogVideoX 평균 CosSim 99.44%로 FP16의 99.45%에 가깝고 E5M2와 INT8보다 높게 나타납니다.

이 수치들은 같은 CogVideoX 텐서 조건에서 얻은 결과이며 다른 모델의 결과로 옮길 수 없습니다.

Table 4: Average accuracyacross all layers of CogvideoX using
different smoothing methods

Table 4 . Average accuracyacross all layers of CogvideoX using different smoothing methods.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 9쪽에서 그림 영역을 추출했습니다.
Table 6: Average accuracyacross all layers of CogvideoX using
different quantization granularities

Table 6 . Average accuracyacross all layers of CogvideoX using different quantization granularities.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 9쪽에서 그림 영역을 추출했습니다.
Table 15: Worst accuracyacross all layers ofCogvideoXusing different quantization granularities

Table 15 .Worst accuracyacross all layers ofCogvideoXusing different quantization granularities.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 21쪽에서 그림 영역을 추출했습니다.
Table 17: Worst accuracyacross all layers ofCogvideoXusing different smooth methods

Table 17 .Worst accuracyacross all layers ofCogvideoXusing different smooth methods.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 22쪽에서 그림 영역을 추출했습니다.

End-to-end 지표와 속도 결과

커널 속도는 RTX4090에서 head dim 128, causal False 설정으로 측정하며, 원문은 SageAttn2-4b와 SageAttn2-8b가 FlashAttention2보다 약 3배와 2.7배 빠르고 xformers보다 약 4.5배와 4배 빠르다고 보고합니다. Hopper GPU에서는 INT4 텐서 코어가 없으므로 Q, K를 INT8로 양자화하고 smoothing Q를 제외한 SageAttn2-8b를 사용합니다. Table 2에서 Llama3.1의 WikiText perplexity는 Full-Precision 6.013, SageAttn2-8b 6.019, SageAttn2-4b 6.256으로 4b 변형이 더 높습니다.

CogVideoX(1.5-5B)에서는 SageAttn2-8b의 CLIPSIM이 0.1775로 Full-Precision 0.1778과 가깝습니다. 생성 지연은 CogVideoX(1.5-5B)에서 1040초에서 SageAttn2-8b 577초로 줄어듭니다. 이 지연 값은 RTX4090에서 측정된 end-to-end 결과입니다.

Figure 1: The upper left figure shows the kernel speedup on RTX4090 GPU. The upper right figure shows the end-to-end inference
speedup of generating the first…

Figure 1 . The upper left figure shows the kernel speedup on RTX4090 GPU. The upper right figure shows the end-to-end inference speedup of generating the first token and performance metrics for the Needle-in-a-Haystack task (Kamradt, 2023) with a sequence length of 100K on Llama3.1 on L20 GPU. The figure below shows two videos generated by CogvideoX (1.5-5B) using FlashAttention2 and SageAttention2on RTX4090, showing thatSageAttention2accelerates generation by 1.8x with no video quality loss.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 2쪽에서 그림 영역을 추출했습니다.
Table 2: End-to-end metrics across text, image, and video generation models.✗indicates an inability to generate results for evaluation

Table 2 .End-to-end metrics across text, image, and video generation models.✗indicates an inability to generate results for evaluation.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 7쪽에서 그림 영역을 추출했습니다.
Table 8: End-to-end generation latency usingSageAttention2
(The latency of Llama3.1 is the time to first token generation
using different sequence lengths)

Table 8 . End-to-end generation latency usingSageAttention2 (The latency of Llama3.1 is the time to first token generation using different sequence lengths).

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 9쪽에서 그림 영역을 추출했습니다.
Table 9: Speedup of different attention methods on various GPUs

Table 9 .Speedup of different attention methods on various GPUs.

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 15쪽에서 그림 영역을 추출했습니다.

적용 범위와 남은 한계

SageAttn2-4b는 Llama3.1 WikiText perplexity에서 Full-Precision보다 높아 일부 지표에서 손실을 보입니다. 반면 SageAttn2-8b는 주요 end-to-end 지표에서 손실이 거의 없다고 보고됩니다. 8b 변형은 smoothing Q를 포함하지 않으므로 4b의 INT4 구성과 같은 설정이 아닙니다. 평가는 Llama, CogVideoX, HunyuanVideo, Mochi, Flux, Stable-Diffusion3.5 등 특정 모델과 데이터셋에서 수행되었으며, 이 결과를 다른 모델 계열이나 하드웨어로 그대로 넓힐 수 없습니다. 원문은 Hopper GPU에서의 FlashAttention3(fp8) 비교를 제시하지만, 이는 같은 비트 폭 비교 조건에서 얻은 결과입니다.

Table 14: Comparison with FlashAttention3(fp8) onLlama-3-262k(8B) on InfiniBench (Zhang et al., 2024) (H100 GPU)

Table 14 .Comparison with FlashAttention3(fp8) onLlama-3-262k(8B) on InfiniBench (Zhang et al., 2024) (H100 GPU).

원문 · CC BY 4.0 · Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen · SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization · 원문 그림 인용 · 원본 PDF 21쪽에서 그림 영역을 추출했습니다.

논문 정보

저자
Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen
학회·저널
arXiv · 프리프린트
최초 공개일
2024년 11월 17일
등록일
2026년 10월 29일
수정일
2025년 10월 1일
버전
v7
arXiv
2411.10958
분류
cs.LG · cs.AI · cs.CV · cs.NE · cs.PF
원문 이용 조건
CC BY 4.0
제공 범위
논문 정보, 해설, 허용된 원문 그림

AI 해설은 논문 원문과 별개의 설명이며 오류가 있을 수 있습니다. 원문과 그림은 각 출처의 이용 조건과 따로 표시된 권리를 따릅니다.

초록

Although quantization for linear layers has been widely used, its application to accelerate the attention process remains limited. To further enhance the efficiency of attention computation compared to SageAttention while maintaining precision, we propose SageAttention2, which utilizes significantly faster 4-bit matrix multiplication (Matmul) alongside additional precision-enhancing techniques. First, we propose to quantize matrices $(Q, K)$ to INT4 in a hardware-friendly thread-level granularity and quantize matrices $(\widetilde P, V)$ to FP8. Second, we propose a method to smooth $Q$, enhancing the accuracy of INT4 $QK^\top$. Third, we propose a two-level accumulation strategy for $\widetilde PV$ to enhance the accuracy of FP8 $\widetilde PV$. The operations per second (OPS) of SageAttention2 surpass FlashAttention2 and xformers by about 3x and 4.5x on RTX4090, respectively. Moreover, SageAttention2 matches the speed of FlashAttention3(fp8) on the Hopper GPUs, while delivering much higher accuracy. Comprehensive experiments confirm that our approach incurs negligible end-to-end metrics loss across diverse models, including those for language, image, and video generation. The code is available at https://github.com/thu-ml/SageAttention.

원문 인용

Jintao Zhang, Haofeng Huang, Pengle Zhang, Jia Wei, Jun Zhu, Jianfei Chen (2024). SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization. arXiv:2411.10958v7. https://arxiv.org/abs/2411.10958v7

BibTeX
@misc{zhang2024sageattention2,
  title = {{SageAttention2: Efficient Attention with Thorough Outlier Smoothing and Per-thread INT4 Quantization}},
  author = {Jintao Zhang and Haofeng Huang and Pengle Zhang and Jia Wei and Jun Zhu and Jianfei Chen},
  year = {2024},
  eprint = {2411.10958},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.10958v7}
}

관련 논문 보기다른 논문 둘러보기

논문 미리 보기
계정 보안

Google 계정 연결

Google 계정을 연결하면 그 계정으로도 로그인할 수 있습니다.

Refivu

회원탈퇴

Refivu
Refivu

회원가입