Uploaded using `kernel-builder`.
Browse files- build/torch212-cxx11-cu130-x86_64-linux/__init__.py +118 -0
- build/torch212-cxx11-cu130-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so} +2 -2
- build/torch212-cxx11-cu130-x86_64-linux/_ops.py +3 -3
- build/torch212-cxx11-cu130-x86_64-linux/metadata.json +5 -5
- build/torch212-cxx11-cu132-x86_64-linux/__init__.py +118 -0
- build/torch212-cxx11-cu132-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so} +2 -2
- build/torch212-cxx11-cu132-x86_64-linux/_ops.py +3 -3
- build/torch212-cxx11-cu132-x86_64-linux/metadata.json +5 -5
- build/torch213-cxx11-cu130-x86_64-linux/__init__.py +118 -0
- build/torch213-cxx11-cu130-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so} +2 -2
- build/torch213-cxx11-cu130-x86_64-linux/_ops.py +3 -3
- build/torch213-cxx11-cu130-x86_64-linux/metadata.json +5 -5
- build/torch213-cxx11-cu132-x86_64-linux/__init__.py +118 -0
- build/torch213-cxx11-cu132-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so} +2 -2
- build/torch213-cxx11-cu132-x86_64-linux/_ops.py +3 -3
- build/torch213-cxx11-cu132-x86_64-linux/metadata.json +5 -5
build/torch212-cxx11-cu130-x86_64-linux/__init__.py
CHANGED
|
@@ -109,6 +109,11 @@ def _quant_mse_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 113 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
return None
|
|
@@ -186,6 +191,91 @@ def quantize_fp4_sfa_mse_fp16(
|
|
| 186 |
return packed, sfa
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
def quantize_e0m3_sfa_fp16(
|
| 190 |
x: torch.Tensor,
|
| 191 |
packed: torch.Tensor | None = None,
|
|
@@ -381,6 +471,29 @@ def nvfp4_gemm_geglu_nvfp4_fp16(
|
|
| 381 |
return out_packed, out_sfa
|
| 382 |
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 385 |
a_packed: torch.Tensor,
|
| 386 |
b_packed: torch.Tensor,
|
|
@@ -601,6 +714,8 @@ def nvfp4_gemm_streamk_bias_bf16(
|
|
| 601 |
|
| 602 |
|
| 603 |
__all__ = [
|
|
|
|
|
|
|
| 604 |
"dequantize_fp4_sfa_fp16",
|
| 605 |
"e0m3_weight_gemm_fp16",
|
| 606 |
"fp4_w4a16_linear_bf16",
|
|
@@ -622,6 +737,9 @@ __all__ = [
|
|
| 622 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 623 |
"quantize_fp4_sfa_fp16",
|
| 624 |
"quantize_fp4_sfa_mse_fp16",
|
|
|
|
|
|
|
|
|
|
| 625 |
"quantize_e0m3_sfa_fp16",
|
| 626 |
"quantize_fp4_sfa_bf16",
|
| 627 |
"sfa_size_bytes",
|
|
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
| 112 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp4_sfa_mse_bf16"))
|
| 113 |
+
def _quant_mse_bf16_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
|
| 117 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 118 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 119 |
return None
|
|
|
|
| 191 |
return packed, sfa
|
| 192 |
|
| 193 |
|
| 194 |
+
def quantize_fp4_sfa_mse_bf16(
|
| 195 |
+
x: torch.Tensor,
|
| 196 |
+
packed: torch.Tensor | None = None,
|
| 197 |
+
sfa: torch.Tensor | None = None,
|
| 198 |
+
is_sfb: bool = False,
|
| 199 |
+
):
|
| 200 |
+
"""Pack BF16 weights using per-block reconstruction-MSE scale search."""
|
| 201 |
+
if packed is None or sfa is None:
|
| 202 |
+
packed, sfa = _alloc_fp4(x.shape[0], x.shape[1], x.device)
|
| 203 |
+
ops.quantize_fp4_sfa_mse_bf16(x, packed, sfa, bool(is_sfb))
|
| 204 |
+
return packed, sfa
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def aligned_fp4_dim(dim: int, alignment: int = 32) -> int:
|
| 208 |
+
"""Return the physical FP4 GEMM dimension for a logical dimension."""
|
| 209 |
+
if dim <= 0 or alignment <= 0 or alignment % 16 != 0:
|
| 210 |
+
raise ValueError("dim must be positive and alignment divisible by 16")
|
| 211 |
+
return ((dim + alignment - 1) // alignment) * alignment
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def quantize_fp4_sfa_padded_bf16(
|
| 215 |
+
x: torch.Tensor,
|
| 216 |
+
*,
|
| 217 |
+
alignment: int = 32,
|
| 218 |
+
is_sfb: bool = False,
|
| 219 |
+
):
|
| 220 |
+
"""Bind-time BF16 pack with zero padding on the final dimension.
|
| 221 |
+
|
| 222 |
+
The returned packed tensor uses the physical aligned width. Keep the
|
| 223 |
+
logical width returned as the third item for slicing final model outputs.
|
| 224 |
+
This helper allocates and is intentionally not a runtime hot-path op.
|
| 225 |
+
"""
|
| 226 |
+
if x.ndim != 2 or x.dtype != torch.bfloat16:
|
| 227 |
+
raise ValueError("x must be a 2-D BF16 tensor")
|
| 228 |
+
logical_dim = int(x.shape[1])
|
| 229 |
+
physical_dim = aligned_fp4_dim(logical_dim, alignment)
|
| 230 |
+
if physical_dim == logical_dim:
|
| 231 |
+
padded = x.contiguous()
|
| 232 |
+
else:
|
| 233 |
+
padded = torch.zeros(
|
| 234 |
+
(x.shape[0], physical_dim), device=x.device, dtype=x.dtype
|
| 235 |
+
)
|
| 236 |
+
padded[:, :logical_dim].copy_(x)
|
| 237 |
+
packed, sfa = quantize_fp4_sfa_bf16(padded, is_sfb=is_sfb)
|
| 238 |
+
return packed, sfa, logical_dim
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def pack_nvfp4_weight_bf16(
|
| 242 |
+
weight: torch.Tensor,
|
| 243 |
+
bias: torch.Tensor | None = None,
|
| 244 |
+
*,
|
| 245 |
+
alignment: int = 32,
|
| 246 |
+
mse: bool = False,
|
| 247 |
+
):
|
| 248 |
+
"""Zero-pad and pack a logical ``(N, K)`` BF16 weight at bind time.
|
| 249 |
+
|
| 250 |
+
Both physical ``N`` and ``K`` are aligned. This is the model-neutral
|
| 251 |
+
contract used by widths such as SigLIP's logical 4304, which becomes 4320
|
| 252 |
+
for Blackwell NVFP4 TMA. The hot path consumes the returned static tensors
|
| 253 |
+
directly and performs no padding or allocation.
|
| 254 |
+
"""
|
| 255 |
+
if weight.ndim != 2 or weight.dtype != torch.bfloat16:
|
| 256 |
+
raise ValueError("weight must be a 2-D BF16 tensor")
|
| 257 |
+
logical_n, logical_k = map(int, weight.shape)
|
| 258 |
+
physical_n = aligned_fp4_dim(logical_n, alignment)
|
| 259 |
+
physical_k = aligned_fp4_dim(logical_k, alignment)
|
| 260 |
+
padded_weight = torch.zeros(
|
| 261 |
+
(physical_n, physical_k), device=weight.device, dtype=weight.dtype
|
| 262 |
+
)
|
| 263 |
+
padded_weight[:logical_n, :logical_k].copy_(weight)
|
| 264 |
+
quantize = quantize_fp4_sfa_mse_bf16 if mse else quantize_fp4_sfa_bf16
|
| 265 |
+
packed, sfb = quantize(padded_weight, is_sfb=True)
|
| 266 |
+
padded_bias = None
|
| 267 |
+
if bias is not None:
|
| 268 |
+
if bias.ndim != 1 or bias.numel() != logical_n:
|
| 269 |
+
raise ValueError("bias must have shape (N,)")
|
| 270 |
+
if bias.dtype != torch.bfloat16 or bias.device != weight.device:
|
| 271 |
+
raise ValueError("bias must match the weight dtype and device")
|
| 272 |
+
padded_bias = torch.zeros(
|
| 273 |
+
(physical_n,), device=bias.device, dtype=bias.dtype
|
| 274 |
+
)
|
| 275 |
+
padded_bias[:logical_n].copy_(bias)
|
| 276 |
+
return packed, sfb, padded_bias, (logical_n, logical_k)
|
| 277 |
+
|
| 278 |
+
|
| 279 |
def quantize_e0m3_sfa_fp16(
|
| 280 |
x: torch.Tensor,
|
| 281 |
packed: torch.Tensor | None = None,
|
|
|
|
| 471 |
return out_packed, out_sfa
|
| 472 |
|
| 473 |
|
| 474 |
+
def cutlass_fp4_gemm_geglu_il_hw_v10(
|
| 475 |
+
a_packed: torch.Tensor,
|
| 476 |
+
b_interleaved_packed: torch.Tensor,
|
| 477 |
+
sfa: torch.Tensor,
|
| 478 |
+
sfb: torch.Tensor,
|
| 479 |
+
*,
|
| 480 |
+
scratch: torch.Tensor | None = None,
|
| 481 |
+
out_packed: torch.Tensor | None = None,
|
| 482 |
+
out_sfa: torch.Tensor | None = None,
|
| 483 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 484 |
+
"""Explicit public alias for the native SM110 v10 GeGLU schedule."""
|
| 485 |
+
return nvfp4_gemm_geglu_nvfp4_fp16(
|
| 486 |
+
a_packed,
|
| 487 |
+
b_interleaved_packed,
|
| 488 |
+
sfa,
|
| 489 |
+
sfb,
|
| 490 |
+
skinny=True,
|
| 491 |
+
scratch=scratch,
|
| 492 |
+
out_packed=out_packed,
|
| 493 |
+
out_sfa=out_sfa,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 498 |
a_packed: torch.Tensor,
|
| 499 |
b_packed: torch.Tensor,
|
|
|
|
| 714 |
|
| 715 |
|
| 716 |
__all__ = [
|
| 717 |
+
"aligned_fp4_dim",
|
| 718 |
+
"cutlass_fp4_gemm_geglu_il_hw_v10",
|
| 719 |
"dequantize_fp4_sfa_fp16",
|
| 720 |
"e0m3_weight_gemm_fp16",
|
| 721 |
"fp4_w4a16_linear_bf16",
|
|
|
|
| 737 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 738 |
"quantize_fp4_sfa_fp16",
|
| 739 |
"quantize_fp4_sfa_mse_fp16",
|
| 740 |
+
"quantize_fp4_sfa_mse_bf16",
|
| 741 |
+
"quantize_fp4_sfa_padded_bf16",
|
| 742 |
+
"pack_nvfp4_weight_bf16",
|
| 743 |
"quantize_e0m3_sfa_fp16",
|
| 744 |
"quantize_fp4_sfa_bf16",
|
| 745 |
"sfa_size_bytes",
|
build/torch212-cxx11-cu130-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fe2db33c4dc640281bcfccce7ae0c98a53a42efeef388079b65149bb7e3031a5
|
| 3 |
+
size 7895896
|
build/torch212-cxx11-cu130-x86_64-linux/_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 _fp4_gemm_cuda_92c4b99
|
| 3 |
+
ops = torch.ops._fp4_gemm_cuda_92c4b99
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_fp4_gemm_cuda_92c4b99::{op_name}"
|
build/torch212-cxx11-cu130-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
@@ -14,9 +14,9 @@
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
-
"__init__.py": "
|
| 18 |
-
"
|
| 19 |
-
"_ops.py": "
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
@@ -26,7 +26,7 @@
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
-
"sha": "
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
+
"id": "_fp4_gemm_cuda_92c4b99",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
+
"__init__.py": "Mr1/bAUzs+af68D+bRXX6iONDof//dzKgn6QU5pKdu8=",
|
| 18 |
+
"_fp4_gemm_cuda_92c4b99.abi3.so": "/i2zPE3GQCgbz8zOeuDJilOkLv7vOIB5tlFJu34wMaU=",
|
| 19 |
+
"_ops.py": "c5GHeHUOPDgpedue7MgdtRjCwHOmUsBo4OfqoFVegq0="
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
+
"sha": "92c4b991b6f1fbd89744aa6f46f62b1bfac7ca7e",
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
build/torch212-cxx11-cu132-x86_64-linux/__init__.py
CHANGED
|
@@ -109,6 +109,11 @@ def _quant_mse_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 113 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
return None
|
|
@@ -186,6 +191,91 @@ def quantize_fp4_sfa_mse_fp16(
|
|
| 186 |
return packed, sfa
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
def quantize_e0m3_sfa_fp16(
|
| 190 |
x: torch.Tensor,
|
| 191 |
packed: torch.Tensor | None = None,
|
|
@@ -381,6 +471,29 @@ def nvfp4_gemm_geglu_nvfp4_fp16(
|
|
| 381 |
return out_packed, out_sfa
|
| 382 |
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 385 |
a_packed: torch.Tensor,
|
| 386 |
b_packed: torch.Tensor,
|
|
@@ -601,6 +714,8 @@ def nvfp4_gemm_streamk_bias_bf16(
|
|
| 601 |
|
| 602 |
|
| 603 |
__all__ = [
|
|
|
|
|
|
|
| 604 |
"dequantize_fp4_sfa_fp16",
|
| 605 |
"e0m3_weight_gemm_fp16",
|
| 606 |
"fp4_w4a16_linear_bf16",
|
|
@@ -622,6 +737,9 @@ __all__ = [
|
|
| 622 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 623 |
"quantize_fp4_sfa_fp16",
|
| 624 |
"quantize_fp4_sfa_mse_fp16",
|
|
|
|
|
|
|
|
|
|
| 625 |
"quantize_e0m3_sfa_fp16",
|
| 626 |
"quantize_fp4_sfa_bf16",
|
| 627 |
"sfa_size_bytes",
|
|
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
| 112 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp4_sfa_mse_bf16"))
|
| 113 |
+
def _quant_mse_bf16_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
|
| 117 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 118 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 119 |
return None
|
|
|
|
| 191 |
return packed, sfa
|
| 192 |
|
| 193 |
|
| 194 |
+
def quantize_fp4_sfa_mse_bf16(
|
| 195 |
+
x: torch.Tensor,
|
| 196 |
+
packed: torch.Tensor | None = None,
|
| 197 |
+
sfa: torch.Tensor | None = None,
|
| 198 |
+
is_sfb: bool = False,
|
| 199 |
+
):
|
| 200 |
+
"""Pack BF16 weights using per-block reconstruction-MSE scale search."""
|
| 201 |
+
if packed is None or sfa is None:
|
| 202 |
+
packed, sfa = _alloc_fp4(x.shape[0], x.shape[1], x.device)
|
| 203 |
+
ops.quantize_fp4_sfa_mse_bf16(x, packed, sfa, bool(is_sfb))
|
| 204 |
+
return packed, sfa
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def aligned_fp4_dim(dim: int, alignment: int = 32) -> int:
|
| 208 |
+
"""Return the physical FP4 GEMM dimension for a logical dimension."""
|
| 209 |
+
if dim <= 0 or alignment <= 0 or alignment % 16 != 0:
|
| 210 |
+
raise ValueError("dim must be positive and alignment divisible by 16")
|
| 211 |
+
return ((dim + alignment - 1) // alignment) * alignment
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def quantize_fp4_sfa_padded_bf16(
|
| 215 |
+
x: torch.Tensor,
|
| 216 |
+
*,
|
| 217 |
+
alignment: int = 32,
|
| 218 |
+
is_sfb: bool = False,
|
| 219 |
+
):
|
| 220 |
+
"""Bind-time BF16 pack with zero padding on the final dimension.
|
| 221 |
+
|
| 222 |
+
The returned packed tensor uses the physical aligned width. Keep the
|
| 223 |
+
logical width returned as the third item for slicing final model outputs.
|
| 224 |
+
This helper allocates and is intentionally not a runtime hot-path op.
|
| 225 |
+
"""
|
| 226 |
+
if x.ndim != 2 or x.dtype != torch.bfloat16:
|
| 227 |
+
raise ValueError("x must be a 2-D BF16 tensor")
|
| 228 |
+
logical_dim = int(x.shape[1])
|
| 229 |
+
physical_dim = aligned_fp4_dim(logical_dim, alignment)
|
| 230 |
+
if physical_dim == logical_dim:
|
| 231 |
+
padded = x.contiguous()
|
| 232 |
+
else:
|
| 233 |
+
padded = torch.zeros(
|
| 234 |
+
(x.shape[0], physical_dim), device=x.device, dtype=x.dtype
|
| 235 |
+
)
|
| 236 |
+
padded[:, :logical_dim].copy_(x)
|
| 237 |
+
packed, sfa = quantize_fp4_sfa_bf16(padded, is_sfb=is_sfb)
|
| 238 |
+
return packed, sfa, logical_dim
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def pack_nvfp4_weight_bf16(
|
| 242 |
+
weight: torch.Tensor,
|
| 243 |
+
bias: torch.Tensor | None = None,
|
| 244 |
+
*,
|
| 245 |
+
alignment: int = 32,
|
| 246 |
+
mse: bool = False,
|
| 247 |
+
):
|
| 248 |
+
"""Zero-pad and pack a logical ``(N, K)`` BF16 weight at bind time.
|
| 249 |
+
|
| 250 |
+
Both physical ``N`` and ``K`` are aligned. This is the model-neutral
|
| 251 |
+
contract used by widths such as SigLIP's logical 4304, which becomes 4320
|
| 252 |
+
for Blackwell NVFP4 TMA. The hot path consumes the returned static tensors
|
| 253 |
+
directly and performs no padding or allocation.
|
| 254 |
+
"""
|
| 255 |
+
if weight.ndim != 2 or weight.dtype != torch.bfloat16:
|
| 256 |
+
raise ValueError("weight must be a 2-D BF16 tensor")
|
| 257 |
+
logical_n, logical_k = map(int, weight.shape)
|
| 258 |
+
physical_n = aligned_fp4_dim(logical_n, alignment)
|
| 259 |
+
physical_k = aligned_fp4_dim(logical_k, alignment)
|
| 260 |
+
padded_weight = torch.zeros(
|
| 261 |
+
(physical_n, physical_k), device=weight.device, dtype=weight.dtype
|
| 262 |
+
)
|
| 263 |
+
padded_weight[:logical_n, :logical_k].copy_(weight)
|
| 264 |
+
quantize = quantize_fp4_sfa_mse_bf16 if mse else quantize_fp4_sfa_bf16
|
| 265 |
+
packed, sfb = quantize(padded_weight, is_sfb=True)
|
| 266 |
+
padded_bias = None
|
| 267 |
+
if bias is not None:
|
| 268 |
+
if bias.ndim != 1 or bias.numel() != logical_n:
|
| 269 |
+
raise ValueError("bias must have shape (N,)")
|
| 270 |
+
if bias.dtype != torch.bfloat16 or bias.device != weight.device:
|
| 271 |
+
raise ValueError("bias must match the weight dtype and device")
|
| 272 |
+
padded_bias = torch.zeros(
|
| 273 |
+
(physical_n,), device=bias.device, dtype=bias.dtype
|
| 274 |
+
)
|
| 275 |
+
padded_bias[:logical_n].copy_(bias)
|
| 276 |
+
return packed, sfb, padded_bias, (logical_n, logical_k)
|
| 277 |
+
|
| 278 |
+
|
| 279 |
def quantize_e0m3_sfa_fp16(
|
| 280 |
x: torch.Tensor,
|
| 281 |
packed: torch.Tensor | None = None,
|
|
|
|
| 471 |
return out_packed, out_sfa
|
| 472 |
|
| 473 |
|
| 474 |
+
def cutlass_fp4_gemm_geglu_il_hw_v10(
|
| 475 |
+
a_packed: torch.Tensor,
|
| 476 |
+
b_interleaved_packed: torch.Tensor,
|
| 477 |
+
sfa: torch.Tensor,
|
| 478 |
+
sfb: torch.Tensor,
|
| 479 |
+
*,
|
| 480 |
+
scratch: torch.Tensor | None = None,
|
| 481 |
+
out_packed: torch.Tensor | None = None,
|
| 482 |
+
out_sfa: torch.Tensor | None = None,
|
| 483 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 484 |
+
"""Explicit public alias for the native SM110 v10 GeGLU schedule."""
|
| 485 |
+
return nvfp4_gemm_geglu_nvfp4_fp16(
|
| 486 |
+
a_packed,
|
| 487 |
+
b_interleaved_packed,
|
| 488 |
+
sfa,
|
| 489 |
+
sfb,
|
| 490 |
+
skinny=True,
|
| 491 |
+
scratch=scratch,
|
| 492 |
+
out_packed=out_packed,
|
| 493 |
+
out_sfa=out_sfa,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 498 |
a_packed: torch.Tensor,
|
| 499 |
b_packed: torch.Tensor,
|
|
|
|
| 714 |
|
| 715 |
|
| 716 |
__all__ = [
|
| 717 |
+
"aligned_fp4_dim",
|
| 718 |
+
"cutlass_fp4_gemm_geglu_il_hw_v10",
|
| 719 |
"dequantize_fp4_sfa_fp16",
|
| 720 |
"e0m3_weight_gemm_fp16",
|
| 721 |
"fp4_w4a16_linear_bf16",
|
|
|
|
| 737 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 738 |
"quantize_fp4_sfa_fp16",
|
| 739 |
"quantize_fp4_sfa_mse_fp16",
|
| 740 |
+
"quantize_fp4_sfa_mse_bf16",
|
| 741 |
+
"quantize_fp4_sfa_padded_bf16",
|
| 742 |
+
"pack_nvfp4_weight_bf16",
|
| 743 |
"quantize_e0m3_sfa_fp16",
|
| 744 |
"quantize_fp4_sfa_bf16",
|
| 745 |
"sfa_size_bytes",
|
build/torch212-cxx11-cu132-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68ba4bc31b2467a824e3e0a2daeb3ddacac43f4e16b5ec0779b90c283194f0cb
|
| 3 |
+
size 7887648
|
build/torch212-cxx11-cu132-x86_64-linux/_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 _fp4_gemm_cuda_92c4b99
|
| 3 |
+
ops = torch.ops._fp4_gemm_cuda_92c4b99
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_fp4_gemm_cuda_92c4b99::{op_name}"
|
build/torch212-cxx11-cu132-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
@@ -14,9 +14,9 @@
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
-
"__init__.py": "
|
| 18 |
-
"
|
| 19 |
-
"_ops.py": "
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
@@ -26,7 +26,7 @@
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
-
"sha": "
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
+
"id": "_fp4_gemm_cuda_92c4b99",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
+
"__init__.py": "Mr1/bAUzs+af68D+bRXX6iONDof//dzKgn6QU5pKdu8=",
|
| 18 |
+
"_fp4_gemm_cuda_92c4b99.abi3.so": "aLpLwxskZ6gk4+Ci2us92srEP04WtewHebkMKDGU8Ms=",
|
| 19 |
+
"_ops.py": "c5GHeHUOPDgpedue7MgdtRjCwHOmUsBo4OfqoFVegq0="
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
+
"sha": "92c4b991b6f1fbd89744aa6f46f62b1bfac7ca7e",
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
build/torch213-cxx11-cu130-x86_64-linux/__init__.py
CHANGED
|
@@ -109,6 +109,11 @@ def _quant_mse_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 113 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
return None
|
|
@@ -186,6 +191,91 @@ def quantize_fp4_sfa_mse_fp16(
|
|
| 186 |
return packed, sfa
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
def quantize_e0m3_sfa_fp16(
|
| 190 |
x: torch.Tensor,
|
| 191 |
packed: torch.Tensor | None = None,
|
|
@@ -381,6 +471,29 @@ def nvfp4_gemm_geglu_nvfp4_fp16(
|
|
| 381 |
return out_packed, out_sfa
|
| 382 |
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 385 |
a_packed: torch.Tensor,
|
| 386 |
b_packed: torch.Tensor,
|
|
@@ -601,6 +714,8 @@ def nvfp4_gemm_streamk_bias_bf16(
|
|
| 601 |
|
| 602 |
|
| 603 |
__all__ = [
|
|
|
|
|
|
|
| 604 |
"dequantize_fp4_sfa_fp16",
|
| 605 |
"e0m3_weight_gemm_fp16",
|
| 606 |
"fp4_w4a16_linear_bf16",
|
|
@@ -622,6 +737,9 @@ __all__ = [
|
|
| 622 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 623 |
"quantize_fp4_sfa_fp16",
|
| 624 |
"quantize_fp4_sfa_mse_fp16",
|
|
|
|
|
|
|
|
|
|
| 625 |
"quantize_e0m3_sfa_fp16",
|
| 626 |
"quantize_fp4_sfa_bf16",
|
| 627 |
"sfa_size_bytes",
|
|
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
| 112 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp4_sfa_mse_bf16"))
|
| 113 |
+
def _quant_mse_bf16_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
|
| 117 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 118 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 119 |
return None
|
|
|
|
| 191 |
return packed, sfa
|
| 192 |
|
| 193 |
|
| 194 |
+
def quantize_fp4_sfa_mse_bf16(
|
| 195 |
+
x: torch.Tensor,
|
| 196 |
+
packed: torch.Tensor | None = None,
|
| 197 |
+
sfa: torch.Tensor | None = None,
|
| 198 |
+
is_sfb: bool = False,
|
| 199 |
+
):
|
| 200 |
+
"""Pack BF16 weights using per-block reconstruction-MSE scale search."""
|
| 201 |
+
if packed is None or sfa is None:
|
| 202 |
+
packed, sfa = _alloc_fp4(x.shape[0], x.shape[1], x.device)
|
| 203 |
+
ops.quantize_fp4_sfa_mse_bf16(x, packed, sfa, bool(is_sfb))
|
| 204 |
+
return packed, sfa
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def aligned_fp4_dim(dim: int, alignment: int = 32) -> int:
|
| 208 |
+
"""Return the physical FP4 GEMM dimension for a logical dimension."""
|
| 209 |
+
if dim <= 0 or alignment <= 0 or alignment % 16 != 0:
|
| 210 |
+
raise ValueError("dim must be positive and alignment divisible by 16")
|
| 211 |
+
return ((dim + alignment - 1) // alignment) * alignment
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def quantize_fp4_sfa_padded_bf16(
|
| 215 |
+
x: torch.Tensor,
|
| 216 |
+
*,
|
| 217 |
+
alignment: int = 32,
|
| 218 |
+
is_sfb: bool = False,
|
| 219 |
+
):
|
| 220 |
+
"""Bind-time BF16 pack with zero padding on the final dimension.
|
| 221 |
+
|
| 222 |
+
The returned packed tensor uses the physical aligned width. Keep the
|
| 223 |
+
logical width returned as the third item for slicing final model outputs.
|
| 224 |
+
This helper allocates and is intentionally not a runtime hot-path op.
|
| 225 |
+
"""
|
| 226 |
+
if x.ndim != 2 or x.dtype != torch.bfloat16:
|
| 227 |
+
raise ValueError("x must be a 2-D BF16 tensor")
|
| 228 |
+
logical_dim = int(x.shape[1])
|
| 229 |
+
physical_dim = aligned_fp4_dim(logical_dim, alignment)
|
| 230 |
+
if physical_dim == logical_dim:
|
| 231 |
+
padded = x.contiguous()
|
| 232 |
+
else:
|
| 233 |
+
padded = torch.zeros(
|
| 234 |
+
(x.shape[0], physical_dim), device=x.device, dtype=x.dtype
|
| 235 |
+
)
|
| 236 |
+
padded[:, :logical_dim].copy_(x)
|
| 237 |
+
packed, sfa = quantize_fp4_sfa_bf16(padded, is_sfb=is_sfb)
|
| 238 |
+
return packed, sfa, logical_dim
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def pack_nvfp4_weight_bf16(
|
| 242 |
+
weight: torch.Tensor,
|
| 243 |
+
bias: torch.Tensor | None = None,
|
| 244 |
+
*,
|
| 245 |
+
alignment: int = 32,
|
| 246 |
+
mse: bool = False,
|
| 247 |
+
):
|
| 248 |
+
"""Zero-pad and pack a logical ``(N, K)`` BF16 weight at bind time.
|
| 249 |
+
|
| 250 |
+
Both physical ``N`` and ``K`` are aligned. This is the model-neutral
|
| 251 |
+
contract used by widths such as SigLIP's logical 4304, which becomes 4320
|
| 252 |
+
for Blackwell NVFP4 TMA. The hot path consumes the returned static tensors
|
| 253 |
+
directly and performs no padding or allocation.
|
| 254 |
+
"""
|
| 255 |
+
if weight.ndim != 2 or weight.dtype != torch.bfloat16:
|
| 256 |
+
raise ValueError("weight must be a 2-D BF16 tensor")
|
| 257 |
+
logical_n, logical_k = map(int, weight.shape)
|
| 258 |
+
physical_n = aligned_fp4_dim(logical_n, alignment)
|
| 259 |
+
physical_k = aligned_fp4_dim(logical_k, alignment)
|
| 260 |
+
padded_weight = torch.zeros(
|
| 261 |
+
(physical_n, physical_k), device=weight.device, dtype=weight.dtype
|
| 262 |
+
)
|
| 263 |
+
padded_weight[:logical_n, :logical_k].copy_(weight)
|
| 264 |
+
quantize = quantize_fp4_sfa_mse_bf16 if mse else quantize_fp4_sfa_bf16
|
| 265 |
+
packed, sfb = quantize(padded_weight, is_sfb=True)
|
| 266 |
+
padded_bias = None
|
| 267 |
+
if bias is not None:
|
| 268 |
+
if bias.ndim != 1 or bias.numel() != logical_n:
|
| 269 |
+
raise ValueError("bias must have shape (N,)")
|
| 270 |
+
if bias.dtype != torch.bfloat16 or bias.device != weight.device:
|
| 271 |
+
raise ValueError("bias must match the weight dtype and device")
|
| 272 |
+
padded_bias = torch.zeros(
|
| 273 |
+
(physical_n,), device=bias.device, dtype=bias.dtype
|
| 274 |
+
)
|
| 275 |
+
padded_bias[:logical_n].copy_(bias)
|
| 276 |
+
return packed, sfb, padded_bias, (logical_n, logical_k)
|
| 277 |
+
|
| 278 |
+
|
| 279 |
def quantize_e0m3_sfa_fp16(
|
| 280 |
x: torch.Tensor,
|
| 281 |
packed: torch.Tensor | None = None,
|
|
|
|
| 471 |
return out_packed, out_sfa
|
| 472 |
|
| 473 |
|
| 474 |
+
def cutlass_fp4_gemm_geglu_il_hw_v10(
|
| 475 |
+
a_packed: torch.Tensor,
|
| 476 |
+
b_interleaved_packed: torch.Tensor,
|
| 477 |
+
sfa: torch.Tensor,
|
| 478 |
+
sfb: torch.Tensor,
|
| 479 |
+
*,
|
| 480 |
+
scratch: torch.Tensor | None = None,
|
| 481 |
+
out_packed: torch.Tensor | None = None,
|
| 482 |
+
out_sfa: torch.Tensor | None = None,
|
| 483 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 484 |
+
"""Explicit public alias for the native SM110 v10 GeGLU schedule."""
|
| 485 |
+
return nvfp4_gemm_geglu_nvfp4_fp16(
|
| 486 |
+
a_packed,
|
| 487 |
+
b_interleaved_packed,
|
| 488 |
+
sfa,
|
| 489 |
+
sfb,
|
| 490 |
+
skinny=True,
|
| 491 |
+
scratch=scratch,
|
| 492 |
+
out_packed=out_packed,
|
| 493 |
+
out_sfa=out_sfa,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 498 |
a_packed: torch.Tensor,
|
| 499 |
b_packed: torch.Tensor,
|
|
|
|
| 714 |
|
| 715 |
|
| 716 |
__all__ = [
|
| 717 |
+
"aligned_fp4_dim",
|
| 718 |
+
"cutlass_fp4_gemm_geglu_il_hw_v10",
|
| 719 |
"dequantize_fp4_sfa_fp16",
|
| 720 |
"e0m3_weight_gemm_fp16",
|
| 721 |
"fp4_w4a16_linear_bf16",
|
|
|
|
| 737 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 738 |
"quantize_fp4_sfa_fp16",
|
| 739 |
"quantize_fp4_sfa_mse_fp16",
|
| 740 |
+
"quantize_fp4_sfa_mse_bf16",
|
| 741 |
+
"quantize_fp4_sfa_padded_bf16",
|
| 742 |
+
"pack_nvfp4_weight_bf16",
|
| 743 |
"quantize_e0m3_sfa_fp16",
|
| 744 |
"quantize_fp4_sfa_bf16",
|
| 745 |
"sfa_size_bytes",
|
build/torch213-cxx11-cu130-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6f97f9a442fba5511c0bcded0b9d388f387b9fd26fe56951698a79ded706ca52
|
| 3 |
+
size 7895736
|
build/torch213-cxx11-cu130-x86_64-linux/_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 _fp4_gemm_cuda_92c4b99
|
| 3 |
+
ops = torch.ops._fp4_gemm_cuda_92c4b99
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_fp4_gemm_cuda_92c4b99::{op_name}"
|
build/torch213-cxx11-cu130-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
@@ -14,9 +14,9 @@
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
-
"__init__.py": "
|
| 18 |
-
"
|
| 19 |
-
"_ops.py": "
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
@@ -26,7 +26,7 @@
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
-
"sha": "
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
+
"id": "_fp4_gemm_cuda_92c4b99",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
+
"__init__.py": "Mr1/bAUzs+af68D+bRXX6iONDof//dzKgn6QU5pKdu8=",
|
| 18 |
+
"_fp4_gemm_cuda_92c4b99.abi3.so": "b5f5pEL7pVEcC83tC504jzh7n9Jv5WlRaYp53tcGylI=",
|
| 19 |
+
"_ops.py": "c5GHeHUOPDgpedue7MgdtRjCwHOmUsBo4OfqoFVegq0="
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
+
"sha": "92c4b991b6f1fbd89744aa6f46f62b1bfac7ca7e",
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
build/torch213-cxx11-cu132-x86_64-linux/__init__.py
CHANGED
|
@@ -109,6 +109,11 @@ def _quant_mse_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 113 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
return None
|
|
@@ -186,6 +191,91 @@ def quantize_fp4_sfa_mse_fp16(
|
|
| 186 |
return packed, sfa
|
| 187 |
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
def quantize_e0m3_sfa_fp16(
|
| 190 |
x: torch.Tensor,
|
| 191 |
packed: torch.Tensor | None = None,
|
|
@@ -381,6 +471,29 @@ def nvfp4_gemm_geglu_nvfp4_fp16(
|
|
| 381 |
return out_packed, out_sfa
|
| 382 |
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 385 |
a_packed: torch.Tensor,
|
| 386 |
b_packed: torch.Tensor,
|
|
@@ -601,6 +714,8 @@ def nvfp4_gemm_streamk_bias_bf16(
|
|
| 601 |
|
| 602 |
|
| 603 |
__all__ = [
|
|
|
|
|
|
|
| 604 |
"dequantize_fp4_sfa_fp16",
|
| 605 |
"e0m3_weight_gemm_fp16",
|
| 606 |
"fp4_w4a16_linear_bf16",
|
|
@@ -622,6 +737,9 @@ __all__ = [
|
|
| 622 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 623 |
"quantize_fp4_sfa_fp16",
|
| 624 |
"quantize_fp4_sfa_mse_fp16",
|
|
|
|
|
|
|
|
|
|
| 625 |
"quantize_e0m3_sfa_fp16",
|
| 626 |
"quantize_fp4_sfa_bf16",
|
| 627 |
"sfa_size_bytes",
|
|
|
|
| 109 |
return None
|
| 110 |
|
| 111 |
|
| 112 |
+
@torch.library.register_fake(add_op_namespace_prefix("quantize_fp4_sfa_mse_bf16"))
|
| 113 |
+
def _quant_mse_bf16_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 114 |
+
return None
|
| 115 |
+
|
| 116 |
+
|
| 117 |
@torch.library.register_fake(add_op_namespace_prefix("quantize_e0m3_sfa_fp16"))
|
| 118 |
def _quant_e0m3_fake(x, packed, sfa, is_sfb: bool = False) -> None:
|
| 119 |
return None
|
|
|
|
| 191 |
return packed, sfa
|
| 192 |
|
| 193 |
|
| 194 |
+
def quantize_fp4_sfa_mse_bf16(
|
| 195 |
+
x: torch.Tensor,
|
| 196 |
+
packed: torch.Tensor | None = None,
|
| 197 |
+
sfa: torch.Tensor | None = None,
|
| 198 |
+
is_sfb: bool = False,
|
| 199 |
+
):
|
| 200 |
+
"""Pack BF16 weights using per-block reconstruction-MSE scale search."""
|
| 201 |
+
if packed is None or sfa is None:
|
| 202 |
+
packed, sfa = _alloc_fp4(x.shape[0], x.shape[1], x.device)
|
| 203 |
+
ops.quantize_fp4_sfa_mse_bf16(x, packed, sfa, bool(is_sfb))
|
| 204 |
+
return packed, sfa
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def aligned_fp4_dim(dim: int, alignment: int = 32) -> int:
|
| 208 |
+
"""Return the physical FP4 GEMM dimension for a logical dimension."""
|
| 209 |
+
if dim <= 0 or alignment <= 0 or alignment % 16 != 0:
|
| 210 |
+
raise ValueError("dim must be positive and alignment divisible by 16")
|
| 211 |
+
return ((dim + alignment - 1) // alignment) * alignment
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def quantize_fp4_sfa_padded_bf16(
|
| 215 |
+
x: torch.Tensor,
|
| 216 |
+
*,
|
| 217 |
+
alignment: int = 32,
|
| 218 |
+
is_sfb: bool = False,
|
| 219 |
+
):
|
| 220 |
+
"""Bind-time BF16 pack with zero padding on the final dimension.
|
| 221 |
+
|
| 222 |
+
The returned packed tensor uses the physical aligned width. Keep the
|
| 223 |
+
logical width returned as the third item for slicing final model outputs.
|
| 224 |
+
This helper allocates and is intentionally not a runtime hot-path op.
|
| 225 |
+
"""
|
| 226 |
+
if x.ndim != 2 or x.dtype != torch.bfloat16:
|
| 227 |
+
raise ValueError("x must be a 2-D BF16 tensor")
|
| 228 |
+
logical_dim = int(x.shape[1])
|
| 229 |
+
physical_dim = aligned_fp4_dim(logical_dim, alignment)
|
| 230 |
+
if physical_dim == logical_dim:
|
| 231 |
+
padded = x.contiguous()
|
| 232 |
+
else:
|
| 233 |
+
padded = torch.zeros(
|
| 234 |
+
(x.shape[0], physical_dim), device=x.device, dtype=x.dtype
|
| 235 |
+
)
|
| 236 |
+
padded[:, :logical_dim].copy_(x)
|
| 237 |
+
packed, sfa = quantize_fp4_sfa_bf16(padded, is_sfb=is_sfb)
|
| 238 |
+
return packed, sfa, logical_dim
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def pack_nvfp4_weight_bf16(
|
| 242 |
+
weight: torch.Tensor,
|
| 243 |
+
bias: torch.Tensor | None = None,
|
| 244 |
+
*,
|
| 245 |
+
alignment: int = 32,
|
| 246 |
+
mse: bool = False,
|
| 247 |
+
):
|
| 248 |
+
"""Zero-pad and pack a logical ``(N, K)`` BF16 weight at bind time.
|
| 249 |
+
|
| 250 |
+
Both physical ``N`` and ``K`` are aligned. This is the model-neutral
|
| 251 |
+
contract used by widths such as SigLIP's logical 4304, which becomes 4320
|
| 252 |
+
for Blackwell NVFP4 TMA. The hot path consumes the returned static tensors
|
| 253 |
+
directly and performs no padding or allocation.
|
| 254 |
+
"""
|
| 255 |
+
if weight.ndim != 2 or weight.dtype != torch.bfloat16:
|
| 256 |
+
raise ValueError("weight must be a 2-D BF16 tensor")
|
| 257 |
+
logical_n, logical_k = map(int, weight.shape)
|
| 258 |
+
physical_n = aligned_fp4_dim(logical_n, alignment)
|
| 259 |
+
physical_k = aligned_fp4_dim(logical_k, alignment)
|
| 260 |
+
padded_weight = torch.zeros(
|
| 261 |
+
(physical_n, physical_k), device=weight.device, dtype=weight.dtype
|
| 262 |
+
)
|
| 263 |
+
padded_weight[:logical_n, :logical_k].copy_(weight)
|
| 264 |
+
quantize = quantize_fp4_sfa_mse_bf16 if mse else quantize_fp4_sfa_bf16
|
| 265 |
+
packed, sfb = quantize(padded_weight, is_sfb=True)
|
| 266 |
+
padded_bias = None
|
| 267 |
+
if bias is not None:
|
| 268 |
+
if bias.ndim != 1 or bias.numel() != logical_n:
|
| 269 |
+
raise ValueError("bias must have shape (N,)")
|
| 270 |
+
if bias.dtype != torch.bfloat16 or bias.device != weight.device:
|
| 271 |
+
raise ValueError("bias must match the weight dtype and device")
|
| 272 |
+
padded_bias = torch.zeros(
|
| 273 |
+
(physical_n,), device=bias.device, dtype=bias.dtype
|
| 274 |
+
)
|
| 275 |
+
padded_bias[:logical_n].copy_(bias)
|
| 276 |
+
return packed, sfb, padded_bias, (logical_n, logical_k)
|
| 277 |
+
|
| 278 |
+
|
| 279 |
def quantize_e0m3_sfa_fp16(
|
| 280 |
x: torch.Tensor,
|
| 281 |
packed: torch.Tensor | None = None,
|
|
|
|
| 471 |
return out_packed, out_sfa
|
| 472 |
|
| 473 |
|
| 474 |
+
def cutlass_fp4_gemm_geglu_il_hw_v10(
|
| 475 |
+
a_packed: torch.Tensor,
|
| 476 |
+
b_interleaved_packed: torch.Tensor,
|
| 477 |
+
sfa: torch.Tensor,
|
| 478 |
+
sfb: torch.Tensor,
|
| 479 |
+
*,
|
| 480 |
+
scratch: torch.Tensor | None = None,
|
| 481 |
+
out_packed: torch.Tensor | None = None,
|
| 482 |
+
out_sfa: torch.Tensor | None = None,
|
| 483 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 484 |
+
"""Explicit public alias for the native SM110 v10 GeGLU schedule."""
|
| 485 |
+
return nvfp4_gemm_geglu_nvfp4_fp16(
|
| 486 |
+
a_packed,
|
| 487 |
+
b_interleaved_packed,
|
| 488 |
+
sfa,
|
| 489 |
+
sfb,
|
| 490 |
+
skinny=True,
|
| 491 |
+
scratch=scratch,
|
| 492 |
+
out_packed=out_packed,
|
| 493 |
+
out_sfa=out_sfa,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
|
| 497 |
def nvfp4_gemm_bias_gelu_nvfp4_fp16(
|
| 498 |
a_packed: torch.Tensor,
|
| 499 |
b_packed: torch.Tensor,
|
|
|
|
| 714 |
|
| 715 |
|
| 716 |
__all__ = [
|
| 717 |
+
"aligned_fp4_dim",
|
| 718 |
+
"cutlass_fp4_gemm_geglu_il_hw_v10",
|
| 719 |
"dequantize_fp4_sfa_fp16",
|
| 720 |
"e0m3_weight_gemm_fp16",
|
| 721 |
"fp4_w4a16_linear_bf16",
|
|
|
|
| 737 |
"nvfp4_gemm_streamk_bias_bf16",
|
| 738 |
"quantize_fp4_sfa_fp16",
|
| 739 |
"quantize_fp4_sfa_mse_fp16",
|
| 740 |
+
"quantize_fp4_sfa_mse_bf16",
|
| 741 |
+
"quantize_fp4_sfa_padded_bf16",
|
| 742 |
+
"pack_nvfp4_weight_bf16",
|
| 743 |
"quantize_e0m3_sfa_fp16",
|
| 744 |
"quantize_fp4_sfa_bf16",
|
| 745 |
"sfa_size_bytes",
|
build/torch213-cxx11-cu132-x86_64-linux/{_fp4_gemm_cuda_b6588aa.abi3.so → _fp4_gemm_cuda_92c4b99.abi3.so}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d1cfd40cecbd45d8a9e0958a5f9af7508f4b8deb0910eda2ad078c5e82690c55
|
| 3 |
+
size 7887496
|
build/torch213-cxx11-cu132-x86_64-linux/_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 _fp4_gemm_cuda_92c4b99
|
| 3 |
+
ops = torch.ops._fp4_gemm_cuda_92c4b99
|
| 4 |
|
| 5 |
def add_op_namespace_prefix(op_name: str):
|
| 6 |
"""
|
| 7 |
Prefix op by namespace.
|
| 8 |
"""
|
| 9 |
+
return f"_fp4_gemm_cuda_92c4b99::{op_name}"
|
build/torch213-cxx11-cu132-x86_64-linux/metadata.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
-
"id": "
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
@@ -14,9 +14,9 @@
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
-
"__init__.py": "
|
| 18 |
-
"
|
| 19 |
-
"_ops.py": "
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
@@ -26,7 +26,7 @@
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
-
"sha": "
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"name": "fp4-gemm",
|
| 3 |
+
"id": "_fp4_gemm_cuda_92c4b99",
|
| 4 |
"version": 1,
|
| 5 |
"license": "Apache-2.0",
|
| 6 |
"python-depends": [],
|
|
|
|
| 14 |
"digest": {
|
| 15 |
"algorithm": "sha256",
|
| 16 |
"files": {
|
| 17 |
+
"__init__.py": "Mr1/bAUzs+af68D+bRXX6iONDof//dzKgn6QU5pKdu8=",
|
| 18 |
+
"_fp4_gemm_cuda_92c4b99.abi3.so": "0c/UDOy9Rdip4JWKX5r3UI9LjesJEO2irQeMXoJpDFU=",
|
| 19 |
+
"_ops.py": "c5GHeHUOPDgpedue7MgdtRjCwHOmUsBo4OfqoFVegq0="
|
| 20 |
}
|
| 21 |
},
|
| 22 |
"provenance": {
|
|
|
|
| 26 |
"dirty": false
|
| 27 |
},
|
| 28 |
"kernel": {
|
| 29 |
+
"sha": "92c4b991b6f1fbd89744aa6f46f62b1bfac7ca7e",
|
| 30 |
"dirty": false
|
| 31 |
}
|
| 32 |
}
|