liangsu9988 commited on
Commit
63ec7fb
·
verified ·
1 Parent(s): 2d478fd

Promote latest kernel artifacts to main

Browse files
.gitattributes CHANGED
@@ -1,35 +1,3 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.so filter=lfs diff=lfs merge=lfs -text
2
+ *.pyd filter=lfs diff=lfs merge=lfs -text
3
+ *.dylib filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md DELETED
@@ -1,9 +0,0 @@
1
- # flashrt/flashrt-fused-quant
2
-
3
- This repository is a compatibility mirror for older `kernels` clients
4
- that resolve repositories through the default Hugging Face model repo API.
5
-
6
- Canonical Kernel Hub repo: https://huggingface.co/kernels/flashrt/flashrt-fused-quant
7
-
8
- Do not edit this mirror by hand. It is generated from the Kernel Hub
9
- `vN` branches and contains the same `build/**` artifacts.
 
 
 
 
 
 
 
 
 
 
benchmarks/benchmark_silu_mul_quant_nvfp4.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from kernels.benchmark import Benchmark
4
+
5
+
6
+ SILU_QUANT_SHAPES = [
7
+ ("decode_r1_h4096", 1, 4096),
8
+ ("decode_r2_h4096", 2, 4096),
9
+ ("decode_r4_h4096", 4, 4096),
10
+ ("decode_r8_h4096", 8, 4096),
11
+ ("decode_r1_h8192", 1, 8192),
12
+ ("decode_r4_h8192", 4, 8192),
13
+ ("decode_r8_h8192", 8, 8192),
14
+ ("decode_r1_h12288", 1, 12288),
15
+ ("decode_r4_h12288", 4, 12288),
16
+ ("decode_r8_h12288", 8, 12288),
17
+ ("decode_r1_h16384", 1, 16384),
18
+ ("decode_r4_h16384", 4, 16384),
19
+ ("decode_r8_h16384", 8, 16384),
20
+ ("small_r16_h4096", 16, 4096),
21
+ ("small_r32_h4096", 32, 4096),
22
+ ("small_r16_h8192", 16, 8192),
23
+ ("small_r32_h8192", 32, 8192),
24
+ ("small_r16_h12288", 16, 12288),
25
+ ("small_r32_h12288", 32, 12288),
26
+ ("small_r16_h16384", 16, 16384),
27
+ ("small_r32_h16384", 32, 16384),
28
+ ("prefill_r64_h4096", 64, 4096),
29
+ ("prefill_r128_h4096", 128, 4096),
30
+ ("prefill_r256_h4096", 256, 4096),
31
+ ("video_r1024_h4096", 1024, 4096),
32
+ ("video_r2520_h4096", 2520, 4096),
33
+ ("prefill_r64_h8192", 64, 8192),
34
+ ("prefill_r128_h8192", 128, 8192),
35
+ ("prefill_r256_h8192", 256, 8192),
36
+ ("video_r1024_h8192", 1024, 8192),
37
+ ("video_r2520_h8192", 2520, 8192),
38
+ ("prefill_r64_h12288", 64, 12288),
39
+ ("prefill_r128_h12288", 128, 12288),
40
+ ("prefill_r256_h12288", 256, 12288),
41
+ ("video_r1024_h12288", 1024, 12288),
42
+ ("video_r2520_h12288", 2520, 12288),
43
+ ]
44
+
45
+
46
+ def _scale_bytes(rows: int, cols: int) -> int:
47
+ n_blocks = cols // 16
48
+ return ((rows + 127) // 128) * ((n_blocks + 3) // 4) * 512
49
+
50
+
51
+ class SiluMulNvfp4SplitBenchmark(Benchmark):
52
+ seed = 17
53
+
54
+ def _setup_shape(self, rows: int, cols: int) -> None:
55
+ self.gate = torch.randn(
56
+ (rows, cols), device=self.device, dtype=torch.bfloat16
57
+ ).contiguous()
58
+ self.up = torch.randn(
59
+ (rows, cols), device=self.device, dtype=torch.bfloat16
60
+ ).contiguous()
61
+ self.packed = torch.empty(
62
+ (rows, cols // 2), device=self.device, dtype=torch.uint8
63
+ )
64
+ self.scales = torch.zeros(
65
+ (_scale_bytes(rows, cols),), device=self.device, dtype=torch.uint8
66
+ )
67
+ self.out = self.packed
68
+
69
+ def _benchmark(self) -> None:
70
+ self.kernel.silu_mul_quant_nvfp4_swizzled_bf16(
71
+ self.gate,
72
+ self.up,
73
+ packed=self.packed,
74
+ scales=self.scales,
75
+ )
76
+
77
+
78
+ class SiluMulNvfp4MergedBenchmark(Benchmark):
79
+ seed = 19
80
+
81
+ def _setup_shape(self, rows: int, cols: int) -> None:
82
+ gate = torch.randn(
83
+ (rows, cols), device=self.device, dtype=torch.bfloat16
84
+ ).contiguous()
85
+ up = torch.randn((rows, cols), device=self.device, dtype=torch.bfloat16)
86
+ self.merged = torch.cat([gate, up], dim=1).contiguous()
87
+ self.packed = torch.empty(
88
+ (rows, cols // 2), device=self.device, dtype=torch.uint8
89
+ )
90
+ self.scales = torch.zeros(
91
+ (_scale_bytes(rows, cols),), device=self.device, dtype=torch.uint8
92
+ )
93
+ self.out = self.packed
94
+
95
+ def _benchmark(self) -> None:
96
+ self.kernel.silu_mul_merged_quant_nvfp4_swizzled_bf16(
97
+ self.merged,
98
+ packed=self.packed,
99
+ scales=self.scales,
100
+ )
101
+
102
+
103
+ def _register_shapes() -> None:
104
+ for label, rows, cols in SILU_QUANT_SHAPES:
105
+
106
+ def setup_split(self, rows=rows, cols=cols) -> None:
107
+ self._setup_shape(rows, cols)
108
+
109
+ def benchmark_split(self) -> None:
110
+ self._benchmark()
111
+
112
+ setattr(SiluMulNvfp4SplitBenchmark, f"setup_{label}", setup_split)
113
+ setattr(SiluMulNvfp4SplitBenchmark, f"benchmark_{label}", benchmark_split)
114
+
115
+ def setup_merged(self, rows=rows, cols=cols) -> None:
116
+ self._setup_shape(rows, cols)
117
+
118
+ def benchmark_merged(self) -> None:
119
+ self._benchmark()
120
+
121
+ setattr(SiluMulNvfp4MergedBenchmark, f"setup_{label}", setup_merged)
122
+ setattr(SiluMulNvfp4MergedBenchmark, f"benchmark_{label}", benchmark_merged)
123
+
124
+
125
+ _register_shapes()
build/torch211-cxx11-cu128-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT fused activation and quantization kernels."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ import torch
8
+
9
+ from ._ops import add_op_namespace_prefix, ops
10
+
11
+
12
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_quant_nvfp4_swizzled_bf16"))
13
+ def _silu_mul_quant_nvfp4_swizzled_bf16_fake(
14
+ gate: torch.Tensor,
15
+ up: torch.Tensor,
16
+ packed: torch.Tensor,
17
+ scales: torch.Tensor,
18
+ ) -> None:
19
+ if packed.shape != (gate.shape[0], gate.shape[1] // 2):
20
+ raise RuntimeError("packed shape must be (rows, cols / 2)")
21
+ return None
22
+
23
+
24
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_merged_quant_nvfp4_swizzled_bf16"))
25
+ def _silu_mul_merged_quant_nvfp4_swizzled_bf16_fake(
26
+ merged_gate_up: torch.Tensor,
27
+ packed: torch.Tensor,
28
+ scales: torch.Tensor,
29
+ ) -> None:
30
+ rows, merged_cols = merged_gate_up.shape
31
+ if packed.shape != (rows, merged_cols // 4):
32
+ raise RuntimeError("packed shape must be (rows, merged_cols / 4)")
33
+ return None
34
+
35
+
36
+ def nvfp4_swizzled_scale_bytes(rows: int, cols: int) -> int:
37
+ """Return byte count for a CUTLASS Sm1xx NVFP4 swizzled scale buffer."""
38
+
39
+ if rows <= 0:
40
+ raise ValueError("rows must be positive")
41
+ if cols <= 0 or cols % 16 != 0:
42
+ raise ValueError("cols must be positive and divisible by 16")
43
+ n_blocks = cols // 16
44
+ return ((rows + 127) // 128) * ((n_blocks + 3) // 4) * 512
45
+
46
+
47
+ def _allocate_outputs(
48
+ rows: int,
49
+ cols: int,
50
+ device: torch.device,
51
+ packed: Optional[torch.Tensor],
52
+ scales: Optional[torch.Tensor],
53
+ ) -> tuple[torch.Tensor, torch.Tensor]:
54
+ if packed is None:
55
+ packed = torch.empty((rows, cols // 2), device=device, dtype=torch.uint8)
56
+ if scales is None:
57
+ scales = torch.zeros(
58
+ (nvfp4_swizzled_scale_bytes(rows, cols),),
59
+ device=device,
60
+ dtype=torch.uint8,
61
+ )
62
+ return packed, scales
63
+
64
+
65
+ def silu_mul_quant_nvfp4_swizzled_bf16(
66
+ gate: torch.Tensor,
67
+ up: torch.Tensor,
68
+ *,
69
+ packed: Optional[torch.Tensor] = None,
70
+ scales: Optional[torch.Tensor] = None,
71
+ ) -> tuple[torch.Tensor, torch.Tensor]:
72
+ """Compute ``SiLU(gate) * up`` and quantize to NVFP4 swizzled layout.
73
+
74
+ ``gate`` and ``up`` must be contiguous BF16 tensors with shape
75
+ ``(rows, cols)``. ``cols`` must be divisible by 16. The returned ``packed``
76
+ tensor has shape ``(rows, cols / 2)`` and dtype ``torch.uint8``. The
77
+ returned ``scales`` tensor is a flat CUTLASS Sm1xx swizzled UE4M3
78
+ scale-factor byte buffer.
79
+ """
80
+
81
+ if gate.dim() != 2:
82
+ raise ValueError("gate must have shape (rows, cols)")
83
+ rows, cols = gate.shape
84
+ packed, scales = _allocate_outputs(rows, cols, gate.device, packed, scales)
85
+ ops.silu_mul_quant_nvfp4_swizzled_bf16(gate, up, packed, scales)
86
+ return packed, scales
87
+
88
+
89
+ def silu_mul_merged_quant_nvfp4_swizzled_bf16(
90
+ merged_gate_up: torch.Tensor,
91
+ *,
92
+ packed: Optional[torch.Tensor] = None,
93
+ scales: Optional[torch.Tensor] = None,
94
+ ) -> tuple[torch.Tensor, torch.Tensor]:
95
+ """Compute merged ``[gate | up]`` SiLU product and NVFP4 quantization.
96
+
97
+ ``merged_gate_up`` must be contiguous BF16 with shape ``(rows, 2 * cols)``
98
+ and row layout ``[gate | up]``.
99
+ """
100
+
101
+ if merged_gate_up.dim() != 2:
102
+ raise ValueError("merged_gate_up must have shape (rows, 2 * cols)")
103
+ rows, merged_cols = merged_gate_up.shape
104
+ if merged_cols % 2 != 0:
105
+ raise ValueError("merged_gate_up.shape[1] must be even")
106
+ cols = merged_cols // 2
107
+ packed, scales = _allocate_outputs(
108
+ rows, cols, merged_gate_up.device, packed, scales
109
+ )
110
+ ops.silu_mul_merged_quant_nvfp4_swizzled_bf16(
111
+ merged_gate_up,
112
+ packed,
113
+ scales,
114
+ )
115
+ return packed, scales
116
+
117
+
118
+ __all__ = [
119
+ "nvfp4_swizzled_scale_bytes",
120
+ "silu_mul_quant_nvfp4_swizzled_bf16",
121
+ "silu_mul_merged_quant_nvfp4_swizzled_bf16",
122
+ ]
build/torch211-cxx11-cu128-x86_64-linux/_flashrt_fused_quant_cuda_c4d802d.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67c419be13dcb2be2ab262886bc60fc9008864a1e200a4bcfa04a9c51d40e363
3
+ size 171912
build/torch211-cxx11-cu128-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _flashrt_fused_quant_cuda_c4d802d
3
+ ops = torch.ops._flashrt_fused_quant_cuda_c4d802d
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_flashrt_fused_quant_cuda_c4d802d::{op_name}"
build/torch211-cxx11-cu128-x86_64-linux/flashrt_fused_quant/__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-cu128-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "flashrt-fused-quant",
3
+ "id": "_flashrt_fused_quant_cuda_c4d802d",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "12.0"
11
+ ]
12
+ }
13
+ }
build/torch211-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT fused activation and quantization kernels."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ import torch
8
+
9
+ from ._ops import add_op_namespace_prefix, ops
10
+
11
+
12
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_quant_nvfp4_swizzled_bf16"))
13
+ def _silu_mul_quant_nvfp4_swizzled_bf16_fake(
14
+ gate: torch.Tensor,
15
+ up: torch.Tensor,
16
+ packed: torch.Tensor,
17
+ scales: torch.Tensor,
18
+ ) -> None:
19
+ if packed.shape != (gate.shape[0], gate.shape[1] // 2):
20
+ raise RuntimeError("packed shape must be (rows, cols / 2)")
21
+ return None
22
+
23
+
24
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_merged_quant_nvfp4_swizzled_bf16"))
25
+ def _silu_mul_merged_quant_nvfp4_swizzled_bf16_fake(
26
+ merged_gate_up: torch.Tensor,
27
+ packed: torch.Tensor,
28
+ scales: torch.Tensor,
29
+ ) -> None:
30
+ rows, merged_cols = merged_gate_up.shape
31
+ if packed.shape != (rows, merged_cols // 4):
32
+ raise RuntimeError("packed shape must be (rows, merged_cols / 4)")
33
+ return None
34
+
35
+
36
+ def nvfp4_swizzled_scale_bytes(rows: int, cols: int) -> int:
37
+ """Return byte count for a CUTLASS Sm1xx NVFP4 swizzled scale buffer."""
38
+
39
+ if rows <= 0:
40
+ raise ValueError("rows must be positive")
41
+ if cols <= 0 or cols % 16 != 0:
42
+ raise ValueError("cols must be positive and divisible by 16")
43
+ n_blocks = cols // 16
44
+ return ((rows + 127) // 128) * ((n_blocks + 3) // 4) * 512
45
+
46
+
47
+ def _allocate_outputs(
48
+ rows: int,
49
+ cols: int,
50
+ device: torch.device,
51
+ packed: Optional[torch.Tensor],
52
+ scales: Optional[torch.Tensor],
53
+ ) -> tuple[torch.Tensor, torch.Tensor]:
54
+ if packed is None:
55
+ packed = torch.empty((rows, cols // 2), device=device, dtype=torch.uint8)
56
+ if scales is None:
57
+ scales = torch.zeros(
58
+ (nvfp4_swizzled_scale_bytes(rows, cols),),
59
+ device=device,
60
+ dtype=torch.uint8,
61
+ )
62
+ return packed, scales
63
+
64
+
65
+ def silu_mul_quant_nvfp4_swizzled_bf16(
66
+ gate: torch.Tensor,
67
+ up: torch.Tensor,
68
+ *,
69
+ packed: Optional[torch.Tensor] = None,
70
+ scales: Optional[torch.Tensor] = None,
71
+ ) -> tuple[torch.Tensor, torch.Tensor]:
72
+ """Compute ``SiLU(gate) * up`` and quantize to NVFP4 swizzled layout.
73
+
74
+ ``gate`` and ``up`` must be contiguous BF16 tensors with shape
75
+ ``(rows, cols)``. ``cols`` must be divisible by 16. The returned ``packed``
76
+ tensor has shape ``(rows, cols / 2)`` and dtype ``torch.uint8``. The
77
+ returned ``scales`` tensor is a flat CUTLASS Sm1xx swizzled UE4M3
78
+ scale-factor byte buffer.
79
+ """
80
+
81
+ if gate.dim() != 2:
82
+ raise ValueError("gate must have shape (rows, cols)")
83
+ rows, cols = gate.shape
84
+ packed, scales = _allocate_outputs(rows, cols, gate.device, packed, scales)
85
+ ops.silu_mul_quant_nvfp4_swizzled_bf16(gate, up, packed, scales)
86
+ return packed, scales
87
+
88
+
89
+ def silu_mul_merged_quant_nvfp4_swizzled_bf16(
90
+ merged_gate_up: torch.Tensor,
91
+ *,
92
+ packed: Optional[torch.Tensor] = None,
93
+ scales: Optional[torch.Tensor] = None,
94
+ ) -> tuple[torch.Tensor, torch.Tensor]:
95
+ """Compute merged ``[gate | up]`` SiLU product and NVFP4 quantization.
96
+
97
+ ``merged_gate_up`` must be contiguous BF16 with shape ``(rows, 2 * cols)``
98
+ and row layout ``[gate | up]``.
99
+ """
100
+
101
+ if merged_gate_up.dim() != 2:
102
+ raise ValueError("merged_gate_up must have shape (rows, 2 * cols)")
103
+ rows, merged_cols = merged_gate_up.shape
104
+ if merged_cols % 2 != 0:
105
+ raise ValueError("merged_gate_up.shape[1] must be even")
106
+ cols = merged_cols // 2
107
+ packed, scales = _allocate_outputs(
108
+ rows, cols, merged_gate_up.device, packed, scales
109
+ )
110
+ ops.silu_mul_merged_quant_nvfp4_swizzled_bf16(
111
+ merged_gate_up,
112
+ packed,
113
+ scales,
114
+ )
115
+ return packed, scales
116
+
117
+
118
+ __all__ = [
119
+ "nvfp4_swizzled_scale_bytes",
120
+ "silu_mul_quant_nvfp4_swizzled_bf16",
121
+ "silu_mul_merged_quant_nvfp4_swizzled_bf16",
122
+ ]
build/torch211-cxx11-cu130-x86_64-linux/_flashrt_fused_quant_cuda_c4d802d.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d766f8d7c97a42c60a5c92680c03f5b21c1d2d73b8df02629f493fdd1dcee1b
3
+ size 176568
build/torch211-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _flashrt_fused_quant_cuda_c4d802d
3
+ ops = torch.ops._flashrt_fused_quant_cuda_c4d802d
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_flashrt_fused_quant_cuda_c4d802d::{op_name}"
build/torch211-cxx11-cu130-x86_64-linux/flashrt_fused_quant/__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-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "flashrt-fused-quant",
3
+ "id": "_flashrt_fused_quant_cuda_c4d802d",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "12.0"
11
+ ]
12
+ }
13
+ }
build/torch212-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT fused activation and quantization kernels."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ import torch
8
+
9
+ from ._ops import add_op_namespace_prefix, ops
10
+
11
+
12
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_quant_nvfp4_swizzled_bf16"))
13
+ def _silu_mul_quant_nvfp4_swizzled_bf16_fake(
14
+ gate: torch.Tensor,
15
+ up: torch.Tensor,
16
+ packed: torch.Tensor,
17
+ scales: torch.Tensor,
18
+ ) -> None:
19
+ if packed.shape != (gate.shape[0], gate.shape[1] // 2):
20
+ raise RuntimeError("packed shape must be (rows, cols / 2)")
21
+ return None
22
+
23
+
24
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_merged_quant_nvfp4_swizzled_bf16"))
25
+ def _silu_mul_merged_quant_nvfp4_swizzled_bf16_fake(
26
+ merged_gate_up: torch.Tensor,
27
+ packed: torch.Tensor,
28
+ scales: torch.Tensor,
29
+ ) -> None:
30
+ rows, merged_cols = merged_gate_up.shape
31
+ if packed.shape != (rows, merged_cols // 4):
32
+ raise RuntimeError("packed shape must be (rows, merged_cols / 4)")
33
+ return None
34
+
35
+
36
+ def nvfp4_swizzled_scale_bytes(rows: int, cols: int) -> int:
37
+ """Return byte count for a CUTLASS Sm1xx NVFP4 swizzled scale buffer."""
38
+
39
+ if rows <= 0:
40
+ raise ValueError("rows must be positive")
41
+ if cols <= 0 or cols % 16 != 0:
42
+ raise ValueError("cols must be positive and divisible by 16")
43
+ n_blocks = cols // 16
44
+ return ((rows + 127) // 128) * ((n_blocks + 3) // 4) * 512
45
+
46
+
47
+ def _allocate_outputs(
48
+ rows: int,
49
+ cols: int,
50
+ device: torch.device,
51
+ packed: Optional[torch.Tensor],
52
+ scales: Optional[torch.Tensor],
53
+ ) -> tuple[torch.Tensor, torch.Tensor]:
54
+ if packed is None:
55
+ packed = torch.empty((rows, cols // 2), device=device, dtype=torch.uint8)
56
+ if scales is None:
57
+ scales = torch.zeros(
58
+ (nvfp4_swizzled_scale_bytes(rows, cols),),
59
+ device=device,
60
+ dtype=torch.uint8,
61
+ )
62
+ return packed, scales
63
+
64
+
65
+ def silu_mul_quant_nvfp4_swizzled_bf16(
66
+ gate: torch.Tensor,
67
+ up: torch.Tensor,
68
+ *,
69
+ packed: Optional[torch.Tensor] = None,
70
+ scales: Optional[torch.Tensor] = None,
71
+ ) -> tuple[torch.Tensor, torch.Tensor]:
72
+ """Compute ``SiLU(gate) * up`` and quantize to NVFP4 swizzled layout.
73
+
74
+ ``gate`` and ``up`` must be contiguous BF16 tensors with shape
75
+ ``(rows, cols)``. ``cols`` must be divisible by 16. The returned ``packed``
76
+ tensor has shape ``(rows, cols / 2)`` and dtype ``torch.uint8``. The
77
+ returned ``scales`` tensor is a flat CUTLASS Sm1xx swizzled UE4M3
78
+ scale-factor byte buffer.
79
+ """
80
+
81
+ if gate.dim() != 2:
82
+ raise ValueError("gate must have shape (rows, cols)")
83
+ rows, cols = gate.shape
84
+ packed, scales = _allocate_outputs(rows, cols, gate.device, packed, scales)
85
+ ops.silu_mul_quant_nvfp4_swizzled_bf16(gate, up, packed, scales)
86
+ return packed, scales
87
+
88
+
89
+ def silu_mul_merged_quant_nvfp4_swizzled_bf16(
90
+ merged_gate_up: torch.Tensor,
91
+ *,
92
+ packed: Optional[torch.Tensor] = None,
93
+ scales: Optional[torch.Tensor] = None,
94
+ ) -> tuple[torch.Tensor, torch.Tensor]:
95
+ """Compute merged ``[gate | up]`` SiLU product and NVFP4 quantization.
96
+
97
+ ``merged_gate_up`` must be contiguous BF16 with shape ``(rows, 2 * cols)``
98
+ and row layout ``[gate | up]``.
99
+ """
100
+
101
+ if merged_gate_up.dim() != 2:
102
+ raise ValueError("merged_gate_up must have shape (rows, 2 * cols)")
103
+ rows, merged_cols = merged_gate_up.shape
104
+ if merged_cols % 2 != 0:
105
+ raise ValueError("merged_gate_up.shape[1] must be even")
106
+ cols = merged_cols // 2
107
+ packed, scales = _allocate_outputs(
108
+ rows, cols, merged_gate_up.device, packed, scales
109
+ )
110
+ ops.silu_mul_merged_quant_nvfp4_swizzled_bf16(
111
+ merged_gate_up,
112
+ packed,
113
+ scales,
114
+ )
115
+ return packed, scales
116
+
117
+
118
+ __all__ = [
119
+ "nvfp4_swizzled_scale_bytes",
120
+ "silu_mul_quant_nvfp4_swizzled_bf16",
121
+ "silu_mul_merged_quant_nvfp4_swizzled_bf16",
122
+ ]
build/torch212-cxx11-cu130-x86_64-linux/_flashrt_fused_quant_cuda_c4d802d.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df5e3115af67a95306487c04b1acc8b85b8a59bfdf5759b93349c9e2a291bf37
3
+ size 182504
build/torch212-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _flashrt_fused_quant_cuda_c4d802d
3
+ ops = torch.ops._flashrt_fused_quant_cuda_c4d802d
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_flashrt_fused_quant_cuda_c4d802d::{op_name}"
build/torch212-cxx11-cu130-x86_64-linux/flashrt_fused_quant/__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-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "flashrt-fused-quant",
3
+ "id": "_flashrt_fused_quant_cuda_c4d802d",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "12.0"
11
+ ]
12
+ }
13
+ }
build/torch212-cxx11-cu132-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT fused activation and quantization kernels."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ import torch
8
+
9
+ from ._ops import add_op_namespace_prefix, ops
10
+
11
+
12
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_quant_nvfp4_swizzled_bf16"))
13
+ def _silu_mul_quant_nvfp4_swizzled_bf16_fake(
14
+ gate: torch.Tensor,
15
+ up: torch.Tensor,
16
+ packed: torch.Tensor,
17
+ scales: torch.Tensor,
18
+ ) -> None:
19
+ if packed.shape != (gate.shape[0], gate.shape[1] // 2):
20
+ raise RuntimeError("packed shape must be (rows, cols / 2)")
21
+ return None
22
+
23
+
24
+ @torch.library.register_fake(add_op_namespace_prefix("silu_mul_merged_quant_nvfp4_swizzled_bf16"))
25
+ def _silu_mul_merged_quant_nvfp4_swizzled_bf16_fake(
26
+ merged_gate_up: torch.Tensor,
27
+ packed: torch.Tensor,
28
+ scales: torch.Tensor,
29
+ ) -> None:
30
+ rows, merged_cols = merged_gate_up.shape
31
+ if packed.shape != (rows, merged_cols // 4):
32
+ raise RuntimeError("packed shape must be (rows, merged_cols / 4)")
33
+ return None
34
+
35
+
36
+ def nvfp4_swizzled_scale_bytes(rows: int, cols: int) -> int:
37
+ """Return byte count for a CUTLASS Sm1xx NVFP4 swizzled scale buffer."""
38
+
39
+ if rows <= 0:
40
+ raise ValueError("rows must be positive")
41
+ if cols <= 0 or cols % 16 != 0:
42
+ raise ValueError("cols must be positive and divisible by 16")
43
+ n_blocks = cols // 16
44
+ return ((rows + 127) // 128) * ((n_blocks + 3) // 4) * 512
45
+
46
+
47
+ def _allocate_outputs(
48
+ rows: int,
49
+ cols: int,
50
+ device: torch.device,
51
+ packed: Optional[torch.Tensor],
52
+ scales: Optional[torch.Tensor],
53
+ ) -> tuple[torch.Tensor, torch.Tensor]:
54
+ if packed is None:
55
+ packed = torch.empty((rows, cols // 2), device=device, dtype=torch.uint8)
56
+ if scales is None:
57
+ scales = torch.zeros(
58
+ (nvfp4_swizzled_scale_bytes(rows, cols),),
59
+ device=device,
60
+ dtype=torch.uint8,
61
+ )
62
+ return packed, scales
63
+
64
+
65
+ def silu_mul_quant_nvfp4_swizzled_bf16(
66
+ gate: torch.Tensor,
67
+ up: torch.Tensor,
68
+ *,
69
+ packed: Optional[torch.Tensor] = None,
70
+ scales: Optional[torch.Tensor] = None,
71
+ ) -> tuple[torch.Tensor, torch.Tensor]:
72
+ """Compute ``SiLU(gate) * up`` and quantize to NVFP4 swizzled layout.
73
+
74
+ ``gate`` and ``up`` must be contiguous BF16 tensors with shape
75
+ ``(rows, cols)``. ``cols`` must be divisible by 16. The returned ``packed``
76
+ tensor has shape ``(rows, cols / 2)`` and dtype ``torch.uint8``. The
77
+ returned ``scales`` tensor is a flat CUTLASS Sm1xx swizzled UE4M3
78
+ scale-factor byte buffer.
79
+ """
80
+
81
+ if gate.dim() != 2:
82
+ raise ValueError("gate must have shape (rows, cols)")
83
+ rows, cols = gate.shape
84
+ packed, scales = _allocate_outputs(rows, cols, gate.device, packed, scales)
85
+ ops.silu_mul_quant_nvfp4_swizzled_bf16(gate, up, packed, scales)
86
+ return packed, scales
87
+
88
+
89
+ def silu_mul_merged_quant_nvfp4_swizzled_bf16(
90
+ merged_gate_up: torch.Tensor,
91
+ *,
92
+ packed: Optional[torch.Tensor] = None,
93
+ scales: Optional[torch.Tensor] = None,
94
+ ) -> tuple[torch.Tensor, torch.Tensor]:
95
+ """Compute merged ``[gate | up]`` SiLU product and NVFP4 quantization.
96
+
97
+ ``merged_gate_up`` must be contiguous BF16 with shape ``(rows, 2 * cols)``
98
+ and row layout ``[gate | up]``.
99
+ """
100
+
101
+ if merged_gate_up.dim() != 2:
102
+ raise ValueError("merged_gate_up must have shape (rows, 2 * cols)")
103
+ rows, merged_cols = merged_gate_up.shape
104
+ if merged_cols % 2 != 0:
105
+ raise ValueError("merged_gate_up.shape[1] must be even")
106
+ cols = merged_cols // 2
107
+ packed, scales = _allocate_outputs(
108
+ rows, cols, merged_gate_up.device, packed, scales
109
+ )
110
+ ops.silu_mul_merged_quant_nvfp4_swizzled_bf16(
111
+ merged_gate_up,
112
+ packed,
113
+ scales,
114
+ )
115
+ return packed, scales
116
+
117
+
118
+ __all__ = [
119
+ "nvfp4_swizzled_scale_bytes",
120
+ "silu_mul_quant_nvfp4_swizzled_bf16",
121
+ "silu_mul_merged_quant_nvfp4_swizzled_bf16",
122
+ ]
build/torch212-cxx11-cu132-x86_64-linux/_flashrt_fused_quant_cuda_c4d802d.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f601af5cea5587f32940bdba39e431bd504ae33c0aee613381d57d3e134adace
3
+ size 182504
build/torch212-cxx11-cu132-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _flashrt_fused_quant_cuda_c4d802d
3
+ ops = torch.ops._flashrt_fused_quant_cuda_c4d802d
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_flashrt_fused_quant_cuda_c4d802d::{op_name}"
build/torch212-cxx11-cu132-x86_64-linux/flashrt_fused_quant/__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-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "flashrt-fused-quant",
3
+ "id": "_flashrt_fused_quant_cuda_c4d802d",
4
+ "version": 1,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "12.0"
11
+ ]
12
+ }
13
+ }