IP Library Granted Patent US 12,664,410
Granted Patent B2
US 12,664,410 · App. 17/513,838 · Granted Jun 23, 2026

Methods and devices for accelerating a transformer with a sparse attention pattern

Inventors: Zhendong Wang (Plano, TX); Yongxiong Ren (San Jose, CA); Yang Liu (San Jose, CA); Lingzhi Liu (San Jose, CA)
Assignee: BEIJING TRANSTREAMS TECHNOLOGY CO. LTD. search
G06N3/063G06F17/16G06N3/0495
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,664,410
App. No.
17/513,838
Filed
Oct 28, 2021
Granted
Jun 23, 2026
Kind
B2
Art Unit
2122
USPC
706/41
Abstract

A method and an apparatus for accelerating a transformer with a sparse attention pattern are provided. The method includes that a heterogeneous device including one or more GPUs loads a first matrix, a second matrix, and a transformed sparsity mask into a first sampled dense-dense matrix multiplication (SDDMM) kernel in a sparse attention module in the transformer and generates a first output based on the first matrix, the second matrix, and the transformed sparsity mask by the first SDDMM kernel, generates a second output by a softmax kernel in the sparse attention module based on the first output, loads the second output, a third matrix, and the transformed sparsity mask into a matrix multiplication kernel in the sparse attention module, and generates an output of the sparse attention module.

Claims (40)

1 . A method for accelerating a transformer with a sparse attention pattern in heterogeneous devices, comprising:

loading, by a heterogeneous device comprising one or more graphic processing units, a first matrix, a second matrix, and a transformed sparsity mask into a first sampled dense-dense matrix multiplication (SDDMM) kernel in a sparse attention module in the transformer and generating a first output based on the first matrix, the second matrix, and the transformed sparsity mask by the first SDDMM kernel;

generating, by the heterogeneous device, a second output by a softmax kernel in the sparse attention module based on the first output; and

loading, by the heterogeneous device, the second output, a third matrix, and the transformed sparsity mask into a matrix multiplication kernel in the sparse attention module and generating an output of the sparse attention module, wherein the matrix multiplication kernel is a second SDDMM kernel.

2 . The method of claim 1 , wherein the transformed sparsity mask and the first output are stored in a compressed format.

3 . The method of claim 2 , further comprising:

transforming, by the heterogeneous device, a sparsity mask in a regular dense matrix format to the transformed sparsity mask in the compressed format, wherein the sparsity mask indicates the sparsity attention pattern.

4 . The method of claim 1 , wherein the first matrix, the second matrix, and the third matrix are in a regular dense matrix format.

5 . The method of claim 2 , wherein loading the second output, the third matrix, and the transformed sparsity mask into the matrix multiplication kernel in the sparse attention module comprises:

loading the second output, the third matrix, and the transformed sparsity mask into the second SDDMM kernel in the sparse attention module to generate the output of the sparse attention module.

6 . The method of claim 1 , further comprising:

scaling and applying, by the softmax kernel, a softmax function over the first output to generate the second output, wherein the first output is a sparse matrix.

7 . An apparatus for accelerating a transformer with a sparse attention pattern in heterogeneous devices, comprising:

one or more processors; and

a memory configured to store instructions executable by the one or more processors,

wherein the one or more processors, upon execution of the instructions, are configured to:

load a first matrix, a second matrix, and a transformed sparsity mask into a first sampled dense-dense matrix multiplication (SDDMM) kernel in a sparse attention module in the transformer and generate a first output based on the first matrix, the second matrix, and the transformed sparsity mask by the first SDDMM kernel;

generate a second output by a softmax kernel in the sparse attention module based on the first output; and

load the second output, a third matrix, and the transformed sparsity mask into a matrix multiplication kernel in the sparse attention module and generate an output of the sparse attention module, wherein the matrix multiplication kernel is a second SDDMM kernel.

8 . The apparatus of claim 7 , wherein the transformed sparsity mask and the first output are stored in a compressed format.

9 . The apparatus of claim 8 , wherein the one or more processors are further configured to:

transform a sparsity mask in a regular dense matrix format to the transformed sparsity mask in the compressed format, wherein the sparsity mask indicates the sparsity attention pattern.

10 . The apparatus of claim 7 , wherein the one or more processors are further configured to:

wherein the first matrix, the second matrix, and the third matrix are in a regular dense matrix format.

11 . The apparatus of claim 8 , wherein the one or more processors are further configured to:

load the second output, the third matrix, and the transformed sparsity mask into the second SDDMM kernel in the sparse attention module to generate the output of the sparse attention module.

12 . The apparatus of claim 7 , wherein the one or more processors are further configured to:

scale and apply, by the softmax kernel, a softmax function over the first output to generate the second output, wherein the first output is a sparse matrix.

13 . A non-transitory computer readable storage medium, comprising instructions stored therein, wherein, upon execution of the instructions by one or more processors, the instructions cause the one or more processors to perform acts comprising:

loading a first matrix, a second matrix, and a transformed sparsity mask into a first sampled dense-dense matrix multiplication (SDDMM) kernel in a sparse attention module in a transformer in heterogeneous devices and generating a first output based on the first matrix, the second matrix, and the transformed sparsity mask by the SDDMM kernel;

generating a second output by a softmax kernel in the sparse attention module based on the first output; and

loading the second output, a third matrix, and the transformed sparsity mask into a matrix multiplication kernel in the sparse attention module and generating an output of the sparse attention module, wherein the matrix multiplication kernel is a second SDDMM kernel.

14 . The non-transitory computer readable storage medium of claim 13 , wherein the transformed sparsity mask and the first output are stored in a compressed format.

15 . The non-transitory computer readable storage medium of claim 14 , wherein the one or more processors are caused to perform acts further comprising:

transforming, by the heterogeneous device, a sparsity mask in a regular dense matrix format to the transformed sparsity mask in the compressed format, wherein the sparsity mask indicates the sparsity attention pattern.

16 . The non-transitory computer readable storage medium of claim 13 , wherein the first matrix, the second matrix, and the third matrix are in a regular dense matrix format.

17 . The non-transitory computer readable storage medium of claim 14 , wherein the one or more processors are caused to perform acts further comprising:

loading the second output, the third matrix, and the transformed sparsity mask into the second SDDMM kernel in the sparse attention module to generate the output of the sparse attention module.

18 . The non-transitory computer readable storage medium of claim 13 , wherein the one or more processors are caused to perform acts further comprising:

scaling and applying, by the softmax kernel, a softmax function over the first output to generate the second output, wherein the first output is a sparse matrix.

Assignments (4)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Mar 28, 2024
From: BEIJING DAJIA INTERNET INFORMATION TECHNOLOGY CO. LTD.,
To: BEIJING TRANSTREAMS TECHNOLOGY CO. LTD.
Reel/Frame 066941/0319 →
CORRECTIVE ASSIGNMENT TO CORRECT THE APPLICATION 11830480 TO PATENT NUMBER PREVIOUSLY RECORDED AT REEL: 66622 FRAME: 672. ASSIGNOR(S) HEREBY CONFIRMS THE ASSIGNMENT . Recorded Mar 12, 2024
From: KWAI INC.
To: BEIJING DAJIA INTERNET INFORMATION TECHNOLOGY CO., LTD.
Reel/Frame 066795/0775 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Mar 1, 2024
From: KWAI INC.
To: BEIJING DAJIA INTERNET INFORMATION TECHNOLOGY CO., LTD.
Reel/Frame 066622/0672 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Nov 1, 2021
From: WANG, ZHENDONG; REN, YONGXIONG; LIU, YANG; LIU, LINGZHI
To: KWAI INC.
Reel/Frame 057977/0159 →
Continuity (1)
Related Publication 20230133305A1 · May 4, 2023
References Cited (16)
US 11562734B2 · Ren et al. · 2023 [cited by applicant]
US 11830480B2 · Ren et al. · 2023 [cited by applicant]
US 20190042542A1 · Narayanamoorthy · 2019 [cited by examiner]
US 20220310068A1 · Ren et al. · 2022 [cited by applicant]
US 20230041163A1 · Elsen · 2023 [cited by examiner]
CN 113901747A · 2022 [cited by examiner]
Takuma Yamaguchi and Federico Busato, “Accelerating Matrix Multiplication with Block Sparse Format and NVidia Tensor Cores”, Mar. 19, 2021, NVidia, web (Year: 2021). [cited by examiner]
NVidia Corp, “cuSPARSE Library” (v11.4), Jun. 2021, NVidia, web (Year: 2021). [cited by examiner]
Lu, Liqiang et al. “Sanger: A Co-Design Framework for Enabling Sparse Attention Using Reconfigurable Architecture.”, Oct. 24, 2021, ACM, pp. 977-991, (Year: 2021). [cited by examiner]
Ashish Vaswani, et al., “Attention Is All You Need”, arXiv:1706.03762, arXiv:1706.03762v7 [cs.CL] Aug. 2, 2023 (15p). [cited by applicant]
Iz Beltagy, et al., “Longformer: The Long-Document Transformer”, arXiv:2004.05150v2 [cs.CL] Dec. 2, 2020, (17p). [cited by applicant]
Qipeng Guo, et al., “Star-Transformer”, arXiv:1902.09113v3 [cs.CL] Apr. 24, 2022, (11p). [cited by applicant]
Krzysztof Choromanski, et al., “Rethinking Attention with Performers”, arXiv:2009.14794v4 [cs.LG] Nov. 19, 2022, (38p). [cited by applicant]
Han Shi et al., “SparseBERT: Rethinking the Importance Analysis in Self-attention”, arXiv:2102.12871v3 [cs.LG] Jul. 1, 2021, (15p). [cited by applicant]
NVidia cuSPARSE provides SDDMM ( ) and SpMM ( ) implementation API, DU-06709-001_v12.0, Dec. 2022, (310p). [cited by applicant]
Hong, Changwan, et al. “Adaptive sparse tiling for sparse matrix multiplication.” Proceedings of the 24th Symposium on Principles and Practice of Parallel Programming. 2019. (15p). [cited by applicant]