liangsu9988 commited on
Commit
3535927
·
verified ·
1 Parent(s): cf45de9

Promote latest kernel artifacts to main

Browse files
README.md CHANGED
@@ -1,9 +1,116 @@
1
- # flashrt/fp4-gemm
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/fp4-gemm
 
 
 
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.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # fp4-gemm
2
 
3
+ FlashRT native Blackwell NVFP4 A4W4 GEMM kernels.
 
4
 
5
+ This package consumes packed FP4 E2M1 tensors plus CUTLASS Sm1xx SFA/SFB scale
6
+ buffers and produces BF16 output. It is designed to pair with
7
+ `flashrt/fp4-fused-ops` and other static low-bit transformer/diffuser runtime
8
+ paths.
9
 
10
+ ## Available Functions
11
+
12
+ - `sfa_size_bytes(rows, dim)`
13
+ - `quantize_fp4_sfa_fp16(x, packed=None, sfa=None, is_sfb=False)`
14
+ - `quantize_fp4_sfa_bf16(x, packed=None, sfa=None, is_sfb=False)`
15
+ - `dequantize_fp4_sfa_fp16(packed, sfa, out=None, is_sfb=False)`
16
+ - `nvfp4_gemm_bf16(a_packed, b_packed, sfa, sfb, alpha=1.0, out=None, variant=-1)`
17
+ - `nvfp4_gemm_bias_bf16(a_packed, b_packed, sfa, sfb, bias, out=None)`
18
+ - `nvfp4_gemm_bias_residual_bf16(a_packed, b_packed, sfa, sfb, bias, residual, out=None)`
19
+ - `nvfp4_gemm_residual_bf16(a_packed, b_packed, sfa, sfb, residual, alpha=1.0, out=None)`
20
+ - `nvfp4_gemm_bias_gelu_bf16(a_packed, b_packed, sfa, sfb, bias, alpha=1.0, out=None)`
21
+ - `nvfp4_gemm_bias_gelu_nvfp4(a_packed, b_packed, sfa, sfb, bias, alpha=1.0, out_packed=None, out_sfa=None)`
22
+ - `nvfp4_gemm_streamk_bf16(a_packed, b_packed, sfa, sfb, alpha=1.0, out=None)`
23
+ - `nvfp4_gemm_streamk_bias_bf16(a_packed, b_packed, sfa, sfb, bias, alpha=1.0, out=None)`
24
+ - `fp4_w4a16_linear_bf16(...)` is retained as a compatibility alias
25
+
26
+ ## Tensor Contract
27
+
28
+ - `a_packed`: `torch.uint8`, shape `(M, K / 2)`.
29
+ - `b_packed`: `torch.uint8`, shape `(N, K / 2)`.
30
+ - `sfa`: `torch.uint8`, CUTLASS SFA layout for `(M, K)`.
31
+ - `sfb`: `torch.uint8`, CUTLASS SFB layout for `(N, K)`.
32
+ - output: `torch.bfloat16`, shape `(M, N)`.
33
+ - `K` must be divisible by 16.
34
+ - Targets: Blackwell `sm_110a` (Jetson AGX Thor, CUDA 13+) and `sm_120a`
35
+ (RTX Blackwell, CUDA 12.8+).
36
+
37
+ `variant` selects the CUTLASS schedule:
38
+
39
+ - `-1`: architecture-aware auto-dispatch (public default).
40
+ - `0`: default `<128,128,256>` cooperative schedule.
41
+ - `1`: widen `<128,256,128>` schedule, intended for very large `N`.
42
+ - `2`: pingpong schedule for A/B testing shape-specific wins.
43
+
44
+ The canonical linear API and FP4/SFA quantize/dequantize helpers are available
45
+ on both SM110 and SM120. SM110 additionally provides the GROOT N1.7 production
46
+ epilogues `nvfp4_gemm_bias_bf16`, `nvfp4_gemm_bias_residual_bf16`, and
47
+ `nvfp4_gemm_bias_gelu_nvfp4`. The latter emits packed FP4 plus CUTLASS SFA so
48
+ the following projection can consume it without a BF16 materialization and a
49
+ standalone quantization launch. Stream-K and the older BF16 GELU epilogue keep
50
+ their existing SM120 dispatch and reject unsupported architectures explicitly.
51
+
52
+ The SM110 release gate includes the production `(M,N,K)` shapes
53
+ `(41,4608,1536)`, `(41,6144,1536)`, and `(41,1536,6144)`, plus the legacy
54
+ `M=51` compatibility row. The kernels are the native sources used by FlashRT's
55
+ GROOT N1.7 Thor NVFP4 pipeline.
56
+
57
+ ## Minimal Usage
58
+
59
+ ```python
60
+ from kernels import get_kernel
61
+ import torch
62
+
63
+ ops = get_kernel("flashrt/fp4-gemm", version=1, trust_remote_code=True)
64
+
65
+ x = torch.randn((32, 256), device="cuda", dtype=torch.float16)
66
+ w = torch.randn((512, 256), device="cuda", dtype=torch.float16)
67
+
68
+ a_packed, sfa = ops.quantize_fp4_sfa_fp16(x, is_sfb=False)
69
+ b_packed, sfb = ops.quantize_fp4_sfa_fp16(w, is_sfb=True)
70
+
71
+ y = ops.nvfp4_gemm_bf16(a_packed, b_packed, sfa, sfb, alpha=1.0)
72
+ ```
73
+
74
+ For BF16 model activations, use the direct producer so the hot path does not
75
+ materialize an intermediate FP16 tensor:
76
+
77
+ ```python
78
+ x_bf16 = torch.randn((1, 5120), device="cuda", dtype=torch.bfloat16)
79
+ a_packed, sfa = ops.quantize_fp4_sfa_bf16(x_bf16)
80
+ ```
81
+
82
+ The BF16 entry writes the same E2M1 bytes and CUTLASS SFA/SFB layout as
83
+ `quantize_fp4_sfa_fp16(x_bf16.to(torch.float16))` for finite FP16-range
84
+ inputs. It is an additive API; the existing FP16 producer remains unchanged.
85
+
86
+ The quantize/dequantize helpers are included for examples and validation. A
87
+ production runtime should keep weights prepacked and should avoid quantizing in
88
+ the hot path unless that producer kernel is part of the intended low-bit block.
89
+
90
+ Use the bias/GELU and residual variants to avoid returning to BF16
91
+ elementwise code between low-bit GEMMs. Stream-K variants are selected only
92
+ for the validated large down-projection shapes; unsupported shapes reject
93
+ rather than silently selecting a losing schedule.
94
+
95
+ ## Validation
96
+
97
+ ```bash
98
+ python fp4-gemm/tests/test_fp4_gemm.py --backend source --mode full
99
+ python fp4-gemm/tests/test_fp4_gemm.py --backend installed --mode full \
100
+ --artifact fp4-gemm/build/torch211-cxx11-cu128-x86_64-linux
101
+ python fp4-gemm/benchmarks/benchmark.py --backend installed --mode headline \
102
+ --artifact fp4-gemm/build/torch211-cxx11-cu128-x86_64-linux
103
+
104
+ # Thor model-shape gate
105
+ python fp4-gemm/tests/test_fp4_gemm.py --backend installed \
106
+ --mode thor-models \
107
+ --artifact fp4-gemm/build/torch211-cxx11-cu130-aarch64-linux
108
+ ```
109
+
110
+ The correctness reference dequantizes the same FP4/SFA and FP4/SFB inputs used
111
+ by the kernel, then computes the PyTorch GEMM reference from those dequantized
112
+ low-bit values.
113
+
114
+ The producer gate also checks the BF16 direct entry byte-for-byte against the
115
+ established FP16 compatibility chain at decode widths 5120, 6144 and 17408,
116
+ plus multi-row activation and SFB layouts.
benchmarks/RESULTS.md CHANGED
@@ -55,17 +55,3 @@ The direct entry is byte-exact against the package's established
55
  BF16-to-FP16 plus FP16-producer contract. The native timing is reported as a
56
  performance reference only because that producer uses a distinct quantization
57
  strategy.
58
-
59
- ## NVIDIA Thor GROOT N1.7 artifact
60
-
61
- The SM110 additions from FlashRT
62
- `24df793f4fa2d50780aea03b644208c6e0cb4162` were rebuilt on NVIDIA Thor with
63
- PyTorch 2.13.0+cu130 as `torch213-cxx11-cu130-aarch64-linux`. The installed
64
- artifact passed 23/23 checks; BF16-to-FP4 output was exact and the fullgraph
65
- compile path had `max_abs=0`.
66
-
67
- The FP4 quantizer Tensor wrapper/raw registered-op measurement was
68
- `5.5812/5.0712 us` in direct mode. This eager delta includes Python-side
69
- allocation and dispatch. With caller-owned buffers under CUDA Graph, the
70
- measurement was `3.2988/3.3003 us` (`0.9995x`), which is the production GROOT
71
- hot-path contract.
 
55
  BF16-to-FP16 plus FP16-producer contract. The native timing is reported as a
56
  performance reference only because that producer uses a distinct quantization
57
  strategy.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/torch212-cxx11-cu130-x86_64-linux/__init__.py CHANGED
@@ -19,7 +19,8 @@ def sfa_size_bytes(rows: int, dim: int) -> int:
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
- torch.empty((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
 
23
  )
24
 
25
 
@@ -36,6 +37,26 @@ def _linear_fake(
36
  return None
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
40
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
41
  if a_packed.shape[0] != 1:
@@ -162,6 +183,100 @@ def nvfp4_gemm_bf16(
162
  return out
163
 
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def fp4_w4a4_gemv_warpsplit_bf16(
166
  a_packed: torch.Tensor,
167
  b_packed: torch.Tensor,
@@ -292,7 +407,7 @@ def nvfp4_gemm_bias_gelu_nvfp4(
292
  if out_packed is None:
293
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
294
  if out_sfa is None:
295
- out_sfa = torch.empty((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
296
  ops.nvfp4_gemm_bias_gelu_nvfp4(
297
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
298
  )
@@ -345,6 +460,10 @@ __all__ = [
345
  "fp4_w4a16_linear_bf16",
346
  "fp4_w4a4_gemv_warpsplit_bf16",
347
  "nvfp4_gemm_bf16",
 
 
 
 
348
  "nvfp4_gemm_bias_bf16",
349
  "nvfp4_gemm_bias_gelu_bf16",
350
  "nvfp4_gemm_bias_gelu_nvfp4",
 
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
+ # Tile-layout padding entries are not written by every quantizer.
23
+ torch.zeros((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
24
  )
25
 
26
 
 
37
  return None
38
 
39
 
40
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_fp16"))
41
+ def _linear_fp16_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, variant: int = -1) -> None:
42
+ return None
43
+
44
+
45
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_geglu_nvfp4_fp16"))
46
+ def _geglu_fp4_fake(a, b, sfa, sfb, scratch, out_packed, out_sfa, skinny: bool = False) -> None:
47
+ return None
48
+
49
+
50
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_gelu_nvfp4_fp16"))
51
+ def _bias_gelu_fp4_fp16_fake(a, b, sfa, sfb, bias, out_packed, out_sfa) -> None:
52
+ return None
53
+
54
+
55
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_residual_fp16"))
56
+ def _bias_residual_fp16_fake(a, b, sfa, sfb, bias, residual, out) -> None:
57
+ return None
58
+
59
+
60
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
61
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
62
  if a_packed.shape[0] != 1:
 
183
  return out
184
 
185
 
186
+ def nvfp4_gemm_fp16(
187
+ a_packed: torch.Tensor,
188
+ b_packed: torch.Tensor,
189
+ sfa: torch.Tensor,
190
+ sfb: torch.Tensor,
191
+ alpha: float = 1.0,
192
+ out: torch.Tensor | None = None,
193
+ variant: int = -1,
194
+ ) -> torch.Tensor:
195
+ """SM110 native NVFP4 GEMM with FP16 output."""
196
+ if out is None:
197
+ out = torch.empty(
198
+ (a_packed.shape[0], b_packed.shape[0]),
199
+ device=a_packed.device,
200
+ dtype=torch.float16,
201
+ )
202
+ ops.nvfp4_gemm_fp16(
203
+ a_packed, b_packed, sfa, sfb, out, float(alpha), int(variant)
204
+ )
205
+ return out
206
+
207
+
208
+ def nvfp4_gemm_geglu_nvfp4_fp16(
209
+ a_packed: torch.Tensor,
210
+ b_interleaved_packed: torch.Tensor,
211
+ sfa: torch.Tensor,
212
+ sfb: torch.Tensor,
213
+ *,
214
+ skinny: bool = False,
215
+ scratch: torch.Tensor | None = None,
216
+ out_packed: torch.Tensor | None = None,
217
+ out_sfa: torch.Tensor | None = None,
218
+ ) -> tuple[torch.Tensor, torch.Tensor]:
219
+ """GEMM with fused GeGLU and compact NVFP4 output on SM110.
220
+
221
+ ``b_interleaved_packed`` stores gate/up rows pairwise, so its first
222
+ dimension is twice the logical hidden width.
223
+ """
224
+ m, n_twice = a_packed.shape[0], b_interleaved_packed.shape[0]
225
+ hidden = n_twice // 2
226
+ if scratch is None:
227
+ scratch = torch.empty((m, hidden), device=a_packed.device, dtype=torch.uint8)
228
+ if out_packed is None:
229
+ out_packed = torch.empty((m, hidden // 2), device=a_packed.device, dtype=torch.uint8)
230
+ if out_sfa is None:
231
+ out_sfa = torch.zeros((sfa_size_bytes(m, hidden),), device=a_packed.device, dtype=torch.uint8)
232
+ ops.nvfp4_gemm_geglu_nvfp4_fp16(
233
+ a_packed, b_interleaved_packed, sfa, sfb, scratch,
234
+ out_packed, out_sfa, bool(skinny)
235
+ )
236
+ return out_packed, out_sfa
237
+
238
+
239
+ def nvfp4_gemm_bias_gelu_nvfp4_fp16(
240
+ a_packed: torch.Tensor,
241
+ b_packed: torch.Tensor,
242
+ sfa: torch.Tensor,
243
+ sfb: torch.Tensor,
244
+ bias: torch.Tensor,
245
+ *,
246
+ out_packed: torch.Tensor | None = None,
247
+ out_sfa: torch.Tensor | None = None,
248
+ ) -> tuple[torch.Tensor, torch.Tensor]:
249
+ """FP16-bias GEMM with fused GELU and NVFP4 output on SM110."""
250
+ m, n = a_packed.shape[0], b_packed.shape[0]
251
+ if out_packed is None:
252
+ out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
253
+ if out_sfa is None:
254
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
255
+ ops.nvfp4_gemm_bias_gelu_nvfp4_fp16(
256
+ a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa
257
+ )
258
+ return out_packed, out_sfa
259
+
260
+
261
+ def nvfp4_gemm_bias_residual_fp16(
262
+ a_packed: torch.Tensor,
263
+ b_packed: torch.Tensor,
264
+ sfa: torch.Tensor,
265
+ sfb: torch.Tensor,
266
+ bias: torch.Tensor,
267
+ residual: torch.Tensor,
268
+ *,
269
+ out: torch.Tensor | None = None,
270
+ ) -> torch.Tensor:
271
+ """FP16-output GEMM with fused FP16 bias and residual on SM110."""
272
+ if out is None:
273
+ out = torch.empty_like(residual)
274
+ ops.nvfp4_gemm_bias_residual_fp16(
275
+ a_packed, b_packed, sfa, sfb, bias, residual, out
276
+ )
277
+ return out
278
+
279
+
280
  def fp4_w4a4_gemv_warpsplit_bf16(
281
  a_packed: torch.Tensor,
282
  b_packed: torch.Tensor,
 
407
  if out_packed is None:
408
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
409
  if out_sfa is None:
410
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
411
  ops.nvfp4_gemm_bias_gelu_nvfp4(
412
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
413
  )
 
460
  "fp4_w4a16_linear_bf16",
461
  "fp4_w4a4_gemv_warpsplit_bf16",
462
  "nvfp4_gemm_bf16",
463
+ "nvfp4_gemm_fp16",
464
+ "nvfp4_gemm_geglu_nvfp4_fp16",
465
+ "nvfp4_gemm_bias_gelu_nvfp4_fp16",
466
+ "nvfp4_gemm_bias_residual_fp16",
467
  "nvfp4_gemm_bias_bf16",
468
  "nvfp4_gemm_bias_gelu_bf16",
469
  "nvfp4_gemm_bias_gelu_nvfp4",
build/torch212-cxx11-cu130-x86_64-linux/{_fp4_gemm_cuda_8a66d8b.abi3.so → _fp4_gemm_cuda_55c4885.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:26fce4c1404d996b8e9ab774125c787e47a568f79da35f734949bff0177a173a
3
- size 2848128
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c55a4f6233f699e6d2e69205e0f4c5e7753d0dc216129bf75e4477d675daee8e
3
+ size 6350504
build/torch212-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _fp4_gemm_cuda_8a66d8b
3
- ops = torch.ops._fp4_gemm_cuda_8a66d8b
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_fp4_gemm_cuda_8a66d8b::{op_name}"
 
1
  import torch
2
+ from . import _fp4_gemm_cuda_55c4885
3
+ ops = torch.ops._fp4_gemm_cuda_55c4885
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_fp4_gemm_cuda_55c4885::{op_name}"
build/torch212-cxx11-cu130-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "fp4-gemm",
3
- "id": "_fp4_gemm_cuda_8a66d8b",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
@@ -14,19 +14,19 @@
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
- "__init__.py": "+Kk/VNnIWwe9nszQYvL2qtU3DpKxbqHVfklg5WtVuB4=",
18
- "_fp4_gemm_cuda_8a66d8b.abi3.so": "JvzkwUBNmWuOmrd0Elx4fkelaPedo19zSUm/8Bd6Fzo=",
19
- "_ops.py": "mZSHUC0K9o9glzvGmRSdtPppOq4bmIaxNEjibkaWTk0="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
- "sha": "870e825d881664e39f9287a27a74ef63ff3c545e",
26
  "dirty": false
27
  },
28
  "kernel": {
29
- "sha": "8a66d8b7f79a6fde86aa6929db2b60ab097e2d55",
30
  "dirty": false
31
  }
32
  }
 
1
  {
2
  "name": "fp4-gemm",
3
+ "id": "_fp4_gemm_cuda_55c4885",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
+ "__init__.py": "4o968SKYWj8r1Ly7FqSPFK/AYdu4G4bXuVv1UcvYjk8=",
18
+ "_fp4_gemm_cuda_55c4885.abi3.so": "xVpPYjP2mebS5pIF4PTF53U9DcIWEpv3XkR31nXa7o4=",
19
+ "_ops.py": "IVtq+3pHXwuoCbgYGw3JP7/nKr3GEZqn8D97JJjf7ZE="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
+ "sha": "81f55ea30fd8f819dcf93a3c934dd584c895bd2f",
26
  "dirty": false
27
  },
28
  "kernel": {
29
+ "sha": "55c4885251068f195418bcf9ae541f4b757a6ea0",
30
  "dirty": false
31
  }
32
  }
build/torch212-cxx11-cu132-x86_64-linux/__init__.py CHANGED
@@ -19,7 +19,8 @@ def sfa_size_bytes(rows: int, dim: int) -> int:
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
- torch.empty((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
 
23
  )
24
 
25
 
@@ -36,6 +37,26 @@ def _linear_fake(
36
  return None
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
40
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
41
  if a_packed.shape[0] != 1:
@@ -162,6 +183,100 @@ def nvfp4_gemm_bf16(
162
  return out
163
 
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def fp4_w4a4_gemv_warpsplit_bf16(
166
  a_packed: torch.Tensor,
167
  b_packed: torch.Tensor,
@@ -292,7 +407,7 @@ def nvfp4_gemm_bias_gelu_nvfp4(
292
  if out_packed is None:
293
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
294
  if out_sfa is None:
295
- out_sfa = torch.empty((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
296
  ops.nvfp4_gemm_bias_gelu_nvfp4(
297
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
298
  )
@@ -345,6 +460,10 @@ __all__ = [
345
  "fp4_w4a16_linear_bf16",
346
  "fp4_w4a4_gemv_warpsplit_bf16",
347
  "nvfp4_gemm_bf16",
 
 
 
 
348
  "nvfp4_gemm_bias_bf16",
349
  "nvfp4_gemm_bias_gelu_bf16",
350
  "nvfp4_gemm_bias_gelu_nvfp4",
 
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
+ # Tile-layout padding entries are not written by every quantizer.
23
+ torch.zeros((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
24
  )
25
 
26
 
 
37
  return None
38
 
39
 
40
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_fp16"))
41
+ def _linear_fp16_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, variant: int = -1) -> None:
42
+ return None
43
+
44
+
45
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_geglu_nvfp4_fp16"))
46
+ def _geglu_fp4_fake(a, b, sfa, sfb, scratch, out_packed, out_sfa, skinny: bool = False) -> None:
47
+ return None
48
+
49
+
50
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_gelu_nvfp4_fp16"))
51
+ def _bias_gelu_fp4_fp16_fake(a, b, sfa, sfb, bias, out_packed, out_sfa) -> None:
52
+ return None
53
+
54
+
55
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_residual_fp16"))
56
+ def _bias_residual_fp16_fake(a, b, sfa, sfb, bias, residual, out) -> None:
57
+ return None
58
+
59
+
60
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
61
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
62
  if a_packed.shape[0] != 1:
 
183
  return out
184
 
185
 
186
+ def nvfp4_gemm_fp16(
187
+ a_packed: torch.Tensor,
188
+ b_packed: torch.Tensor,
189
+ sfa: torch.Tensor,
190
+ sfb: torch.Tensor,
191
+ alpha: float = 1.0,
192
+ out: torch.Tensor | None = None,
193
+ variant: int = -1,
194
+ ) -> torch.Tensor:
195
+ """SM110 native NVFP4 GEMM with FP16 output."""
196
+ if out is None:
197
+ out = torch.empty(
198
+ (a_packed.shape[0], b_packed.shape[0]),
199
+ device=a_packed.device,
200
+ dtype=torch.float16,
201
+ )
202
+ ops.nvfp4_gemm_fp16(
203
+ a_packed, b_packed, sfa, sfb, out, float(alpha), int(variant)
204
+ )
205
+ return out
206
+
207
+
208
+ def nvfp4_gemm_geglu_nvfp4_fp16(
209
+ a_packed: torch.Tensor,
210
+ b_interleaved_packed: torch.Tensor,
211
+ sfa: torch.Tensor,
212
+ sfb: torch.Tensor,
213
+ *,
214
+ skinny: bool = False,
215
+ scratch: torch.Tensor | None = None,
216
+ out_packed: torch.Tensor | None = None,
217
+ out_sfa: torch.Tensor | None = None,
218
+ ) -> tuple[torch.Tensor, torch.Tensor]:
219
+ """GEMM with fused GeGLU and compact NVFP4 output on SM110.
220
+
221
+ ``b_interleaved_packed`` stores gate/up rows pairwise, so its first
222
+ dimension is twice the logical hidden width.
223
+ """
224
+ m, n_twice = a_packed.shape[0], b_interleaved_packed.shape[0]
225
+ hidden = n_twice // 2
226
+ if scratch is None:
227
+ scratch = torch.empty((m, hidden), device=a_packed.device, dtype=torch.uint8)
228
+ if out_packed is None:
229
+ out_packed = torch.empty((m, hidden // 2), device=a_packed.device, dtype=torch.uint8)
230
+ if out_sfa is None:
231
+ out_sfa = torch.zeros((sfa_size_bytes(m, hidden),), device=a_packed.device, dtype=torch.uint8)
232
+ ops.nvfp4_gemm_geglu_nvfp4_fp16(
233
+ a_packed, b_interleaved_packed, sfa, sfb, scratch,
234
+ out_packed, out_sfa, bool(skinny)
235
+ )
236
+ return out_packed, out_sfa
237
+
238
+
239
+ def nvfp4_gemm_bias_gelu_nvfp4_fp16(
240
+ a_packed: torch.Tensor,
241
+ b_packed: torch.Tensor,
242
+ sfa: torch.Tensor,
243
+ sfb: torch.Tensor,
244
+ bias: torch.Tensor,
245
+ *,
246
+ out_packed: torch.Tensor | None = None,
247
+ out_sfa: torch.Tensor | None = None,
248
+ ) -> tuple[torch.Tensor, torch.Tensor]:
249
+ """FP16-bias GEMM with fused GELU and NVFP4 output on SM110."""
250
+ m, n = a_packed.shape[0], b_packed.shape[0]
251
+ if out_packed is None:
252
+ out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
253
+ if out_sfa is None:
254
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
255
+ ops.nvfp4_gemm_bias_gelu_nvfp4_fp16(
256
+ a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa
257
+ )
258
+ return out_packed, out_sfa
259
+
260
+
261
+ def nvfp4_gemm_bias_residual_fp16(
262
+ a_packed: torch.Tensor,
263
+ b_packed: torch.Tensor,
264
+ sfa: torch.Tensor,
265
+ sfb: torch.Tensor,
266
+ bias: torch.Tensor,
267
+ residual: torch.Tensor,
268
+ *,
269
+ out: torch.Tensor | None = None,
270
+ ) -> torch.Tensor:
271
+ """FP16-output GEMM with fused FP16 bias and residual on SM110."""
272
+ if out is None:
273
+ out = torch.empty_like(residual)
274
+ ops.nvfp4_gemm_bias_residual_fp16(
275
+ a_packed, b_packed, sfa, sfb, bias, residual, out
276
+ )
277
+ return out
278
+
279
+
280
  def fp4_w4a4_gemv_warpsplit_bf16(
281
  a_packed: torch.Tensor,
282
  b_packed: torch.Tensor,
 
407
  if out_packed is None:
408
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
409
  if out_sfa is None:
410
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
411
  ops.nvfp4_gemm_bias_gelu_nvfp4(
412
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
413
  )
 
460
  "fp4_w4a16_linear_bf16",
461
  "fp4_w4a4_gemv_warpsplit_bf16",
462
  "nvfp4_gemm_bf16",
463
+ "nvfp4_gemm_fp16",
464
+ "nvfp4_gemm_geglu_nvfp4_fp16",
465
+ "nvfp4_gemm_bias_gelu_nvfp4_fp16",
466
+ "nvfp4_gemm_bias_residual_fp16",
467
  "nvfp4_gemm_bias_bf16",
468
  "nvfp4_gemm_bias_gelu_bf16",
469
  "nvfp4_gemm_bias_gelu_nvfp4",
build/torch212-cxx11-cu132-x86_64-linux/{_fp4_gemm_cuda_8a66d8b.abi3.so → _fp4_gemm_cuda_55c4885.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:69c1903f5c54a54d13a0a27890d26ca0f17123dfceb463d44c1cc7185d2db1b6
3
- size 2843976
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9745e68973460d1d2fbb943c7ba63ab9fb23d8bb8a59c707bcf386e3891c69cb
3
+ size 6342256
build/torch212-cxx11-cu132-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _fp4_gemm_cuda_8a66d8b
3
- ops = torch.ops._fp4_gemm_cuda_8a66d8b
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_fp4_gemm_cuda_8a66d8b::{op_name}"
 
1
  import torch
2
+ from . import _fp4_gemm_cuda_55c4885
3
+ ops = torch.ops._fp4_gemm_cuda_55c4885
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_fp4_gemm_cuda_55c4885::{op_name}"
build/torch212-cxx11-cu132-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "fp4-gemm",
3
- "id": "_fp4_gemm_cuda_8a66d8b",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
@@ -14,19 +14,19 @@
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
- "__init__.py": "+Kk/VNnIWwe9nszQYvL2qtU3DpKxbqHVfklg5WtVuB4=",
18
- "_fp4_gemm_cuda_8a66d8b.abi3.so": "acGQP1xUpU0ToKJ4kNJsoPFxI9/OtGPUTBzHGF0tsbY=",
19
- "_ops.py": "mZSHUC0K9o9glzvGmRSdtPppOq4bmIaxNEjibkaWTk0="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
- "sha": "870e825d881664e39f9287a27a74ef63ff3c545e",
26
  "dirty": false
27
  },
28
  "kernel": {
29
- "sha": "8a66d8b7f79a6fde86aa6929db2b60ab097e2d55",
30
  "dirty": false
31
  }
32
  }
 
1
  {
2
  "name": "fp4-gemm",
3
+ "id": "_fp4_gemm_cuda_55c4885",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
+ "__init__.py": "4o968SKYWj8r1Ly7FqSPFK/AYdu4G4bXuVv1UcvYjk8=",
18
+ "_fp4_gemm_cuda_55c4885.abi3.so": "l0XmiXNGDR0vu5Q8e6Y6ufsj2LuKWccHvPOG44kcacs=",
19
+ "_ops.py": "IVtq+3pHXwuoCbgYGw3JP7/nKr3GEZqn8D97JJjf7ZE="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
+ "sha": "81f55ea30fd8f819dcf93a3c934dd584c895bd2f",
26
  "dirty": false
27
  },
28
  "kernel": {
29
+ "sha": "55c4885251068f195418bcf9ae541f4b757a6ea0",
30
  "dirty": false
31
  }
32
  }
build/torch213-cxx11-cu130-x86_64-linux/__init__.py CHANGED
@@ -19,7 +19,8 @@ def sfa_size_bytes(rows: int, dim: int) -> int:
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
- torch.empty((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
 
23
  )
24
 
25
 
@@ -36,6 +37,26 @@ def _linear_fake(
36
  return None
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
40
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
41
  if a_packed.shape[0] != 1:
@@ -162,6 +183,100 @@ def nvfp4_gemm_bf16(
162
  return out
163
 
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def fp4_w4a4_gemv_warpsplit_bf16(
166
  a_packed: torch.Tensor,
167
  b_packed: torch.Tensor,
@@ -292,7 +407,7 @@ def nvfp4_gemm_bias_gelu_nvfp4(
292
  if out_packed is None:
293
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
294
  if out_sfa is None:
295
- out_sfa = torch.empty((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
296
  ops.nvfp4_gemm_bias_gelu_nvfp4(
297
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
298
  )
@@ -345,6 +460,10 @@ __all__ = [
345
  "fp4_w4a16_linear_bf16",
346
  "fp4_w4a4_gemv_warpsplit_bf16",
347
  "nvfp4_gemm_bf16",
 
 
 
 
348
  "nvfp4_gemm_bias_bf16",
349
  "nvfp4_gemm_bias_gelu_bf16",
350
  "nvfp4_gemm_bias_gelu_nvfp4",
 
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
+ # Tile-layout padding entries are not written by every quantizer.
23
+ torch.zeros((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
24
  )
25
 
26
 
 
37
  return None
38
 
39
 
40
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_fp16"))
41
+ def _linear_fp16_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, variant: int = -1) -> None:
42
+ return None
43
+
44
+
45
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_geglu_nvfp4_fp16"))
46
+ def _geglu_fp4_fake(a, b, sfa, sfb, scratch, out_packed, out_sfa, skinny: bool = False) -> None:
47
+ return None
48
+
49
+
50
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_gelu_nvfp4_fp16"))
51
+ def _bias_gelu_fp4_fp16_fake(a, b, sfa, sfb, bias, out_packed, out_sfa) -> None:
52
+ return None
53
+
54
+
55
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_residual_fp16"))
56
+ def _bias_residual_fp16_fake(a, b, sfa, sfb, bias, residual, out) -> None:
57
+ return None
58
+
59
+
60
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
61
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
62
  if a_packed.shape[0] != 1:
 
183
  return out
184
 
185
 
186
+ def nvfp4_gemm_fp16(
187
+ a_packed: torch.Tensor,
188
+ b_packed: torch.Tensor,
189
+ sfa: torch.Tensor,
190
+ sfb: torch.Tensor,
191
+ alpha: float = 1.0,
192
+ out: torch.Tensor | None = None,
193
+ variant: int = -1,
194
+ ) -> torch.Tensor:
195
+ """SM110 native NVFP4 GEMM with FP16 output."""
196
+ if out is None:
197
+ out = torch.empty(
198
+ (a_packed.shape[0], b_packed.shape[0]),
199
+ device=a_packed.device,
200
+ dtype=torch.float16,
201
+ )
202
+ ops.nvfp4_gemm_fp16(
203
+ a_packed, b_packed, sfa, sfb, out, float(alpha), int(variant)
204
+ )
205
+ return out
206
+
207
+
208
+ def nvfp4_gemm_geglu_nvfp4_fp16(
209
+ a_packed: torch.Tensor,
210
+ b_interleaved_packed: torch.Tensor,
211
+ sfa: torch.Tensor,
212
+ sfb: torch.Tensor,
213
+ *,
214
+ skinny: bool = False,
215
+ scratch: torch.Tensor | None = None,
216
+ out_packed: torch.Tensor | None = None,
217
+ out_sfa: torch.Tensor | None = None,
218
+ ) -> tuple[torch.Tensor, torch.Tensor]:
219
+ """GEMM with fused GeGLU and compact NVFP4 output on SM110.
220
+
221
+ ``b_interleaved_packed`` stores gate/up rows pairwise, so its first
222
+ dimension is twice the logical hidden width.
223
+ """
224
+ m, n_twice = a_packed.shape[0], b_interleaved_packed.shape[0]
225
+ hidden = n_twice // 2
226
+ if scratch is None:
227
+ scratch = torch.empty((m, hidden), device=a_packed.device, dtype=torch.uint8)
228
+ if out_packed is None:
229
+ out_packed = torch.empty((m, hidden // 2), device=a_packed.device, dtype=torch.uint8)
230
+ if out_sfa is None:
231
+ out_sfa = torch.zeros((sfa_size_bytes(m, hidden),), device=a_packed.device, dtype=torch.uint8)
232
+ ops.nvfp4_gemm_geglu_nvfp4_fp16(
233
+ a_packed, b_interleaved_packed, sfa, sfb, scratch,
234
+ out_packed, out_sfa, bool(skinny)
235
+ )
236
+ return out_packed, out_sfa
237
+
238
+
239
+ def nvfp4_gemm_bias_gelu_nvfp4_fp16(
240
+ a_packed: torch.Tensor,
241
+ b_packed: torch.Tensor,
242
+ sfa: torch.Tensor,
243
+ sfb: torch.Tensor,
244
+ bias: torch.Tensor,
245
+ *,
246
+ out_packed: torch.Tensor | None = None,
247
+ out_sfa: torch.Tensor | None = None,
248
+ ) -> tuple[torch.Tensor, torch.Tensor]:
249
+ """FP16-bias GEMM with fused GELU and NVFP4 output on SM110."""
250
+ m, n = a_packed.shape[0], b_packed.shape[0]
251
+ if out_packed is None:
252
+ out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
253
+ if out_sfa is None:
254
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
255
+ ops.nvfp4_gemm_bias_gelu_nvfp4_fp16(
256
+ a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa
257
+ )
258
+ return out_packed, out_sfa
259
+
260
+
261
+ def nvfp4_gemm_bias_residual_fp16(
262
+ a_packed: torch.Tensor,
263
+ b_packed: torch.Tensor,
264
+ sfa: torch.Tensor,
265
+ sfb: torch.Tensor,
266
+ bias: torch.Tensor,
267
+ residual: torch.Tensor,
268
+ *,
269
+ out: torch.Tensor | None = None,
270
+ ) -> torch.Tensor:
271
+ """FP16-output GEMM with fused FP16 bias and residual on SM110."""
272
+ if out is None:
273
+ out = torch.empty_like(residual)
274
+ ops.nvfp4_gemm_bias_residual_fp16(
275
+ a_packed, b_packed, sfa, sfb, bias, residual, out
276
+ )
277
+ return out
278
+
279
+
280
  def fp4_w4a4_gemv_warpsplit_bf16(
281
  a_packed: torch.Tensor,
282
  b_packed: torch.Tensor,
 
407
  if out_packed is None:
408
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
409
  if out_sfa is None:
410
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
411
  ops.nvfp4_gemm_bias_gelu_nvfp4(
412
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
413
  )
 
460
  "fp4_w4a16_linear_bf16",
461
  "fp4_w4a4_gemv_warpsplit_bf16",
462
  "nvfp4_gemm_bf16",
463
+ "nvfp4_gemm_fp16",
464
+ "nvfp4_gemm_geglu_nvfp4_fp16",
465
+ "nvfp4_gemm_bias_gelu_nvfp4_fp16",
466
+ "nvfp4_gemm_bias_residual_fp16",
467
  "nvfp4_gemm_bias_bf16",
468
  "nvfp4_gemm_bias_gelu_bf16",
469
  "nvfp4_gemm_bias_gelu_nvfp4",
build/torch213-cxx11-cu130-x86_64-linux/{_fp4_gemm_cuda_8a66d8b.abi3.so → _fp4_gemm_cuda_55c4885.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:2fe7efef250feb7e8ec881de0919f010812cc5840a2b071993b4336cdfa9717e
3
- size 2847968
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a35111ce16d53ac8a6300acc0ea58b3c560abc04ca16e3be4297b4e3bb09335
3
+ size 6350344
build/torch213-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _fp4_gemm_cuda_8a66d8b
3
- ops = torch.ops._fp4_gemm_cuda_8a66d8b
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_fp4_gemm_cuda_8a66d8b::{op_name}"
 
1
  import torch
2
+ from . import _fp4_gemm_cuda_55c4885
3
+ ops = torch.ops._fp4_gemm_cuda_55c4885
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_fp4_gemm_cuda_55c4885::{op_name}"
build/torch213-cxx11-cu130-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "fp4-gemm",
3
- "id": "_fp4_gemm_cuda_8a66d8b",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
@@ -14,19 +14,19 @@
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
- "__init__.py": "+Kk/VNnIWwe9nszQYvL2qtU3DpKxbqHVfklg5WtVuB4=",
18
- "_fp4_gemm_cuda_8a66d8b.abi3.so": "L+fv7yUP636OyIHeCRnwEIEsxYQKKwcZk7QzbN+pcX4=",
19
- "_ops.py": "mZSHUC0K9o9glzvGmRSdtPppOq4bmIaxNEjibkaWTk0="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
- "sha": "870e825d881664e39f9287a27a74ef63ff3c545e",
26
  "dirty": false
27
  },
28
  "kernel": {
29
- "sha": "8a66d8b7f79a6fde86aa6929db2b60ab097e2d55",
30
  "dirty": false
31
  }
32
  }
 
1
  {
2
  "name": "fp4-gemm",
3
+ "id": "_fp4_gemm_cuda_55c4885",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
+ "__init__.py": "4o968SKYWj8r1Ly7FqSPFK/AYdu4G4bXuVv1UcvYjk8=",
18
+ "_fp4_gemm_cuda_55c4885.abi3.so": "CjURHOFtU6yKYwCswOpYs8Vgq8BMoW475Cl7TjuwkzU=",
19
+ "_ops.py": "IVtq+3pHXwuoCbgYGw3JP7/nKr3GEZqn8D97JJjf7ZE="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
+ "sha": "81f55ea30fd8f819dcf93a3c934dd584c895bd2f",
26
  "dirty": false
27
  },
28
  "kernel": {
29
+ "sha": "55c4885251068f195418bcf9ae541f4b757a6ea0",
30
  "dirty": false
31
  }
32
  }
build/torch213-cxx11-cu132-x86_64-linux/__init__.py CHANGED
@@ -19,7 +19,8 @@ def sfa_size_bytes(rows: int, dim: int) -> int:
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
- torch.empty((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
 
23
  )
24
 
25
 
@@ -36,6 +37,26 @@ def _linear_fake(
36
  return None
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
40
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
41
  if a_packed.shape[0] != 1:
@@ -162,6 +183,100 @@ def nvfp4_gemm_bf16(
162
  return out
163
 
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def fp4_w4a4_gemv_warpsplit_bf16(
166
  a_packed: torch.Tensor,
167
  b_packed: torch.Tensor,
@@ -292,7 +407,7 @@ def nvfp4_gemm_bias_gelu_nvfp4(
292
  if out_packed is None:
293
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
294
  if out_sfa is None:
295
- out_sfa = torch.empty((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
296
  ops.nvfp4_gemm_bias_gelu_nvfp4(
297
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
298
  )
@@ -345,6 +460,10 @@ __all__ = [
345
  "fp4_w4a16_linear_bf16",
346
  "fp4_w4a4_gemv_warpsplit_bf16",
347
  "nvfp4_gemm_bf16",
 
 
 
 
348
  "nvfp4_gemm_bias_bf16",
349
  "nvfp4_gemm_bias_gelu_bf16",
350
  "nvfp4_gemm_bias_gelu_nvfp4",
 
19
  def _alloc_fp4(rows: int, dim: int, device: torch.device | str):
20
  return (
21
  torch.empty((rows, dim // 2), device=device, dtype=torch.uint8),
22
+ # Tile-layout padding entries are not written by every quantizer.
23
+ torch.zeros((sfa_size_bytes(rows, dim),), device=device, dtype=torch.uint8),
24
  )
25
 
26
 
 
37
  return None
38
 
39
 
40
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_fp16"))
41
+ def _linear_fp16_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, variant: int = -1) -> None:
42
+ return None
43
+
44
+
45
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_geglu_nvfp4_fp16"))
46
+ def _geglu_fp4_fake(a, b, sfa, sfb, scratch, out_packed, out_sfa, skinny: bool = False) -> None:
47
+ return None
48
+
49
+
50
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_gelu_nvfp4_fp16"))
51
+ def _bias_gelu_fp4_fp16_fake(a, b, sfa, sfb, bias, out_packed, out_sfa) -> None:
52
+ return None
53
+
54
+
55
+ @torch.library.register_fake(add_op_namespace_prefix("nvfp4_gemm_bias_residual_fp16"))
56
+ def _bias_residual_fp16_fake(a, b, sfa, sfb, bias, residual, out) -> None:
57
+ return None
58
+
59
+
60
  @torch.library.register_fake(add_op_namespace_prefix("fp4_w4a4_gemv_warpsplit_bf16"))
61
  def _gemv_warpsplit_fake(a_packed, b_packed, sfa, sfb, out, alpha: float = 1.0, warps: int = 4, stages: int = 4) -> None:
62
  if a_packed.shape[0] != 1:
 
183
  return out
184
 
185
 
186
+ def nvfp4_gemm_fp16(
187
+ a_packed: torch.Tensor,
188
+ b_packed: torch.Tensor,
189
+ sfa: torch.Tensor,
190
+ sfb: torch.Tensor,
191
+ alpha: float = 1.0,
192
+ out: torch.Tensor | None = None,
193
+ variant: int = -1,
194
+ ) -> torch.Tensor:
195
+ """SM110 native NVFP4 GEMM with FP16 output."""
196
+ if out is None:
197
+ out = torch.empty(
198
+ (a_packed.shape[0], b_packed.shape[0]),
199
+ device=a_packed.device,
200
+ dtype=torch.float16,
201
+ )
202
+ ops.nvfp4_gemm_fp16(
203
+ a_packed, b_packed, sfa, sfb, out, float(alpha), int(variant)
204
+ )
205
+ return out
206
+
207
+
208
+ def nvfp4_gemm_geglu_nvfp4_fp16(
209
+ a_packed: torch.Tensor,
210
+ b_interleaved_packed: torch.Tensor,
211
+ sfa: torch.Tensor,
212
+ sfb: torch.Tensor,
213
+ *,
214
+ skinny: bool = False,
215
+ scratch: torch.Tensor | None = None,
216
+ out_packed: torch.Tensor | None = None,
217
+ out_sfa: torch.Tensor | None = None,
218
+ ) -> tuple[torch.Tensor, torch.Tensor]:
219
+ """GEMM with fused GeGLU and compact NVFP4 output on SM110.
220
+
221
+ ``b_interleaved_packed`` stores gate/up rows pairwise, so its first
222
+ dimension is twice the logical hidden width.
223
+ """
224
+ m, n_twice = a_packed.shape[0], b_interleaved_packed.shape[0]
225
+ hidden = n_twice // 2
226
+ if scratch is None:
227
+ scratch = torch.empty((m, hidden), device=a_packed.device, dtype=torch.uint8)
228
+ if out_packed is None:
229
+ out_packed = torch.empty((m, hidden // 2), device=a_packed.device, dtype=torch.uint8)
230
+ if out_sfa is None:
231
+ out_sfa = torch.zeros((sfa_size_bytes(m, hidden),), device=a_packed.device, dtype=torch.uint8)
232
+ ops.nvfp4_gemm_geglu_nvfp4_fp16(
233
+ a_packed, b_interleaved_packed, sfa, sfb, scratch,
234
+ out_packed, out_sfa, bool(skinny)
235
+ )
236
+ return out_packed, out_sfa
237
+
238
+
239
+ def nvfp4_gemm_bias_gelu_nvfp4_fp16(
240
+ a_packed: torch.Tensor,
241
+ b_packed: torch.Tensor,
242
+ sfa: torch.Tensor,
243
+ sfb: torch.Tensor,
244
+ bias: torch.Tensor,
245
+ *,
246
+ out_packed: torch.Tensor | None = None,
247
+ out_sfa: torch.Tensor | None = None,
248
+ ) -> tuple[torch.Tensor, torch.Tensor]:
249
+ """FP16-bias GEMM with fused GELU and NVFP4 output on SM110."""
250
+ m, n = a_packed.shape[0], b_packed.shape[0]
251
+ if out_packed is None:
252
+ out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
253
+ if out_sfa is None:
254
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
255
+ ops.nvfp4_gemm_bias_gelu_nvfp4_fp16(
256
+ a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa
257
+ )
258
+ return out_packed, out_sfa
259
+
260
+
261
+ def nvfp4_gemm_bias_residual_fp16(
262
+ a_packed: torch.Tensor,
263
+ b_packed: torch.Tensor,
264
+ sfa: torch.Tensor,
265
+ sfb: torch.Tensor,
266
+ bias: torch.Tensor,
267
+ residual: torch.Tensor,
268
+ *,
269
+ out: torch.Tensor | None = None,
270
+ ) -> torch.Tensor:
271
+ """FP16-output GEMM with fused FP16 bias and residual on SM110."""
272
+ if out is None:
273
+ out = torch.empty_like(residual)
274
+ ops.nvfp4_gemm_bias_residual_fp16(
275
+ a_packed, b_packed, sfa, sfb, bias, residual, out
276
+ )
277
+ return out
278
+
279
+
280
  def fp4_w4a4_gemv_warpsplit_bf16(
281
  a_packed: torch.Tensor,
282
  b_packed: torch.Tensor,
 
407
  if out_packed is None:
408
  out_packed = torch.empty((m, n // 2), device=a_packed.device, dtype=torch.uint8)
409
  if out_sfa is None:
410
+ out_sfa = torch.zeros((sfa_size_bytes(m, n),), device=a_packed.device, dtype=torch.uint8)
411
  ops.nvfp4_gemm_bias_gelu_nvfp4(
412
  a_packed, b_packed, sfa, sfb, bias, out_packed, out_sfa, float(alpha)
413
  )
 
460
  "fp4_w4a16_linear_bf16",
461
  "fp4_w4a4_gemv_warpsplit_bf16",
462
  "nvfp4_gemm_bf16",
463
+ "nvfp4_gemm_fp16",
464
+ "nvfp4_gemm_geglu_nvfp4_fp16",
465
+ "nvfp4_gemm_bias_gelu_nvfp4_fp16",
466
+ "nvfp4_gemm_bias_residual_fp16",
467
  "nvfp4_gemm_bias_bf16",
468
  "nvfp4_gemm_bias_gelu_bf16",
469
  "nvfp4_gemm_bias_gelu_nvfp4",
build/torch213-cxx11-cu132-x86_64-linux/{_fp4_gemm_cuda_8a66d8b.abi3.so → _fp4_gemm_cuda_55c4885.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7043e89c27719838b2dfab5d8c82e8098528a792ba5d89861a5bfe45cecc022c
3
- size 2843824
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce8cdbdd5f77404bb14b639d16ca5cdada3ddd43a40d6edeb5a4cdee2d6a260e
3
+ size 6342104
build/torch213-cxx11-cu132-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _fp4_gemm_cuda_8a66d8b
3
- ops = torch.ops._fp4_gemm_cuda_8a66d8b
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_fp4_gemm_cuda_8a66d8b::{op_name}"
 
1
  import torch
2
+ from . import _fp4_gemm_cuda_55c4885
3
+ ops = torch.ops._fp4_gemm_cuda_55c4885
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_fp4_gemm_cuda_55c4885::{op_name}"
build/torch213-cxx11-cu132-x86_64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "fp4-gemm",
3
- "id": "_fp4_gemm_cuda_8a66d8b",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
@@ -14,19 +14,19 @@
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
- "__init__.py": "+Kk/VNnIWwe9nszQYvL2qtU3DpKxbqHVfklg5WtVuB4=",
18
- "_fp4_gemm_cuda_8a66d8b.abi3.so": "cEPonCdxmDiy36tdjILoCYUop5K6XYmGGlv+Rc7MAiw=",
19
- "_ops.py": "mZSHUC0K9o9glzvGmRSdtPppOq4bmIaxNEjibkaWTk0="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
- "sha": "870e825d881664e39f9287a27a74ef63ff3c545e",
26
  "dirty": false
27
  },
28
  "kernel": {
29
- "sha": "8a66d8b7f79a6fde86aa6929db2b60ab097e2d55",
30
  "dirty": false
31
  }
32
  }
 
1
  {
2
  "name": "fp4-gemm",
3
+ "id": "_fp4_gemm_cuda_55c4885",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
14
  "digest": {
15
  "algorithm": "sha256",
16
  "files": {
17
+ "__init__.py": "4o968SKYWj8r1Ly7FqSPFK/AYdu4G4bXuVv1UcvYjk8=",
18
+ "_fp4_gemm_cuda_55c4885.abi3.so": "zozb3V93QEuxS2OdFspc2to93UOkDW7etaTN7i1qJg4=",
19
+ "_ops.py": "IVtq+3pHXwuoCbgYGw3JP7/nKr3GEZqn8D97JJjf7ZE="
20
  }
21
  },
22
  "provenance": {
23
  "kernel-builder": {
24
  "version": "0.17.0-dev0",
25
+ "sha": "81f55ea30fd8f819dcf93a3c934dd584c895bd2f",
26
  "dirty": false
27
  },
28
  "kernel": {
29
+ "sha": "55c4885251068f195418bcf9ae541f4b757a6ea0",
30
  "dirty": false
31
  }
32
  }