Instructions to use replicate/sage-attention with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Kernels
How to use replicate/sage-attention with Kernels:
# !pip install kernels from kernels import get_kernel # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones kernel = get_kernel("replicate/sage-attention", version=1) - Notebooks
- Google Colab
- Kaggle
Build uploaded using `kernels`.
Browse files- .gitattributes +1 -0
- build/torch210-cu128-x86_64-windows/_ops.py +3 -3
- build/torch210-cu128-x86_64-windows/{_sage_attention_cuda_554dbc8.pyd → _sage_attention_cuda_a8f8348.pyd} +1 -1
- build/torch210-cu128-x86_64-windows/core.py +27 -5
- build/torch210-cu128-x86_64-windows/sm80_compile.py +37 -132
- build/torch210-cu128-x86_64-windows/sm89_compile.py +34 -126
- build/torch210-cu128-x86_64-windows/sm90_compile.py +18 -76
.gitattributes
CHANGED
|
@@ -74,3 +74,4 @@ build/torch210-cxx11-cu130-x86_64-linux/_sage_attention_cuda_5568690.abi3.so fil
|
|
| 74 |
build/torch29-cxx11-cu126-x86_64-linux/_sage_attention_cuda_5568690.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 75 |
build/torch29-cxx11-cu128-x86_64-linux/_sage_attention_cuda_5568690.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 76 |
build/torch29-cxx11-cu130-x86_64-linux/_sage_attention_cuda_5568690.abi3.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 74 |
build/torch29-cxx11-cu126-x86_64-linux/_sage_attention_cuda_5568690.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 75 |
build/torch29-cxx11-cu128-x86_64-linux/_sage_attention_cuda_5568690.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 76 |
build/torch29-cxx11-cu130-x86_64-linux/_sage_attention_cuda_5568690.abi3.so filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
build/torch210-cu128-x86_64-windows/_sage_attention_cuda_a8f8348.pyd filter=lfs diff=lfs merge=lfs -text
|
build/torch210-cu128-x86_64-windows/_ops.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import torch
|
| 2 |
-
from . import
|
| 3 |
-
ops = torch.ops.
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
-
return f"
|
|
|
|
| 1 |
import torch
|
| 2 |
+
from . import _sage_attention_cuda_a8f8348
|
| 3 |
+
ops = torch.ops._sage_attention_cuda_a8f8348
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_sage_attention_cuda_a8f8348::{op_name}"
|
build/torch210-cu128-x86_64-windows/{_sage_attention_cuda_554dbc8.pyd → _sage_attention_cuda_a8f8348.pyd}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 24102400
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e342044fa0755f8e66d9f1f5d852da973ba6b8001ad737177515d27532e465a7
|
| 3 |
size 24102400
|
build/torch210-cu128-x86_64-windows/core.py
CHANGED
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
| 16 |
|
| 17 |
import torch
|
| 18 |
import torch.nn.functional as F
|
|
|
|
| 19 |
|
| 20 |
from ._ops import ops
|
| 21 |
|
|
@@ -33,8 +34,9 @@ try:
|
|
| 33 |
qk_int8_sv_f16_accum_f16_attn_inst_buf as sm80_qk_int8_sv_f16_accum_f16_attn_inst_buf,
|
| 34 |
)
|
| 35 |
SM80_ENABLED = True
|
| 36 |
-
except Exception:
|
| 37 |
SM80_ENABLED = False
|
|
|
|
| 38 |
|
| 39 |
try:
|
| 40 |
from .sm89_compile import (
|
|
@@ -44,20 +46,20 @@ try:
|
|
| 44 |
qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf as sm89_qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf,
|
| 45 |
)
|
| 46 |
SM89_ENABLED = True
|
| 47 |
-
except Exception:
|
| 48 |
SM89_ENABLED = False
|
|
|
|
| 49 |
|
| 50 |
try:
|
| 51 |
from .sm90_compile import (
|
| 52 |
qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90 as sm90_qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90,
|
| 53 |
)
|
| 54 |
SM90_ENABLED = True
|
| 55 |
-
except Exception:
|
| 56 |
SM90_ENABLED = False
|
|
|
|
| 57 |
|
| 58 |
from typing import Any, List, Literal, Optional, Tuple, Union
|
| 59 |
-
import warnings
|
| 60 |
-
|
| 61 |
|
| 62 |
import subprocess
|
| 63 |
import re
|
|
@@ -148,6 +150,11 @@ def sageattn(
|
|
| 148 |
"""
|
| 149 |
arch = get_cuda_arch_versions()[q.device.index]
|
| 150 |
if arch == "sm80":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
return sageattn_qk_int8_pv_fp16_cuda(
|
| 152 |
q,
|
| 153 |
k,
|
|
@@ -159,6 +166,11 @@ def sageattn(
|
|
| 159 |
pv_accum_dtype="fp32",
|
| 160 |
)
|
| 161 |
elif arch == "sm89":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
return sageattn_qk_int8_pv_fp8_cuda(
|
| 163 |
q,
|
| 164 |
k,
|
|
@@ -170,6 +182,11 @@ def sageattn(
|
|
| 170 |
pv_accum_dtype="fp32+fp16",
|
| 171 |
)
|
| 172 |
elif arch == "sm90":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
return sageattn_qk_int8_pv_fp8_cuda_sm90(
|
| 174 |
q,
|
| 175 |
k,
|
|
@@ -181,6 +198,11 @@ def sageattn(
|
|
| 181 |
pv_accum_dtype="fp32+fp32",
|
| 182 |
)
|
| 183 |
elif arch == "sm120":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
return sageattn_qk_int8_pv_fp8_cuda(
|
| 185 |
q,
|
| 186 |
k,
|
|
|
|
| 16 |
|
| 17 |
import torch
|
| 18 |
import torch.nn.functional as F
|
| 19 |
+
import warnings
|
| 20 |
|
| 21 |
from ._ops import ops
|
| 22 |
|
|
|
|
| 34 |
qk_int8_sv_f16_accum_f16_attn_inst_buf as sm80_qk_int8_sv_f16_accum_f16_attn_inst_buf,
|
| 35 |
)
|
| 36 |
SM80_ENABLED = True
|
| 37 |
+
except Exception as e:
|
| 38 |
SM80_ENABLED = False
|
| 39 |
+
warnings.warn(f"Failed to load SM80 SageAttention kernels: {e}")
|
| 40 |
|
| 41 |
try:
|
| 42 |
from .sm89_compile import (
|
|
|
|
| 46 |
qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf as sm89_qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf,
|
| 47 |
)
|
| 48 |
SM89_ENABLED = True
|
| 49 |
+
except Exception as e:
|
| 50 |
SM89_ENABLED = False
|
| 51 |
+
warnings.warn(f"Failed to load SM89 SageAttention kernels: {e}")
|
| 52 |
|
| 53 |
try:
|
| 54 |
from .sm90_compile import (
|
| 55 |
qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90 as sm90_qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90,
|
| 56 |
)
|
| 57 |
SM90_ENABLED = True
|
| 58 |
+
except Exception as e:
|
| 59 |
SM90_ENABLED = False
|
| 60 |
+
warnings.warn(f"Failed to load SM90 SageAttention kernels: {e}")
|
| 61 |
|
| 62 |
from typing import Any, List, Literal, Optional, Tuple, Union
|
|
|
|
|
|
|
| 63 |
|
| 64 |
import subprocess
|
| 65 |
import re
|
|
|
|
| 150 |
"""
|
| 151 |
arch = get_cuda_arch_versions()[q.device.index]
|
| 152 |
if arch == "sm80":
|
| 153 |
+
if not SM80_ENABLED:
|
| 154 |
+
raise RuntimeError(
|
| 155 |
+
"SM80 SageAttention kernels failed to load. "
|
| 156 |
+
"Ensure the kernel was compiled for SM80 (Ampere)."
|
| 157 |
+
)
|
| 158 |
return sageattn_qk_int8_pv_fp16_cuda(
|
| 159 |
q,
|
| 160 |
k,
|
|
|
|
| 166 |
pv_accum_dtype="fp32",
|
| 167 |
)
|
| 168 |
elif arch == "sm89":
|
| 169 |
+
if not SM89_ENABLED:
|
| 170 |
+
raise RuntimeError(
|
| 171 |
+
"SM89 SageAttention kernels failed to load. "
|
| 172 |
+
"Ensure the kernel was compiled for SM89 (Ada Lovelace)."
|
| 173 |
+
)
|
| 174 |
return sageattn_qk_int8_pv_fp8_cuda(
|
| 175 |
q,
|
| 176 |
k,
|
|
|
|
| 182 |
pv_accum_dtype="fp32+fp16",
|
| 183 |
)
|
| 184 |
elif arch == "sm90":
|
| 185 |
+
if not SM90_ENABLED:
|
| 186 |
+
raise RuntimeError(
|
| 187 |
+
"SM90 SageAttention kernels failed to load. "
|
| 188 |
+
"Ensure the kernel was compiled for SM90 (Hopper)."
|
| 189 |
+
)
|
| 190 |
return sageattn_qk_int8_pv_fp8_cuda_sm90(
|
| 191 |
q,
|
| 192 |
k,
|
|
|
|
| 198 |
pv_accum_dtype="fp32+fp32",
|
| 199 |
)
|
| 200 |
elif arch == "sm120":
|
| 201 |
+
if not SM89_ENABLED:
|
| 202 |
+
raise RuntimeError(
|
| 203 |
+
"SM89 SageAttention kernels failed to load. "
|
| 204 |
+
"SM120 (Blackwell) uses SM89 kernels; ensure they were compiled."
|
| 205 |
+
)
|
| 206 |
return sageattn_qk_int8_pv_fp8_cuda(
|
| 207 |
q,
|
| 208 |
k,
|
build/torch210-cu128-x86_64-windows/sm80_compile.py
CHANGED
|
@@ -2,148 +2,53 @@ from ._ops import ops
|
|
| 2 |
import torch
|
| 3 |
from ._ops import add_op_namespace_prefix
|
| 4 |
|
| 5 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_attn"), mutates_args=("output",), device_types="cuda")
|
| 6 |
-
def qk_int8_sv_f16_accum_f16_attn(
|
| 7 |
-
query: torch.Tensor,
|
| 8 |
-
key: torch.Tensor,
|
| 9 |
-
value: torch.Tensor,
|
| 10 |
-
output: torch.Tensor,
|
| 11 |
-
query_scale: torch.Tensor,
|
| 12 |
-
key_scale: torch.Tensor,
|
| 13 |
-
tensor_layout: int,
|
| 14 |
-
is_causal: int,
|
| 15 |
-
qk_quant_gran: int,
|
| 16 |
-
sm_scale: float,
|
| 17 |
-
return_lse: int,
|
| 18 |
-
) -> torch.Tensor:
|
| 19 |
-
"""
|
| 20 |
-
Custom CUDA kernel for SageAttention with INT8 quantization for Q and K, FP16 PV with FP16 accumulation.
|
| 21 |
-
"""
|
| 22 |
-
return ops.qk_int8_sv_f16_accum_f16_attn(
|
| 23 |
-
query, key, value, output, query_scale, key_scale, tensor_layout,
|
| 24 |
-
is_causal, qk_quant_gran, sm_scale, return_lse
|
| 25 |
-
)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f16_accum_f32_attn"), mutates_args=("output",), device_types="cuda")
|
| 29 |
-
def qk_int8_sv_f16_accum_f32_attn(
|
| 30 |
-
query: torch.Tensor,
|
| 31 |
-
key: torch.Tensor,
|
| 32 |
-
value: torch.Tensor,
|
| 33 |
-
output: torch.Tensor,
|
| 34 |
-
query_scale: torch.Tensor,
|
| 35 |
-
key_scale: torch.Tensor,
|
| 36 |
-
tensor_layout: int,
|
| 37 |
-
is_causal: int,
|
| 38 |
-
qk_quant_gran: int,
|
| 39 |
-
sm_scale: float,
|
| 40 |
-
return_lse: int,
|
| 41 |
-
) -> torch.Tensor:
|
| 42 |
-
"""
|
| 43 |
-
Custom CUDA kernel for SageAttention with INT8 quantization for Q and K, FP16 PV with FP32 accumulation.
|
| 44 |
-
"""
|
| 45 |
-
return ops.qk_int8_sv_f16_accum_f32_attn(
|
| 46 |
-
query, key, value, output, query_scale, key_scale, tensor_layout,
|
| 47 |
-
is_causal, qk_quant_gran, sm_scale, return_lse
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_attn_inst_buf"), mutates_args=("output",), device_types="cuda")
|
| 52 |
-
def qk_int8_sv_f16_accum_f16_attn_inst_buf(
|
| 53 |
-
query: torch.Tensor,
|
| 54 |
-
key: torch.Tensor,
|
| 55 |
-
value: torch.Tensor,
|
| 56 |
-
output: torch.Tensor,
|
| 57 |
-
query_scale: torch.Tensor,
|
| 58 |
-
key_scale: torch.Tensor,
|
| 59 |
-
tensor_layout: int,
|
| 60 |
-
is_causal: int,
|
| 61 |
-
qk_quant_gran: int,
|
| 62 |
-
sm_scale: float,
|
| 63 |
-
return_lse: int,
|
| 64 |
-
) -> torch.Tensor:
|
| 65 |
-
"""
|
| 66 |
-
Custom CUDA kernel for SageAttention with INT8 quantization for Q and K, FP16 PV with FP16 accumulation.
|
| 67 |
-
"""
|
| 68 |
-
return ops.qk_int8_sv_f16_accum_f16_attn_inst_buf(
|
| 69 |
-
query, key, value, output, query_scale, key_scale, tensor_layout,
|
| 70 |
-
is_causal, qk_quant_gran, sm_scale, return_lse
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_fuse_v_mean_attn"), mutates_args=("output",), device_types="cuda")
|
| 75 |
-
def qk_int8_sv_f16_accum_f16_fuse_v_mean_attn(
|
| 76 |
-
query: torch.Tensor,
|
| 77 |
-
key: torch.Tensor,
|
| 78 |
-
value: torch.Tensor,
|
| 79 |
-
output: torch.Tensor,
|
| 80 |
-
query_scale: torch.Tensor,
|
| 81 |
-
key_scale: torch.Tensor,
|
| 82 |
-
value_mean: torch.Tensor,
|
| 83 |
-
tensor_layout: int,
|
| 84 |
-
is_causal: int,
|
| 85 |
-
qk_quant_gran: int,
|
| 86 |
-
sm_scale: float,
|
| 87 |
-
return_lse: int,
|
| 88 |
-
) -> torch.Tensor:
|
| 89 |
-
"""
|
| 90 |
-
Custom CUDA kernel for SageAttention with INT8 quantization for Q and K, FP16 PV with FP16 accumulation.
|
| 91 |
-
"""
|
| 92 |
-
return ops.qk_int8_sv_f16_accum_f16_fuse_v_mean_attn(
|
| 93 |
-
query, key, value, output, query_scale, key_scale, value_mean,
|
| 94 |
-
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse
|
| 95 |
-
)
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
def sm80_qk_fake_impl(
|
| 99 |
-
query: torch.Tensor,
|
| 100 |
-
key: torch.Tensor,
|
| 101 |
-
value: torch.Tensor,
|
| 102 |
-
output: torch.Tensor,
|
| 103 |
-
query_scale: torch.Tensor,
|
| 104 |
-
key_scale: torch.Tensor,
|
| 105 |
-
tensor_layout: int,
|
| 106 |
-
is_causal: int,
|
| 107 |
-
qk_quant_gran: int,
|
| 108 |
-
sm_scale: float,
|
| 109 |
-
return_lse: int,
|
| 110 |
-
) -> torch.Tensor:
|
| 111 |
batch_size = query.size(0)
|
| 112 |
-
|
| 113 |
if tensor_layout == 0:
|
| 114 |
num_qo_heads = query.size(2)
|
| 115 |
qo_len = query.size(1)
|
| 116 |
else:
|
| 117 |
num_qo_heads = query.size(1)
|
| 118 |
qo_len = query.size(2)
|
| 119 |
-
|
| 120 |
if return_lse:
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
-
torch.library.register_fake(add_op_namespace_prefix("
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_fuse_v_mean_attn"))
|
| 132 |
-
def
|
| 133 |
-
query
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
sm_scale: float,
|
| 144 |
-
return_lse: int,
|
| 145 |
-
) -> torch.Tensor:
|
| 146 |
-
return sm80_qk_fake_impl(
|
| 147 |
-
query, key, value, output, query_scale, key_scale, tensor_layout,
|
| 148 |
-
is_causal, qk_quant_gran, sm_scale, return_lse
|
| 149 |
-
)
|
|
|
|
| 2 |
import torch
|
| 3 |
from ._ops import add_op_namespace_prefix
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def _lse_fake_impl(query, tensor_layout, return_lse):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
batch_size = query.size(0)
|
|
|
|
| 8 |
if tensor_layout == 0:
|
| 9 |
num_qo_heads = query.size(2)
|
| 10 |
qo_len = query.size(1)
|
| 11 |
else:
|
| 12 |
num_qo_heads = query.size(1)
|
| 13 |
qo_len = query.size(2)
|
|
|
|
| 14 |
if return_lse:
|
| 15 |
+
return torch.empty((batch_size, num_qo_heads, qo_len), dtype=torch.float32, device=query.device)
|
| 16 |
+
return torch.empty((0))
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_attn"))
|
| 20 |
+
def qk_int8_sv_f16_accum_f16_attn_fake(
|
| 21 |
+
query, key, value, output, query_scale, key_scale,
|
| 22 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 23 |
+
):
|
| 24 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 25 |
+
|
| 26 |
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f16_accum_f32_attn"))
|
| 28 |
+
def qk_int8_sv_f16_accum_f32_attn_fake(
|
| 29 |
+
query, key, value, output, query_scale, key_scale,
|
| 30 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 31 |
+
):
|
| 32 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_attn_inst_buf"))
|
| 36 |
+
def qk_int8_sv_f16_accum_f16_attn_inst_buf_fake(
|
| 37 |
+
query, key, value, output, query_scale, key_scale,
|
| 38 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 39 |
+
):
|
| 40 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 41 |
|
| 42 |
|
| 43 |
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f16_accum_f16_fuse_v_mean_attn"))
|
| 44 |
+
def qk_int8_sv_f16_accum_f16_fuse_v_mean_attn_fake(
|
| 45 |
+
query, key, value, output, query_scale, key_scale, value_mean,
|
| 46 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 47 |
+
):
|
| 48 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
qk_int8_sv_f16_accum_f16_attn = ops.qk_int8_sv_f16_accum_f16_attn
|
| 52 |
+
qk_int8_sv_f16_accum_f32_attn = ops.qk_int8_sv_f16_accum_f32_attn
|
| 53 |
+
qk_int8_sv_f16_accum_f16_attn_inst_buf = ops.qk_int8_sv_f16_accum_f16_attn_inst_buf
|
| 54 |
+
qk_int8_sv_f16_accum_f16_fuse_v_mean_attn = ops.qk_int8_sv_f16_accum_f16_fuse_v_mean_attn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cu128-x86_64-windows/sm89_compile.py
CHANGED
|
@@ -2,145 +2,53 @@ from ._ops import ops
|
|
| 2 |
import torch
|
| 3 |
from ._ops import add_op_namespace_prefix
|
| 4 |
|
| 5 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn"), mutates_args=("output",), device_types="cuda")
|
| 6 |
-
def qk_int8_sv_f8_accum_f32_fuse_v_scale_attn(
|
| 7 |
-
query: torch.Tensor,
|
| 8 |
-
key: torch.Tensor,
|
| 9 |
-
value: torch.Tensor,
|
| 10 |
-
output: torch.Tensor,
|
| 11 |
-
query_scale: torch.Tensor,
|
| 12 |
-
key_scale: torch.Tensor,
|
| 13 |
-
value_scale: torch.Tensor,
|
| 14 |
-
tensor_layout: int,
|
| 15 |
-
is_causal: int,
|
| 16 |
-
qk_quant_gran: int,
|
| 17 |
-
sm_scale: float,
|
| 18 |
-
return_lse: int,
|
| 19 |
-
) -> torch.Tensor:
|
| 20 |
-
return ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn(
|
| 21 |
-
query, key, value, output, query_scale, key_scale, value_scale,
|
| 22 |
-
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse
|
| 23 |
-
)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf"), mutates_args=("output",), device_types="cuda")
|
| 28 |
-
def qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf(
|
| 29 |
-
query: torch.Tensor,
|
| 30 |
-
key: torch.Tensor,
|
| 31 |
-
value: torch.Tensor,
|
| 32 |
-
output: torch.Tensor,
|
| 33 |
-
query_scale: torch.Tensor,
|
| 34 |
-
key_scale: torch.Tensor,
|
| 35 |
-
value_scale: torch.Tensor,
|
| 36 |
-
tensor_layout: int,
|
| 37 |
-
is_causal: int,
|
| 38 |
-
qk_quant_gran: int,
|
| 39 |
-
sm_scale: float,
|
| 40 |
-
return_lse: int,
|
| 41 |
-
) -> torch.Tensor:
|
| 42 |
-
return ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf(
|
| 43 |
-
query, key, value, output, query_scale, key_scale, value_scale,
|
| 44 |
-
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf"), mutates_args=("output",), device_types="cuda")
|
| 49 |
-
def qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf(
|
| 50 |
-
query: torch.Tensor,
|
| 51 |
-
key: torch.Tensor,
|
| 52 |
-
value: torch.Tensor,
|
| 53 |
-
output: torch.Tensor,
|
| 54 |
-
query_scale: torch.Tensor,
|
| 55 |
-
key_scale: torch.Tensor,
|
| 56 |
-
value_scale: torch.Tensor,
|
| 57 |
-
tensor_layout: int,
|
| 58 |
-
is_causal: int,
|
| 59 |
-
qk_quant_gran: int,
|
| 60 |
-
sm_scale: float,
|
| 61 |
-
return_lse: int,
|
| 62 |
-
) -> torch.Tensor:
|
| 63 |
-
return ops.qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf(
|
| 64 |
-
query, key, value, output, query_scale, key_scale, value_scale,
|
| 65 |
-
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse
|
| 66 |
-
)
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
def sm89_qk_with_key_value(
|
| 70 |
-
query: torch.Tensor,
|
| 71 |
-
key: torch.Tensor,
|
| 72 |
-
value: torch.Tensor,
|
| 73 |
-
output: torch.Tensor,
|
| 74 |
-
query_scale: torch.Tensor,
|
| 75 |
-
key_scale: torch.Tensor,
|
| 76 |
-
value_scale: torch.Tensor,
|
| 77 |
-
tensor_layout: int,
|
| 78 |
-
is_causal: int,
|
| 79 |
-
qk_quant_gran: int,
|
| 80 |
-
sm_scale: float,
|
| 81 |
-
return_lse: int,
|
| 82 |
-
) -> torch.Tensor:
|
| 83 |
batch_size = query.size(0)
|
| 84 |
-
|
| 85 |
if tensor_layout == 0:
|
| 86 |
num_qo_heads = query.size(2)
|
| 87 |
qo_len = query.size(1)
|
| 88 |
else:
|
| 89 |
num_qo_heads = query.size(1)
|
| 90 |
qo_len = query.size(2)
|
| 91 |
-
|
| 92 |
if return_lse:
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
return lse
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
-
torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf"))(sm89_qk_with_key_value)
|
| 100 |
-
torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf"))(sm89_qk_with_key_value)
|
| 101 |
-
torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn"))(sm89_qk_with_key_value)
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
key
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
key_scale: torch.Tensor,
|
| 112 |
-
value_scale: torch.Tensor,
|
| 113 |
-
value_mean: torch.Tensor,
|
| 114 |
-
tensor_layout: int,
|
| 115 |
-
is_causal: int,
|
| 116 |
-
qk_quant_gran: int,
|
| 117 |
-
sm_scale: float,
|
| 118 |
-
return_lse: int,
|
| 119 |
-
) -> torch.Tensor:
|
| 120 |
-
return ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_fuse_v_mean_attn(
|
| 121 |
-
query, key, value, output, query_scale, key_scale, value_scale,
|
| 122 |
-
value_mean, tensor_layout, is_causal, qk_quant_gran, sm_scale,
|
| 123 |
-
return_lse
|
| 124 |
-
)
|
| 125 |
|
| 126 |
|
| 127 |
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_fuse_v_mean_attn"))
|
| 128 |
-
def
|
| 129 |
-
query
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
qk_quant_gran: int,
|
| 140 |
-
sm_scale: float,
|
| 141 |
-
return_lse: int,
|
| 142 |
-
) -> torch.Tensor:
|
| 143 |
-
return sm89_qk_with_key_value(
|
| 144 |
-
query, key, value, output, query_scale, key_scale, value_scale,
|
| 145 |
-
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse
|
| 146 |
-
)
|
|
|
|
| 2 |
import torch
|
| 3 |
from ._ops import add_op_namespace_prefix
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def _lse_fake_impl(query, tensor_layout, return_lse):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
batch_size = query.size(0)
|
|
|
|
| 8 |
if tensor_layout == 0:
|
| 9 |
num_qo_heads = query.size(2)
|
| 10 |
qo_len = query.size(1)
|
| 11 |
else:
|
| 12 |
num_qo_heads = query.size(1)
|
| 13 |
qo_len = query.size(2)
|
|
|
|
| 14 |
if return_lse:
|
| 15 |
+
return torch.empty((batch_size, num_qo_heads, qo_len), dtype=torch.float32, device=query.device)
|
| 16 |
+
return torch.empty((0))
|
| 17 |
+
|
|
|
|
| 18 |
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn"))
|
| 20 |
+
def qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_fake(
|
| 21 |
+
query, key, value, output, query_scale, key_scale, value_scale,
|
| 22 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 23 |
+
):
|
| 24 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf"))
|
| 28 |
+
def qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_fake(
|
| 29 |
+
query, key, value, output, query_scale, key_scale, value_scale,
|
| 30 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 31 |
+
):
|
| 32 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 33 |
|
| 34 |
+
|
| 35 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf"))
|
| 36 |
+
def qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf_fake(
|
| 37 |
+
query, key, value, output, query_scale, key_scale, value_scale,
|
| 38 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 39 |
+
):
|
| 40 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_fuse_v_mean_attn"))
|
| 44 |
+
def qk_int8_sv_f8_accum_f32_fuse_v_scale_fuse_v_mean_attn_fake(
|
| 45 |
+
query, key, value, output, query_scale, key_scale, value_scale, value_mean,
|
| 46 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 47 |
+
):
|
| 48 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
qk_int8_sv_f8_accum_f32_fuse_v_scale_attn = ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn
|
| 52 |
+
qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf = ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf
|
| 53 |
+
qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf = ops.qk_int8_sv_f8_accum_f16_fuse_v_scale_attn_inst_buf
|
| 54 |
+
qk_int8_sv_f8_accum_f32_fuse_v_scale_fuse_v_mean_attn = ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_fuse_v_mean_attn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build/torch210-cu128-x86_64-windows/sm90_compile.py
CHANGED
|
@@ -2,93 +2,35 @@ from ._ops import ops
|
|
| 2 |
import torch
|
| 3 |
from ._ops import add_op_namespace_prefix
|
| 4 |
|
| 5 |
-
@torch.library.custom_op(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_attn_inst_buf"), mutates_args=("output",), device_types="cuda")
|
| 6 |
-
def qk_int8_sv_f8_accum_f32_attn_inst_buf(
|
| 7 |
-
query: torch.Tensor,
|
| 8 |
-
key: torch.Tensor,
|
| 9 |
-
value: torch.Tensor,
|
| 10 |
-
output: torch.Tensor,
|
| 11 |
-
query_scale: torch.Tensor,
|
| 12 |
-
key_scale: torch.Tensor,
|
| 13 |
-
tensor_layout: int,
|
| 14 |
-
is_causal: int,
|
| 15 |
-
qk_quant_gran: int,
|
| 16 |
-
sm_scale: float,
|
| 17 |
-
return_lse: int,
|
| 18 |
-
) -> torch.Tensor:
|
| 19 |
-
return ops.qk_int8_sv_f8_accum_f32_attn_inst_buf(
|
| 20 |
-
query, key, value, output, query_scale, key_scale, tensor_layout,
|
| 21 |
-
is_causal, qk_quant_gran, sm_scale, return_lse
|
| 22 |
-
)
|
| 23 |
|
| 24 |
-
|
| 25 |
-
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_attn_inst_buf"))
|
| 26 |
-
def qk_int8_sv_f8_accum_f32_attn_inst_buf_fake_impl(
|
| 27 |
-
query: torch.Tensor,
|
| 28 |
-
key: torch.Tensor,
|
| 29 |
-
value: torch.Tensor,
|
| 30 |
-
output: torch.Tensor,
|
| 31 |
-
query_scale: torch.Tensor,
|
| 32 |
-
key_scale: torch.Tensor,
|
| 33 |
-
tensor_layout: int,
|
| 34 |
-
is_causal: int,
|
| 35 |
-
qk_quant_gran: int,
|
| 36 |
-
sm_scale: float,
|
| 37 |
-
return_lse: int,
|
| 38 |
-
) -> torch.Tensor:
|
| 39 |
batch_size = query.size(0)
|
| 40 |
-
|
| 41 |
if tensor_layout == 0:
|
| 42 |
num_qo_heads = query.size(2)
|
| 43 |
qo_len = query.size(1)
|
| 44 |
else:
|
| 45 |
num_qo_heads = query.size(1)
|
| 46 |
qo_len = query.size(2)
|
| 47 |
-
|
| 48 |
if return_lse:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
lse = torch.empty((0))
|
| 52 |
-
return lse
|
| 53 |
|
| 54 |
|
| 55 |
-
@torch.library.
|
| 56 |
-
def
|
| 57 |
-
query
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
query_scale: torch.Tensor,
|
| 62 |
-
key_scale: torch.Tensor,
|
| 63 |
-
value_scale: torch.Tensor,
|
| 64 |
-
tensor_layout: int,
|
| 65 |
-
is_causal: int,
|
| 66 |
-
qk_quant_gran: int,
|
| 67 |
-
sm_scale: float,
|
| 68 |
-
return_lse: int,
|
| 69 |
-
) -> torch.Tensor:
|
| 70 |
-
return ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90(
|
| 71 |
-
query, key, value, output, query_scale, key_scale, value_scale,
|
| 72 |
-
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse
|
| 73 |
-
)
|
| 74 |
|
| 75 |
|
| 76 |
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90"))
|
| 77 |
-
def
|
| 78 |
-
query
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
is_causal: int,
|
| 87 |
-
qk_quant_gran: int,
|
| 88 |
-
sm_scale: float,
|
| 89 |
-
return_lse: int,
|
| 90 |
-
) -> torch.Tensor:
|
| 91 |
-
return qk_int8_sv_f8_accum_f32_attn_inst_buf_fake_impl(
|
| 92 |
-
query, key, value, output, query_scale, key_scale, tensor_layout,
|
| 93 |
-
is_causal, qk_quant_gran, sm_scale, return_lse
|
| 94 |
-
)
|
|
|
|
| 2 |
import torch
|
| 3 |
from ._ops import add_op_namespace_prefix
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
def _lse_fake_impl(query, tensor_layout, return_lse):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
batch_size = query.size(0)
|
|
|
|
| 8 |
if tensor_layout == 0:
|
| 9 |
num_qo_heads = query.size(2)
|
| 10 |
qo_len = query.size(1)
|
| 11 |
else:
|
| 12 |
num_qo_heads = query.size(1)
|
| 13 |
qo_len = query.size(2)
|
|
|
|
| 14 |
if return_lse:
|
| 15 |
+
return torch.empty((batch_size, num_qo_heads, qo_len), dtype=torch.float32, device=query.device)
|
| 16 |
+
return torch.empty((0))
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_attn_inst_buf"))
|
| 20 |
+
def qk_int8_sv_f8_accum_f32_attn_inst_buf_fake(
|
| 21 |
+
query, key, value, output, query_scale, key_scale,
|
| 22 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 23 |
+
):
|
| 24 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
|
| 27 |
@torch.library.register_fake(add_op_namespace_prefix("qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90"))
|
| 28 |
+
def qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90_fake(
|
| 29 |
+
query, key, value, output, query_scale, key_scale, value_scale,
|
| 30 |
+
tensor_layout, is_causal, qk_quant_gran, sm_scale, return_lse,
|
| 31 |
+
):
|
| 32 |
+
return _lse_fake_impl(query, tensor_layout, return_lse)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
qk_int8_sv_f8_accum_f32_attn_inst_buf = ops.qk_int8_sv_f8_accum_f32_attn_inst_buf
|
| 36 |
+
qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90 = ops.qk_int8_sv_f8_accum_f32_fuse_v_scale_attn_inst_buf_sm90
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|