Uploaded using `kernel-builder`.
Browse files- build/torch210-cxx11-cu130-aarch64-linux/__init__.py +57 -0
- build/torch210-cxx11-cu130-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so +3 -0
- build/torch210-cxx11-cu130-aarch64-linux/_ops.py +9 -0
- build/torch210-cxx11-cu130-aarch64-linux/metadata.json +10 -0
- build/torch210-cxx11-cu130-aarch64-linux/nvfp4_dense_gemm/__init__.py +26 -0
- build/torch211-cxx11-cu130-aarch64-linux/__init__.py +57 -0
- build/torch211-cxx11-cu130-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so +3 -0
- build/torch211-cxx11-cu130-aarch64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu130-aarch64-linux/metadata.json +10 -0
- build/torch211-cxx11-cu130-aarch64-linux/nvfp4_dense_gemm/__init__.py +26 -0
- build/torch212-cxx11-cu130-aarch64-linux/__init__.py +57 -0
- build/torch212-cxx11-cu130-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so +3 -0
- build/torch212-cxx11-cu130-aarch64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu130-aarch64-linux/metadata.json +10 -0
- build/torch212-cxx11-cu130-aarch64-linux/nvfp4_dense_gemm/__init__.py +26 -0
- build/torch212-cxx11-cu132-aarch64-linux/__init__.py +57 -0
- build/torch212-cxx11-cu132-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so +3 -0
- build/torch212-cxx11-cu132-aarch64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu132-aarch64-linux/metadata.json +10 -0
- build/torch212-cxx11-cu132-aarch64-linux/nvfp4_dense_gemm/__init__.py +26 -0
build/torch210-cxx11-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-only
|
| 2 |
+
"""Atlas dense NVFP4/FP8 GEMM kernels for Qwen3.6-27B on GB10 (SM121).
|
| 3 |
+
|
| 4 |
+
Powers the attention Q/K/V/O projections and the dense FFN
|
| 5 |
+
(intermediate_size=17408, hidden=5120). Two precisions are supported:
|
| 6 |
+
|
| 7 |
+
- W4A16 (NVFP4 weight, BF16 activation): direct path
|
| 8 |
+
- FP8 W/A: via ``predequant_nvfp4_to_fp8`` + ``fp8_gemm_t`` for
|
| 9 |
+
KV-cache scenarios where the weight is loaded as NVFP4 but the
|
| 10 |
+
GEMM runs in FP8 against an FP8-packed activation.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from ._ops import ops
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"w4a16_gemm",
|
| 19 |
+
"w4a16_gemm_t",
|
| 20 |
+
"predequant_nvfp4_to_fp8",
|
| 21 |
+
"fp8_gemm_t",
|
| 22 |
+
"bf16_to_fp8",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def w4a16_gemm(
|
| 27 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 28 |
+
scale2: float, C: torch.Tensor,
|
| 29 |
+
) -> None:
|
| 30 |
+
"""C = A @ B^T where B is NVFP4. Standard layout."""
|
| 31 |
+
ops.w4a16_gemm(A, B_packed, B_scale, scale2, C)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def w4a16_gemm_t(
|
| 35 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 36 |
+
scale2: float, C: torch.Tensor,
|
| 37 |
+
) -> None:
|
| 38 |
+
"""Transposed-B variant (N-major) — typically faster for [N>K] shapes."""
|
| 39 |
+
ops.w4a16_gemm_t(A, B_packed, B_scale, scale2, C)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def predequant_nvfp4_to_fp8(
|
| 43 |
+
B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 44 |
+
scale2: float, B_fp8_out: torch.Tensor,
|
| 45 |
+
) -> None:
|
| 46 |
+
"""Materialize an NVFP4-packed weight into a dense FP8 E4M3 tensor."""
|
| 47 |
+
ops.predequant_nvfp4_to_fp8(B_packed, B_scale, scale2, B_fp8_out)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def fp8_gemm_t(A: torch.Tensor, B_fp8: torch.Tensor, C: torch.Tensor) -> None:
|
| 51 |
+
"""C = A @ B^T where both A is BF16 and B is FP8 E4M3."""
|
| 52 |
+
ops.fp8_gemm_t(A, B_fp8, C)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def bf16_to_fp8(src: torch.Tensor, dst: torch.Tensor) -> None:
|
| 56 |
+
"""Pair-wise BF16 → FP8 E4M3 quantization (no scaling, uses PTX cvt)."""
|
| 57 |
+
ops.bf16_to_fp8(src, dst)
|
build/torch210-cxx11-cu130-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6e1407400342d579a6e86fbe821bcd506fda3ad0216671cf2101e9dcbe49f434
|
| 3 |
+
size 2505208
|
build/torch210-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _nvfp4_dense_gemm_cuda_bcba8ad
|
| 3 |
+
ops = torch.ops._nvfp4_dense_gemm_cuda_bcba8ad
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_nvfp4_dense_gemm_cuda_bcba8ad::{op_name}"
|
build/torch210-cxx11-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "nvfp4-dense-gemm",
|
| 3 |
+
"id": "_nvfp4_dense_gemm_cuda_bcba8ad",
|
| 4 |
+
"version": 0,
|
| 5 |
+
"license": "AGPL-3.0-only",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda"
|
| 9 |
+
}
|
| 10 |
+
}
|
build/torch210-cxx11-cu130-aarch64-linux/nvfp4_dense_gemm/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch211-cxx11-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-only
|
| 2 |
+
"""Atlas dense NVFP4/FP8 GEMM kernels for Qwen3.6-27B on GB10 (SM121).
|
| 3 |
+
|
| 4 |
+
Powers the attention Q/K/V/O projections and the dense FFN
|
| 5 |
+
(intermediate_size=17408, hidden=5120). Two precisions are supported:
|
| 6 |
+
|
| 7 |
+
- W4A16 (NVFP4 weight, BF16 activation): direct path
|
| 8 |
+
- FP8 W/A: via ``predequant_nvfp4_to_fp8`` + ``fp8_gemm_t`` for
|
| 9 |
+
KV-cache scenarios where the weight is loaded as NVFP4 but the
|
| 10 |
+
GEMM runs in FP8 against an FP8-packed activation.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from ._ops import ops
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"w4a16_gemm",
|
| 19 |
+
"w4a16_gemm_t",
|
| 20 |
+
"predequant_nvfp4_to_fp8",
|
| 21 |
+
"fp8_gemm_t",
|
| 22 |
+
"bf16_to_fp8",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def w4a16_gemm(
|
| 27 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 28 |
+
scale2: float, C: torch.Tensor,
|
| 29 |
+
) -> None:
|
| 30 |
+
"""C = A @ B^T where B is NVFP4. Standard layout."""
|
| 31 |
+
ops.w4a16_gemm(A, B_packed, B_scale, scale2, C)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def w4a16_gemm_t(
|
| 35 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 36 |
+
scale2: float, C: torch.Tensor,
|
| 37 |
+
) -> None:
|
| 38 |
+
"""Transposed-B variant (N-major) — typically faster for [N>K] shapes."""
|
| 39 |
+
ops.w4a16_gemm_t(A, B_packed, B_scale, scale2, C)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def predequant_nvfp4_to_fp8(
|
| 43 |
+
B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 44 |
+
scale2: float, B_fp8_out: torch.Tensor,
|
| 45 |
+
) -> None:
|
| 46 |
+
"""Materialize an NVFP4-packed weight into a dense FP8 E4M3 tensor."""
|
| 47 |
+
ops.predequant_nvfp4_to_fp8(B_packed, B_scale, scale2, B_fp8_out)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def fp8_gemm_t(A: torch.Tensor, B_fp8: torch.Tensor, C: torch.Tensor) -> None:
|
| 51 |
+
"""C = A @ B^T where both A is BF16 and B is FP8 E4M3."""
|
| 52 |
+
ops.fp8_gemm_t(A, B_fp8, C)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def bf16_to_fp8(src: torch.Tensor, dst: torch.Tensor) -> None:
|
| 56 |
+
"""Pair-wise BF16 → FP8 E4M3 quantization (no scaling, uses PTX cvt)."""
|
| 57 |
+
ops.bf16_to_fp8(src, dst)
|
build/torch211-cxx11-cu130-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3d646b4764445cdd173802d7c5074664bac8ce4c97df5124075f7e44ac51c808
|
| 3 |
+
size 2505208
|
build/torch211-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _nvfp4_dense_gemm_cuda_bcba8ad
|
| 3 |
+
ops = torch.ops._nvfp4_dense_gemm_cuda_bcba8ad
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_nvfp4_dense_gemm_cuda_bcba8ad::{op_name}"
|
build/torch211-cxx11-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "nvfp4-dense-gemm",
|
| 3 |
+
"id": "_nvfp4_dense_gemm_cuda_bcba8ad",
|
| 4 |
+
"version": 0,
|
| 5 |
+
"license": "AGPL-3.0-only",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda"
|
| 9 |
+
}
|
| 10 |
+
}
|
build/torch211-cxx11-cu130-aarch64-linux/nvfp4_dense_gemm/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu130-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-only
|
| 2 |
+
"""Atlas dense NVFP4/FP8 GEMM kernels for Qwen3.6-27B on GB10 (SM121).
|
| 3 |
+
|
| 4 |
+
Powers the attention Q/K/V/O projections and the dense FFN
|
| 5 |
+
(intermediate_size=17408, hidden=5120). Two precisions are supported:
|
| 6 |
+
|
| 7 |
+
- W4A16 (NVFP4 weight, BF16 activation): direct path
|
| 8 |
+
- FP8 W/A: via ``predequant_nvfp4_to_fp8`` + ``fp8_gemm_t`` for
|
| 9 |
+
KV-cache scenarios where the weight is loaded as NVFP4 but the
|
| 10 |
+
GEMM runs in FP8 against an FP8-packed activation.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from ._ops import ops
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"w4a16_gemm",
|
| 19 |
+
"w4a16_gemm_t",
|
| 20 |
+
"predequant_nvfp4_to_fp8",
|
| 21 |
+
"fp8_gemm_t",
|
| 22 |
+
"bf16_to_fp8",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def w4a16_gemm(
|
| 27 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 28 |
+
scale2: float, C: torch.Tensor,
|
| 29 |
+
) -> None:
|
| 30 |
+
"""C = A @ B^T where B is NVFP4. Standard layout."""
|
| 31 |
+
ops.w4a16_gemm(A, B_packed, B_scale, scale2, C)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def w4a16_gemm_t(
|
| 35 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 36 |
+
scale2: float, C: torch.Tensor,
|
| 37 |
+
) -> None:
|
| 38 |
+
"""Transposed-B variant (N-major) — typically faster for [N>K] shapes."""
|
| 39 |
+
ops.w4a16_gemm_t(A, B_packed, B_scale, scale2, C)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def predequant_nvfp4_to_fp8(
|
| 43 |
+
B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 44 |
+
scale2: float, B_fp8_out: torch.Tensor,
|
| 45 |
+
) -> None:
|
| 46 |
+
"""Materialize an NVFP4-packed weight into a dense FP8 E4M3 tensor."""
|
| 47 |
+
ops.predequant_nvfp4_to_fp8(B_packed, B_scale, scale2, B_fp8_out)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def fp8_gemm_t(A: torch.Tensor, B_fp8: torch.Tensor, C: torch.Tensor) -> None:
|
| 51 |
+
"""C = A @ B^T where both A is BF16 and B is FP8 E4M3."""
|
| 52 |
+
ops.fp8_gemm_t(A, B_fp8, C)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def bf16_to_fp8(src: torch.Tensor, dst: torch.Tensor) -> None:
|
| 56 |
+
"""Pair-wise BF16 → FP8 E4M3 quantization (no scaling, uses PTX cvt)."""
|
| 57 |
+
ops.bf16_to_fp8(src, dst)
|
build/torch212-cxx11-cu130-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7f3695fa1e52677900262e486733b0454ce8312ec1ab834a2026237097733bfb
|
| 3 |
+
size 2505216
|
build/torch212-cxx11-cu130-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _nvfp4_dense_gemm_cuda_bcba8ad
|
| 3 |
+
ops = torch.ops._nvfp4_dense_gemm_cuda_bcba8ad
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_nvfp4_dense_gemm_cuda_bcba8ad::{op_name}"
|
build/torch212-cxx11-cu130-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "nvfp4-dense-gemm",
|
| 3 |
+
"id": "_nvfp4_dense_gemm_cuda_bcba8ad",
|
| 4 |
+
"version": 0,
|
| 5 |
+
"license": "AGPL-3.0-only",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda"
|
| 9 |
+
}
|
| 10 |
+
}
|
build/torch212-cxx11-cu130-aarch64-linux/nvfp4_dense_gemm/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu132-aarch64-linux/__init__.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: AGPL-3.0-only
|
| 2 |
+
"""Atlas dense NVFP4/FP8 GEMM kernels for Qwen3.6-27B on GB10 (SM121).
|
| 3 |
+
|
| 4 |
+
Powers the attention Q/K/V/O projections and the dense FFN
|
| 5 |
+
(intermediate_size=17408, hidden=5120). Two precisions are supported:
|
| 6 |
+
|
| 7 |
+
- W4A16 (NVFP4 weight, BF16 activation): direct path
|
| 8 |
+
- FP8 W/A: via ``predequant_nvfp4_to_fp8`` + ``fp8_gemm_t`` for
|
| 9 |
+
KV-cache scenarios where the weight is loaded as NVFP4 but the
|
| 10 |
+
GEMM runs in FP8 against an FP8-packed activation.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import torch
|
| 14 |
+
|
| 15 |
+
from ._ops import ops
|
| 16 |
+
|
| 17 |
+
__all__ = [
|
| 18 |
+
"w4a16_gemm",
|
| 19 |
+
"w4a16_gemm_t",
|
| 20 |
+
"predequant_nvfp4_to_fp8",
|
| 21 |
+
"fp8_gemm_t",
|
| 22 |
+
"bf16_to_fp8",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def w4a16_gemm(
|
| 27 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 28 |
+
scale2: float, C: torch.Tensor,
|
| 29 |
+
) -> None:
|
| 30 |
+
"""C = A @ B^T where B is NVFP4. Standard layout."""
|
| 31 |
+
ops.w4a16_gemm(A, B_packed, B_scale, scale2, C)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def w4a16_gemm_t(
|
| 35 |
+
A: torch.Tensor, B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 36 |
+
scale2: float, C: torch.Tensor,
|
| 37 |
+
) -> None:
|
| 38 |
+
"""Transposed-B variant (N-major) — typically faster for [N>K] shapes."""
|
| 39 |
+
ops.w4a16_gemm_t(A, B_packed, B_scale, scale2, C)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def predequant_nvfp4_to_fp8(
|
| 43 |
+
B_packed: torch.Tensor, B_scale: torch.Tensor,
|
| 44 |
+
scale2: float, B_fp8_out: torch.Tensor,
|
| 45 |
+
) -> None:
|
| 46 |
+
"""Materialize an NVFP4-packed weight into a dense FP8 E4M3 tensor."""
|
| 47 |
+
ops.predequant_nvfp4_to_fp8(B_packed, B_scale, scale2, B_fp8_out)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def fp8_gemm_t(A: torch.Tensor, B_fp8: torch.Tensor, C: torch.Tensor) -> None:
|
| 51 |
+
"""C = A @ B^T where both A is BF16 and B is FP8 E4M3."""
|
| 52 |
+
ops.fp8_gemm_t(A, B_fp8, C)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def bf16_to_fp8(src: torch.Tensor, dst: torch.Tensor) -> None:
|
| 56 |
+
"""Pair-wise BF16 → FP8 E4M3 quantization (no scaling, uses PTX cvt)."""
|
| 57 |
+
ops.bf16_to_fp8(src, dst)
|
build/torch212-cxx11-cu132-aarch64-linux/_nvfp4_dense_gemm_cuda_bcba8ad.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:286187ea055712565459c5316a345e1f76fb4ef2027c98bdaf20a316cab1ab55
|
| 3 |
+
size 2505216
|
build/torch212-cxx11-cu132-aarch64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _nvfp4_dense_gemm_cuda_bcba8ad
|
| 3 |
+
ops = torch.ops._nvfp4_dense_gemm_cuda_bcba8ad
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_nvfp4_dense_gemm_cuda_bcba8ad::{op_name}"
|
build/torch212-cxx11-cu132-aarch64-linux/metadata.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "nvfp4-dense-gemm",
|
| 3 |
+
"id": "_nvfp4_dense_gemm_cuda_bcba8ad",
|
| 4 |
+
"version": 0,
|
| 5 |
+
"license": "AGPL-3.0-only",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda"
|
| 9 |
+
}
|
| 10 |
+
}
|
build/torch212-cxx11-cu132-aarch64-linux/nvfp4_dense_gemm/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|