Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
xuwx1
LightX2V
Commits
503c3abc
Unverified
Commit
503c3abc
authored
Oct 30, 2025
by
gushiqiao
Committed by
GitHub
Oct 30, 2025
Browse files
[Feat] add sageattn3 (#416)
Co-authored-by:
gushiqiao
<
975033167@qq.ocm
>
parent
e106ff67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
lightx2v/common/ops/attn/__init__.py
lightx2v/common/ops/attn/__init__.py
+1
-1
lightx2v/common/ops/attn/sage_attn.py
lightx2v/common/ops/attn/sage_attn.py
+34
-1
No files found.
lightx2v/common/ops/attn/__init__.py
View file @
503c3abc
from
.flash_attn
import
FlashAttn2Weight
,
FlashAttn3Weight
from
.radial_attn
import
RadialAttnWeight
from
.ring_attn
import
RingAttnWeight
from
.sage_attn
import
SageAttn2Weight
from
.sage_attn
import
SageAttn2Weight
,
SageAttn3Weight
from
.spassage_attn
import
SageAttnWeight
from
.svg2_attn
import
Svg2AttnWeight
from
.svg_attn
import
SvgAttnWeight
...
...
lightx2v/common/ops/attn/sage_attn.py
View file @
503c3abc
...
...
@@ -5,7 +5,7 @@ from lightx2v.utils.registry_factory import ATTN_WEIGHT_REGISTER
from
.template
import
AttnWeightTemplate
if
torch
.
cuda
.
get_device_capability
(
0
)
==
(
8
,
9
):
if
torch
.
cuda
.
get_device_capability
(
0
)
in
[
(
8
,
9
)
,
(
12
,
0
)]
:
try
:
from
sageattention
import
sageattn_qk_int8_pv_fp16_triton
as
sageattn
except
ImportError
:
...
...
@@ -18,6 +18,12 @@ else:
logger
.
info
(
"sageattn not found, please install sageattention first"
)
sageattn
=
None
try
:
from
sageattn3
import
sageattn3_blackwell
except
ImportError
:
logger
.
info
(
"sageattn3 not found, please install sageattention first"
)
sageattn3_blackwell
=
None
@
ATTN_WEIGHT_REGISTER
(
"sage_attn2"
)
class
SageAttn2Weight
(
AttnWeightTemplate
):
...
...
@@ -48,3 +54,30 @@ class SageAttn2Weight(AttnWeightTemplate):
tensor_layout
=
"NHD"
,
).
view
(
bs
*
max_seqlen_q
,
-
1
)
return
x
@
ATTN_WEIGHT_REGISTER
(
"sage_attn3"
)
class
SageAttn3Weight
(
AttnWeightTemplate
):
def
__init__
(
self
):
self
.
config
=
{}
def
apply
(
self
,
q
,
k
,
v
,
cu_seqlens_q
=
None
,
cu_seqlens_kv
=
None
,
max_seqlen_q
=
None
,
max_seqlen_kv
=
None
,
model_cls
=
None
,
):
q
,
k
,
v
=
q
.
contiguous
(),
k
.
contiguous
(),
v
.
contiguous
()
if
len
(
q
.
shape
)
==
3
:
bs
=
1
q
,
k
,
v
=
q
.
unsqueeze
(
0
),
k
.
unsqueeze
(
0
),
v
.
unsqueeze
(
0
)
elif
len
(
q
.
shape
)
==
4
:
bs
=
q
.
shape
[
0
]
x
=
sageattn3_blackwell
(
q
.
transpose
(
1
,
2
),
k
.
transpose
(
1
,
2
),
v
.
transpose
(
1
,
2
)).
transpose
(
1
,
2
).
reshape
(
bs
*
max_seqlen_q
,
-
1
)
return
x
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment