liangsu9988 commited on
Commit
5ec72ab
·
verified ·
1 Parent(s): 3a545c6

Uploaded using `kernel-builder`.

Browse files
benchmarks/benchmark.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Benchmark causal-conv1d-state."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import argparse
7
+ import json
8
+ from pathlib import Path
9
+
10
+ import sys
11
+ import torch
12
+
13
+ TESTS = Path(__file__).resolve().parents[1] / "tests"
14
+ sys.path.insert(0, str(TESTS))
15
+ from test_causal_conv1d_state import MODES, SHAPES, load_installed_ops, load_source_ops, make_inputs, ref_chunk # noqa: E402
16
+
17
+
18
+ def time_cuda(fn, warmup: int, iters: int) -> float:
19
+ for _ in range(warmup):
20
+ fn()
21
+ torch.cuda.synchronize()
22
+ start = torch.cuda.Event(enable_timing=True)
23
+ end = torch.cuda.Event(enable_timing=True)
24
+ start.record()
25
+ for _ in range(iters):
26
+ fn()
27
+ end.record()
28
+ torch.cuda.synchronize()
29
+ return float(start.elapsed_time(end) * 1000.0 / iters)
30
+
31
+
32
+ def main() -> int:
33
+ parser = argparse.ArgumentParser()
34
+ parser.add_argument("--backend", choices=["source", "installed"], default="source")
35
+ parser.add_argument("--artifact", default=None)
36
+ parser.add_argument("--mode", choices=sorted(MODES), default="headline")
37
+ parser.add_argument("--warmup", type=int, default=20)
38
+ parser.add_argument("--iters", type=int, default=200)
39
+ parser.add_argument("--json-out", default=None)
40
+ args = parser.parse_args()
41
+ ops = load_source_ops() if args.backend == "source" else load_installed_ops(args.artifact)
42
+ rows = []
43
+ for name in MODES[args.mode]:
44
+ kind, B, S, C, K = SHAPES[name]
45
+ x, w, bias, state = make_inputs(B, S, C, K, seed=9900 + C + S)
46
+ if kind in {"chunk", "parallel", "gqa"}:
47
+ if kind == "gqa":
48
+ def kernel_call():
49
+ state_work = state.clone()
50
+ return ops.gqa(x, w, state_work, bias)
51
+ elif kind == "parallel":
52
+ def kernel_call():
53
+ state_work = state.clone()
54
+ return ops.parallel(x, w, state_work, bias)
55
+ else:
56
+ def kernel_call():
57
+ state_work = state.clone()
58
+ return ops.chunk(x, w, state_work, bias)
59
+
60
+ def ref_call():
61
+ return ref_chunk(x, w, bias, state)
62
+ else:
63
+ continue
64
+ kernel_us = time_cuda(kernel_call, args.warmup, args.iters)
65
+ ref_us = time_cuda(ref_call, max(2, args.warmup // 5), max(5, args.iters // 20))
66
+ rows.append({"shape": name, "kind": kind, "B": B, "S": S, "C": C, "K": K, "kernel_us": kernel_us, "torch_reference_us": ref_us, "speedup": ref_us / kernel_us})
67
+ print(f"{name}: kernel={kernel_us:.3f}us ref={ref_us:.3f}us speedup={ref_us / kernel_us:.2f}x")
68
+ if args.json_out:
69
+ Path(args.json_out).parent.mkdir(parents=True, exist_ok=True)
70
+ Path(args.json_out).write_text(json.dumps(rows, indent=2) + "\n")
71
+ return 0
72
+
73
+
74
+ if __name__ == "__main__":
75
+ raise SystemExit(main())
build/torch211-cxx11-cu128-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT causal Conv1D state 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
+ def _empty_bias_like(x: torch.Tensor) -> torch.Tensor:
13
+ return torch.empty((0,), device=x.device, dtype=torch.bfloat16)
14
+
15
+
16
+ def _check_conv_shapes(x: torch.Tensor, w: torch.Tensor, bias: torch.Tensor, has_bias: bool, out: torch.Tensor) -> None:
17
+ if x.dim() != 3:
18
+ raise RuntimeError("x must have shape (B,S,C)")
19
+ if w.dim() != 2 or w.shape[0] != x.shape[2] or w.shape[1] < 2 or w.shape[1] > 8:
20
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
21
+ if has_bias and bias.shape != (x.shape[2],):
22
+ raise RuntimeError("bias must have shape (C,)")
23
+ if out.shape != x.shape:
24
+ raise RuntimeError("out must match x shape")
25
+
26
+
27
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_bf16"))
28
+ def _causal_conv1d_bf16_fake(
29
+ x: torch.Tensor,
30
+ w: torch.Tensor,
31
+ bias: torch.Tensor,
32
+ out: torch.Tensor,
33
+ has_bias: bool = True,
34
+ apply_silu: bool = True,
35
+ ) -> None:
36
+ _check_conv_shapes(x, w, bias, has_bias, out)
37
+ return None
38
+
39
+
40
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_bf16"))
41
+ def _causal_conv1d_update_bf16_fake(
42
+ x_new: torch.Tensor,
43
+ w: torch.Tensor,
44
+ bias: torch.Tensor,
45
+ state: torch.Tensor,
46
+ out: torch.Tensor,
47
+ has_bias: bool = True,
48
+ apply_silu: bool = True,
49
+ ) -> None:
50
+ if x_new.dim() != 2:
51
+ raise RuntimeError("x_new must have shape (B,C)")
52
+ b, c = x_new.shape
53
+ if w.dim() != 2 or w.shape[0] != c or w.shape[1] < 2 or w.shape[1] > 8:
54
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
55
+ if has_bias and bias.shape != (c,):
56
+ raise RuntimeError("bias must have shape (C,)")
57
+ if state.shape != (b, c, w.shape[1] - 1):
58
+ raise RuntimeError("state must have shape (B,C,K-1)")
59
+ if out.shape != x_new.shape:
60
+ raise RuntimeError("out must match x_new shape")
61
+ return None
62
+
63
+
64
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_inout_bf16"))
65
+ def _causal_conv1d_update_inout_bf16_fake(
66
+ x_new: torch.Tensor,
67
+ w: torch.Tensor,
68
+ bias: torch.Tensor,
69
+ state_in: torch.Tensor,
70
+ state_out: torch.Tensor,
71
+ out: torch.Tensor,
72
+ has_bias: bool = True,
73
+ apply_silu: bool = True,
74
+ ) -> None:
75
+ _causal_conv1d_update_bf16_fake(x_new, w, bias, state_in, out, has_bias, apply_silu)
76
+ if state_out.shape != state_in.shape:
77
+ raise RuntimeError("state_out shape mismatch")
78
+ return None
79
+
80
+
81
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_bf16"))
82
+ def _causal_conv1d_update_chunk_bf16_fake(
83
+ x: torch.Tensor,
84
+ w: torch.Tensor,
85
+ bias: torch.Tensor,
86
+ state: torch.Tensor,
87
+ out: torch.Tensor,
88
+ has_bias: bool = True,
89
+ apply_silu: bool = True,
90
+ ) -> None:
91
+ _check_conv_shapes(x, w, bias, has_bias, out)
92
+ if state.shape != (x.shape[0], x.shape[2], w.shape[1] - 1):
93
+ raise RuntimeError("state must have shape (B,C,K-1)")
94
+ return None
95
+
96
+
97
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_bf16"))
98
+ def _causal_conv1d_update_chunk_parallel_bf16_fake(
99
+ x: torch.Tensor,
100
+ w: torch.Tensor,
101
+ bias: torch.Tensor,
102
+ state: torch.Tensor,
103
+ out: torch.Tensor,
104
+ has_bias: bool = True,
105
+ apply_silu: bool = True,
106
+ ) -> None:
107
+ _causal_conv1d_update_chunk_bf16_fake(x, w, bias, state, out, has_bias, apply_silu)
108
+ return None
109
+
110
+
111
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_gqa_bf16"))
112
+ def _causal_conv1d_update_chunk_parallel_gqa_bf16_fake(
113
+ x: torch.Tensor,
114
+ w: torch.Tensor,
115
+ bias: torch.Tensor,
116
+ state: torch.Tensor,
117
+ q16: torch.Tensor,
118
+ k16: torch.Tensor,
119
+ v48: torch.Tensor,
120
+ has_bias: bool = True,
121
+ apply_silu: bool = True,
122
+ ) -> None:
123
+ if x.dim() != 3 or x.shape[2] != 10240:
124
+ raise RuntimeError("GQA split variant expects x shape (B,S,10240)")
125
+ if w.shape != (10240, w.shape[1]) or w.shape[1] < 2 or w.shape[1] > 8:
126
+ raise RuntimeError("w must have shape (10240,K), 2 <= K <= 8")
127
+ b, s, _ = x.shape
128
+ if state.shape != (b, 10240, w.shape[1] - 1):
129
+ raise RuntimeError("state must have shape (B,10240,K-1)")
130
+ if q16.shape != (b, s, 16, 128) or k16.shape != q16.shape or v48.shape != (b, s, 48, 128):
131
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
132
+ if has_bias and bias.shape != (10240,):
133
+ raise RuntimeError("bias must have shape (10240,)")
134
+ return None
135
+
136
+
137
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_steps_gqa_bf16"))
138
+ def _causal_conv1d_update_steps_gqa_bf16_fake(
139
+ x, w, bias, state, q16, k16, v48, apply_silu: bool = True
140
+ ) -> None:
141
+ del apply_silu
142
+ if x.dim() != 2 or x.shape[1] != 10240:
143
+ raise RuntimeError("x must have shape (S,10240)")
144
+ s = x.shape[0]
145
+ if w.shape != (10240, 4) or bias.shape != (10240,) or state.shape != (10240, 3):
146
+ raise RuntimeError("w/bias/state shape contract failed")
147
+ if q16.shape != (s, 2048) or k16.shape != q16.shape or v48.shape != (s, 6144):
148
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
149
+ return None
150
+
151
+
152
+ def causal_conv1d_bf16(
153
+ x: torch.Tensor,
154
+ w: torch.Tensor,
155
+ bias: Optional[torch.Tensor] = None,
156
+ *,
157
+ apply_silu: bool = True,
158
+ out: Optional[torch.Tensor] = None,
159
+ ) -> torch.Tensor:
160
+ if out is None:
161
+ out = torch.empty_like(x)
162
+ has_bias = bias is not None
163
+ if bias is None:
164
+ bias = _empty_bias_like(x)
165
+ ops.causal_conv1d_bf16(x, w, bias, out, bool(has_bias), bool(apply_silu))
166
+ return out
167
+
168
+
169
+ def causal_conv1d_update_bf16(
170
+ x_new: torch.Tensor,
171
+ w: torch.Tensor,
172
+ state: torch.Tensor,
173
+ bias: Optional[torch.Tensor] = None,
174
+ *,
175
+ apply_silu: bool = True,
176
+ out: Optional[torch.Tensor] = None,
177
+ ) -> torch.Tensor:
178
+ if out is None:
179
+ out = torch.empty_like(x_new)
180
+ has_bias = bias is not None
181
+ if bias is None:
182
+ bias = _empty_bias_like(x_new)
183
+ ops.causal_conv1d_update_bf16(x_new, w, bias, state, out, bool(has_bias), bool(apply_silu))
184
+ return out
185
+
186
+
187
+ def causal_conv1d_update_inout_bf16(
188
+ x_new: torch.Tensor,
189
+ w: torch.Tensor,
190
+ state_in: torch.Tensor,
191
+ bias: Optional[torch.Tensor] = None,
192
+ *,
193
+ apply_silu: bool = True,
194
+ out: Optional[torch.Tensor] = None,
195
+ state_out: Optional[torch.Tensor] = None,
196
+ ) -> tuple[torch.Tensor, torch.Tensor]:
197
+ if out is None:
198
+ out = torch.empty_like(x_new)
199
+ if state_out is None:
200
+ state_out = torch.empty_like(state_in)
201
+ has_bias = bias is not None
202
+ if bias is None:
203
+ bias = _empty_bias_like(x_new)
204
+ ops.causal_conv1d_update_inout_bf16(
205
+ x_new, w, bias, state_in, state_out, out, bool(has_bias), bool(apply_silu)
206
+ )
207
+ return out, state_out
208
+
209
+
210
+ def causal_conv1d_update_chunk_bf16(
211
+ x: torch.Tensor,
212
+ w: torch.Tensor,
213
+ state: torch.Tensor,
214
+ bias: Optional[torch.Tensor] = None,
215
+ *,
216
+ apply_silu: bool = True,
217
+ out: Optional[torch.Tensor] = None,
218
+ ) -> torch.Tensor:
219
+ if out is None:
220
+ out = torch.empty_like(x)
221
+ has_bias = bias is not None
222
+ if bias is None:
223
+ bias = _empty_bias_like(x)
224
+ ops.causal_conv1d_update_chunk_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
225
+ return out
226
+
227
+
228
+ def causal_conv1d_update_chunk_parallel_bf16(
229
+ x: torch.Tensor,
230
+ w: torch.Tensor,
231
+ state: torch.Tensor,
232
+ bias: Optional[torch.Tensor] = None,
233
+ *,
234
+ apply_silu: bool = True,
235
+ out: Optional[torch.Tensor] = None,
236
+ ) -> torch.Tensor:
237
+ if out is None:
238
+ out = torch.empty_like(x)
239
+ has_bias = bias is not None
240
+ if bias is None:
241
+ bias = _empty_bias_like(x)
242
+ ops.causal_conv1d_update_chunk_parallel_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
243
+ return out
244
+
245
+
246
+ def causal_conv1d_update_chunk_parallel_gqa_bf16(
247
+ x: torch.Tensor,
248
+ w: torch.Tensor,
249
+ state: torch.Tensor,
250
+ bias: Optional[torch.Tensor] = None,
251
+ *,
252
+ apply_silu: bool = True,
253
+ q16: Optional[torch.Tensor] = None,
254
+ k16: Optional[torch.Tensor] = None,
255
+ v48: Optional[torch.Tensor] = None,
256
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
257
+ b, s, _ = x.shape
258
+ if q16 is None:
259
+ q16 = torch.empty((b, s, 16, 128), device=x.device, dtype=torch.bfloat16)
260
+ if k16 is None:
261
+ k16 = torch.empty_like(q16)
262
+ if v48 is None:
263
+ v48 = torch.empty((b, s, 48, 128), device=x.device, dtype=torch.bfloat16)
264
+ has_bias = bias is not None
265
+ if bias is None:
266
+ bias = _empty_bias_like(x)
267
+ ops.causal_conv1d_update_chunk_parallel_gqa_bf16(
268
+ x, w, bias, state, q16, k16, v48, bool(has_bias), bool(apply_silu)
269
+ )
270
+ return q16, k16, v48
271
+
272
+
273
+ def causal_conv1d_update_steps_gqa_bf16(
274
+ x: torch.Tensor,
275
+ w: torch.Tensor,
276
+ state: torch.Tensor,
277
+ bias: torch.Tensor,
278
+ *,
279
+ apply_silu: bool = True,
280
+ q16: Optional[torch.Tensor] = None,
281
+ k16: Optional[torch.Tensor] = None,
282
+ v48: Optional[torch.Tensor] = None,
283
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
284
+ s = x.shape[0]
285
+ if q16 is None:
286
+ q16 = torch.empty((s, 2048), device=x.device, dtype=torch.bfloat16)
287
+ if k16 is None:
288
+ k16 = torch.empty_like(q16)
289
+ if v48 is None:
290
+ v48 = torch.empty((s, 6144), device=x.device, dtype=torch.bfloat16)
291
+ ops.causal_conv1d_update_steps_gqa_bf16(
292
+ x, w, bias, state, q16, k16, v48, bool(apply_silu)
293
+ )
294
+ return q16, k16, v48
295
+
296
+
297
+ __all__ = [
298
+ "causal_conv1d_bf16",
299
+ "causal_conv1d_update_bf16",
300
+ "causal_conv1d_update_inout_bf16",
301
+ "causal_conv1d_update_chunk_bf16",
302
+ "causal_conv1d_update_chunk_parallel_bf16",
303
+ "causal_conv1d_update_chunk_parallel_gqa_bf16",
304
+ "causal_conv1d_update_steps_gqa_bf16",
305
+ ]
build/torch211-cxx11-cu128-x86_64-linux/_causal_conv1d_state_cuda_7de0b39.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71eb4543729a3c6625a72ac2f819c15a210cf9bce05b34d4e8a67460cee0bc1f
3
+ size 1293160
build/torch211-cxx11-cu128-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_state_cuda_7de0b39
3
+ ops = torch.ops._causal_conv1d_state_cuda_7de0b39
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_state_cuda_7de0b39::{op_name}"
build/torch211-cxx11-cu128-x86_64-linux/causal_conv1d_state/__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,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d-state",
3
+ "id": "_causal_conv1d_state_cuda_7de0b39",
4
+ "version": 2,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "10.1",
12
+ "12.0+PTX",
13
+ "7.0",
14
+ "7.2",
15
+ "7.5",
16
+ "8.0",
17
+ "8.6",
18
+ "8.7",
19
+ "8.9",
20
+ "9.0"
21
+ ]
22
+ }
23
+ }
build/torch211-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT causal Conv1D state 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
+ def _empty_bias_like(x: torch.Tensor) -> torch.Tensor:
13
+ return torch.empty((0,), device=x.device, dtype=torch.bfloat16)
14
+
15
+
16
+ def _check_conv_shapes(x: torch.Tensor, w: torch.Tensor, bias: torch.Tensor, has_bias: bool, out: torch.Tensor) -> None:
17
+ if x.dim() != 3:
18
+ raise RuntimeError("x must have shape (B,S,C)")
19
+ if w.dim() != 2 or w.shape[0] != x.shape[2] or w.shape[1] < 2 or w.shape[1] > 8:
20
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
21
+ if has_bias and bias.shape != (x.shape[2],):
22
+ raise RuntimeError("bias must have shape (C,)")
23
+ if out.shape != x.shape:
24
+ raise RuntimeError("out must match x shape")
25
+
26
+
27
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_bf16"))
28
+ def _causal_conv1d_bf16_fake(
29
+ x: torch.Tensor,
30
+ w: torch.Tensor,
31
+ bias: torch.Tensor,
32
+ out: torch.Tensor,
33
+ has_bias: bool = True,
34
+ apply_silu: bool = True,
35
+ ) -> None:
36
+ _check_conv_shapes(x, w, bias, has_bias, out)
37
+ return None
38
+
39
+
40
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_bf16"))
41
+ def _causal_conv1d_update_bf16_fake(
42
+ x_new: torch.Tensor,
43
+ w: torch.Tensor,
44
+ bias: torch.Tensor,
45
+ state: torch.Tensor,
46
+ out: torch.Tensor,
47
+ has_bias: bool = True,
48
+ apply_silu: bool = True,
49
+ ) -> None:
50
+ if x_new.dim() != 2:
51
+ raise RuntimeError("x_new must have shape (B,C)")
52
+ b, c = x_new.shape
53
+ if w.dim() != 2 or w.shape[0] != c or w.shape[1] < 2 or w.shape[1] > 8:
54
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
55
+ if has_bias and bias.shape != (c,):
56
+ raise RuntimeError("bias must have shape (C,)")
57
+ if state.shape != (b, c, w.shape[1] - 1):
58
+ raise RuntimeError("state must have shape (B,C,K-1)")
59
+ if out.shape != x_new.shape:
60
+ raise RuntimeError("out must match x_new shape")
61
+ return None
62
+
63
+
64
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_inout_bf16"))
65
+ def _causal_conv1d_update_inout_bf16_fake(
66
+ x_new: torch.Tensor,
67
+ w: torch.Tensor,
68
+ bias: torch.Tensor,
69
+ state_in: torch.Tensor,
70
+ state_out: torch.Tensor,
71
+ out: torch.Tensor,
72
+ has_bias: bool = True,
73
+ apply_silu: bool = True,
74
+ ) -> None:
75
+ _causal_conv1d_update_bf16_fake(x_new, w, bias, state_in, out, has_bias, apply_silu)
76
+ if state_out.shape != state_in.shape:
77
+ raise RuntimeError("state_out shape mismatch")
78
+ return None
79
+
80
+
81
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_bf16"))
82
+ def _causal_conv1d_update_chunk_bf16_fake(
83
+ x: torch.Tensor,
84
+ w: torch.Tensor,
85
+ bias: torch.Tensor,
86
+ state: torch.Tensor,
87
+ out: torch.Tensor,
88
+ has_bias: bool = True,
89
+ apply_silu: bool = True,
90
+ ) -> None:
91
+ _check_conv_shapes(x, w, bias, has_bias, out)
92
+ if state.shape != (x.shape[0], x.shape[2], w.shape[1] - 1):
93
+ raise RuntimeError("state must have shape (B,C,K-1)")
94
+ return None
95
+
96
+
97
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_bf16"))
98
+ def _causal_conv1d_update_chunk_parallel_bf16_fake(
99
+ x: torch.Tensor,
100
+ w: torch.Tensor,
101
+ bias: torch.Tensor,
102
+ state: torch.Tensor,
103
+ out: torch.Tensor,
104
+ has_bias: bool = True,
105
+ apply_silu: bool = True,
106
+ ) -> None:
107
+ _causal_conv1d_update_chunk_bf16_fake(x, w, bias, state, out, has_bias, apply_silu)
108
+ return None
109
+
110
+
111
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_gqa_bf16"))
112
+ def _causal_conv1d_update_chunk_parallel_gqa_bf16_fake(
113
+ x: torch.Tensor,
114
+ w: torch.Tensor,
115
+ bias: torch.Tensor,
116
+ state: torch.Tensor,
117
+ q16: torch.Tensor,
118
+ k16: torch.Tensor,
119
+ v48: torch.Tensor,
120
+ has_bias: bool = True,
121
+ apply_silu: bool = True,
122
+ ) -> None:
123
+ if x.dim() != 3 or x.shape[2] != 10240:
124
+ raise RuntimeError("GQA split variant expects x shape (B,S,10240)")
125
+ if w.shape != (10240, w.shape[1]) or w.shape[1] < 2 or w.shape[1] > 8:
126
+ raise RuntimeError("w must have shape (10240,K), 2 <= K <= 8")
127
+ b, s, _ = x.shape
128
+ if state.shape != (b, 10240, w.shape[1] - 1):
129
+ raise RuntimeError("state must have shape (B,10240,K-1)")
130
+ if q16.shape != (b, s, 16, 128) or k16.shape != q16.shape or v48.shape != (b, s, 48, 128):
131
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
132
+ if has_bias and bias.shape != (10240,):
133
+ raise RuntimeError("bias must have shape (10240,)")
134
+ return None
135
+
136
+
137
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_steps_gqa_bf16"))
138
+ def _causal_conv1d_update_steps_gqa_bf16_fake(
139
+ x, w, bias, state, q16, k16, v48, apply_silu: bool = True
140
+ ) -> None:
141
+ del apply_silu
142
+ if x.dim() != 2 or x.shape[1] != 10240:
143
+ raise RuntimeError("x must have shape (S,10240)")
144
+ s = x.shape[0]
145
+ if w.shape != (10240, 4) or bias.shape != (10240,) or state.shape != (10240, 3):
146
+ raise RuntimeError("w/bias/state shape contract failed")
147
+ if q16.shape != (s, 2048) or k16.shape != q16.shape or v48.shape != (s, 6144):
148
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
149
+ return None
150
+
151
+
152
+ def causal_conv1d_bf16(
153
+ x: torch.Tensor,
154
+ w: torch.Tensor,
155
+ bias: Optional[torch.Tensor] = None,
156
+ *,
157
+ apply_silu: bool = True,
158
+ out: Optional[torch.Tensor] = None,
159
+ ) -> torch.Tensor:
160
+ if out is None:
161
+ out = torch.empty_like(x)
162
+ has_bias = bias is not None
163
+ if bias is None:
164
+ bias = _empty_bias_like(x)
165
+ ops.causal_conv1d_bf16(x, w, bias, out, bool(has_bias), bool(apply_silu))
166
+ return out
167
+
168
+
169
+ def causal_conv1d_update_bf16(
170
+ x_new: torch.Tensor,
171
+ w: torch.Tensor,
172
+ state: torch.Tensor,
173
+ bias: Optional[torch.Tensor] = None,
174
+ *,
175
+ apply_silu: bool = True,
176
+ out: Optional[torch.Tensor] = None,
177
+ ) -> torch.Tensor:
178
+ if out is None:
179
+ out = torch.empty_like(x_new)
180
+ has_bias = bias is not None
181
+ if bias is None:
182
+ bias = _empty_bias_like(x_new)
183
+ ops.causal_conv1d_update_bf16(x_new, w, bias, state, out, bool(has_bias), bool(apply_silu))
184
+ return out
185
+
186
+
187
+ def causal_conv1d_update_inout_bf16(
188
+ x_new: torch.Tensor,
189
+ w: torch.Tensor,
190
+ state_in: torch.Tensor,
191
+ bias: Optional[torch.Tensor] = None,
192
+ *,
193
+ apply_silu: bool = True,
194
+ out: Optional[torch.Tensor] = None,
195
+ state_out: Optional[torch.Tensor] = None,
196
+ ) -> tuple[torch.Tensor, torch.Tensor]:
197
+ if out is None:
198
+ out = torch.empty_like(x_new)
199
+ if state_out is None:
200
+ state_out = torch.empty_like(state_in)
201
+ has_bias = bias is not None
202
+ if bias is None:
203
+ bias = _empty_bias_like(x_new)
204
+ ops.causal_conv1d_update_inout_bf16(
205
+ x_new, w, bias, state_in, state_out, out, bool(has_bias), bool(apply_silu)
206
+ )
207
+ return out, state_out
208
+
209
+
210
+ def causal_conv1d_update_chunk_bf16(
211
+ x: torch.Tensor,
212
+ w: torch.Tensor,
213
+ state: torch.Tensor,
214
+ bias: Optional[torch.Tensor] = None,
215
+ *,
216
+ apply_silu: bool = True,
217
+ out: Optional[torch.Tensor] = None,
218
+ ) -> torch.Tensor:
219
+ if out is None:
220
+ out = torch.empty_like(x)
221
+ has_bias = bias is not None
222
+ if bias is None:
223
+ bias = _empty_bias_like(x)
224
+ ops.causal_conv1d_update_chunk_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
225
+ return out
226
+
227
+
228
+ def causal_conv1d_update_chunk_parallel_bf16(
229
+ x: torch.Tensor,
230
+ w: torch.Tensor,
231
+ state: torch.Tensor,
232
+ bias: Optional[torch.Tensor] = None,
233
+ *,
234
+ apply_silu: bool = True,
235
+ out: Optional[torch.Tensor] = None,
236
+ ) -> torch.Tensor:
237
+ if out is None:
238
+ out = torch.empty_like(x)
239
+ has_bias = bias is not None
240
+ if bias is None:
241
+ bias = _empty_bias_like(x)
242
+ ops.causal_conv1d_update_chunk_parallel_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
243
+ return out
244
+
245
+
246
+ def causal_conv1d_update_chunk_parallel_gqa_bf16(
247
+ x: torch.Tensor,
248
+ w: torch.Tensor,
249
+ state: torch.Tensor,
250
+ bias: Optional[torch.Tensor] = None,
251
+ *,
252
+ apply_silu: bool = True,
253
+ q16: Optional[torch.Tensor] = None,
254
+ k16: Optional[torch.Tensor] = None,
255
+ v48: Optional[torch.Tensor] = None,
256
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
257
+ b, s, _ = x.shape
258
+ if q16 is None:
259
+ q16 = torch.empty((b, s, 16, 128), device=x.device, dtype=torch.bfloat16)
260
+ if k16 is None:
261
+ k16 = torch.empty_like(q16)
262
+ if v48 is None:
263
+ v48 = torch.empty((b, s, 48, 128), device=x.device, dtype=torch.bfloat16)
264
+ has_bias = bias is not None
265
+ if bias is None:
266
+ bias = _empty_bias_like(x)
267
+ ops.causal_conv1d_update_chunk_parallel_gqa_bf16(
268
+ x, w, bias, state, q16, k16, v48, bool(has_bias), bool(apply_silu)
269
+ )
270
+ return q16, k16, v48
271
+
272
+
273
+ def causal_conv1d_update_steps_gqa_bf16(
274
+ x: torch.Tensor,
275
+ w: torch.Tensor,
276
+ state: torch.Tensor,
277
+ bias: torch.Tensor,
278
+ *,
279
+ apply_silu: bool = True,
280
+ q16: Optional[torch.Tensor] = None,
281
+ k16: Optional[torch.Tensor] = None,
282
+ v48: Optional[torch.Tensor] = None,
283
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
284
+ s = x.shape[0]
285
+ if q16 is None:
286
+ q16 = torch.empty((s, 2048), device=x.device, dtype=torch.bfloat16)
287
+ if k16 is None:
288
+ k16 = torch.empty_like(q16)
289
+ if v48 is None:
290
+ v48 = torch.empty((s, 6144), device=x.device, dtype=torch.bfloat16)
291
+ ops.causal_conv1d_update_steps_gqa_bf16(
292
+ x, w, bias, state, q16, k16, v48, bool(apply_silu)
293
+ )
294
+ return q16, k16, v48
295
+
296
+
297
+ __all__ = [
298
+ "causal_conv1d_bf16",
299
+ "causal_conv1d_update_bf16",
300
+ "causal_conv1d_update_inout_bf16",
301
+ "causal_conv1d_update_chunk_bf16",
302
+ "causal_conv1d_update_chunk_parallel_bf16",
303
+ "causal_conv1d_update_chunk_parallel_gqa_bf16",
304
+ "causal_conv1d_update_steps_gqa_bf16",
305
+ ]
build/torch211-cxx11-cu130-x86_64-linux/_causal_conv1d_state_cuda_7de0b39.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:943896d2b700a814dfcba3d8de8c787781616dc8febd96bc53a3686b17cc407d
3
+ size 1250080
build/torch211-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_state_cuda_7de0b39
3
+ ops = torch.ops._causal_conv1d_state_cuda_7de0b39
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_state_cuda_7de0b39::{op_name}"
build/torch211-cxx11-cu130-x86_64-linux/causal_conv1d_state/__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,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d-state",
3
+ "id": "_causal_conv1d_state_cuda_7de0b39",
4
+ "version": 2,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "11.0",
12
+ "12.0",
13
+ "12.1+PTX",
14
+ "7.5",
15
+ "8.0",
16
+ "8.6",
17
+ "8.7",
18
+ "8.9",
19
+ "9.0"
20
+ ]
21
+ }
22
+ }
build/torch212-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT causal Conv1D state 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
+ def _empty_bias_like(x: torch.Tensor) -> torch.Tensor:
13
+ return torch.empty((0,), device=x.device, dtype=torch.bfloat16)
14
+
15
+
16
+ def _check_conv_shapes(x: torch.Tensor, w: torch.Tensor, bias: torch.Tensor, has_bias: bool, out: torch.Tensor) -> None:
17
+ if x.dim() != 3:
18
+ raise RuntimeError("x must have shape (B,S,C)")
19
+ if w.dim() != 2 or w.shape[0] != x.shape[2] or w.shape[1] < 2 or w.shape[1] > 8:
20
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
21
+ if has_bias and bias.shape != (x.shape[2],):
22
+ raise RuntimeError("bias must have shape (C,)")
23
+ if out.shape != x.shape:
24
+ raise RuntimeError("out must match x shape")
25
+
26
+
27
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_bf16"))
28
+ def _causal_conv1d_bf16_fake(
29
+ x: torch.Tensor,
30
+ w: torch.Tensor,
31
+ bias: torch.Tensor,
32
+ out: torch.Tensor,
33
+ has_bias: bool = True,
34
+ apply_silu: bool = True,
35
+ ) -> None:
36
+ _check_conv_shapes(x, w, bias, has_bias, out)
37
+ return None
38
+
39
+
40
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_bf16"))
41
+ def _causal_conv1d_update_bf16_fake(
42
+ x_new: torch.Tensor,
43
+ w: torch.Tensor,
44
+ bias: torch.Tensor,
45
+ state: torch.Tensor,
46
+ out: torch.Tensor,
47
+ has_bias: bool = True,
48
+ apply_silu: bool = True,
49
+ ) -> None:
50
+ if x_new.dim() != 2:
51
+ raise RuntimeError("x_new must have shape (B,C)")
52
+ b, c = x_new.shape
53
+ if w.dim() != 2 or w.shape[0] != c or w.shape[1] < 2 or w.shape[1] > 8:
54
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
55
+ if has_bias and bias.shape != (c,):
56
+ raise RuntimeError("bias must have shape (C,)")
57
+ if state.shape != (b, c, w.shape[1] - 1):
58
+ raise RuntimeError("state must have shape (B,C,K-1)")
59
+ if out.shape != x_new.shape:
60
+ raise RuntimeError("out must match x_new shape")
61
+ return None
62
+
63
+
64
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_inout_bf16"))
65
+ def _causal_conv1d_update_inout_bf16_fake(
66
+ x_new: torch.Tensor,
67
+ w: torch.Tensor,
68
+ bias: torch.Tensor,
69
+ state_in: torch.Tensor,
70
+ state_out: torch.Tensor,
71
+ out: torch.Tensor,
72
+ has_bias: bool = True,
73
+ apply_silu: bool = True,
74
+ ) -> None:
75
+ _causal_conv1d_update_bf16_fake(x_new, w, bias, state_in, out, has_bias, apply_silu)
76
+ if state_out.shape != state_in.shape:
77
+ raise RuntimeError("state_out shape mismatch")
78
+ return None
79
+
80
+
81
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_bf16"))
82
+ def _causal_conv1d_update_chunk_bf16_fake(
83
+ x: torch.Tensor,
84
+ w: torch.Tensor,
85
+ bias: torch.Tensor,
86
+ state: torch.Tensor,
87
+ out: torch.Tensor,
88
+ has_bias: bool = True,
89
+ apply_silu: bool = True,
90
+ ) -> None:
91
+ _check_conv_shapes(x, w, bias, has_bias, out)
92
+ if state.shape != (x.shape[0], x.shape[2], w.shape[1] - 1):
93
+ raise RuntimeError("state must have shape (B,C,K-1)")
94
+ return None
95
+
96
+
97
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_bf16"))
98
+ def _causal_conv1d_update_chunk_parallel_bf16_fake(
99
+ x: torch.Tensor,
100
+ w: torch.Tensor,
101
+ bias: torch.Tensor,
102
+ state: torch.Tensor,
103
+ out: torch.Tensor,
104
+ has_bias: bool = True,
105
+ apply_silu: bool = True,
106
+ ) -> None:
107
+ _causal_conv1d_update_chunk_bf16_fake(x, w, bias, state, out, has_bias, apply_silu)
108
+ return None
109
+
110
+
111
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_gqa_bf16"))
112
+ def _causal_conv1d_update_chunk_parallel_gqa_bf16_fake(
113
+ x: torch.Tensor,
114
+ w: torch.Tensor,
115
+ bias: torch.Tensor,
116
+ state: torch.Tensor,
117
+ q16: torch.Tensor,
118
+ k16: torch.Tensor,
119
+ v48: torch.Tensor,
120
+ has_bias: bool = True,
121
+ apply_silu: bool = True,
122
+ ) -> None:
123
+ if x.dim() != 3 or x.shape[2] != 10240:
124
+ raise RuntimeError("GQA split variant expects x shape (B,S,10240)")
125
+ if w.shape != (10240, w.shape[1]) or w.shape[1] < 2 or w.shape[1] > 8:
126
+ raise RuntimeError("w must have shape (10240,K), 2 <= K <= 8")
127
+ b, s, _ = x.shape
128
+ if state.shape != (b, 10240, w.shape[1] - 1):
129
+ raise RuntimeError("state must have shape (B,10240,K-1)")
130
+ if q16.shape != (b, s, 16, 128) or k16.shape != q16.shape or v48.shape != (b, s, 48, 128):
131
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
132
+ if has_bias and bias.shape != (10240,):
133
+ raise RuntimeError("bias must have shape (10240,)")
134
+ return None
135
+
136
+
137
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_steps_gqa_bf16"))
138
+ def _causal_conv1d_update_steps_gqa_bf16_fake(
139
+ x, w, bias, state, q16, k16, v48, apply_silu: bool = True
140
+ ) -> None:
141
+ del apply_silu
142
+ if x.dim() != 2 or x.shape[1] != 10240:
143
+ raise RuntimeError("x must have shape (S,10240)")
144
+ s = x.shape[0]
145
+ if w.shape != (10240, 4) or bias.shape != (10240,) or state.shape != (10240, 3):
146
+ raise RuntimeError("w/bias/state shape contract failed")
147
+ if q16.shape != (s, 2048) or k16.shape != q16.shape or v48.shape != (s, 6144):
148
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
149
+ return None
150
+
151
+
152
+ def causal_conv1d_bf16(
153
+ x: torch.Tensor,
154
+ w: torch.Tensor,
155
+ bias: Optional[torch.Tensor] = None,
156
+ *,
157
+ apply_silu: bool = True,
158
+ out: Optional[torch.Tensor] = None,
159
+ ) -> torch.Tensor:
160
+ if out is None:
161
+ out = torch.empty_like(x)
162
+ has_bias = bias is not None
163
+ if bias is None:
164
+ bias = _empty_bias_like(x)
165
+ ops.causal_conv1d_bf16(x, w, bias, out, bool(has_bias), bool(apply_silu))
166
+ return out
167
+
168
+
169
+ def causal_conv1d_update_bf16(
170
+ x_new: torch.Tensor,
171
+ w: torch.Tensor,
172
+ state: torch.Tensor,
173
+ bias: Optional[torch.Tensor] = None,
174
+ *,
175
+ apply_silu: bool = True,
176
+ out: Optional[torch.Tensor] = None,
177
+ ) -> torch.Tensor:
178
+ if out is None:
179
+ out = torch.empty_like(x_new)
180
+ has_bias = bias is not None
181
+ if bias is None:
182
+ bias = _empty_bias_like(x_new)
183
+ ops.causal_conv1d_update_bf16(x_new, w, bias, state, out, bool(has_bias), bool(apply_silu))
184
+ return out
185
+
186
+
187
+ def causal_conv1d_update_inout_bf16(
188
+ x_new: torch.Tensor,
189
+ w: torch.Tensor,
190
+ state_in: torch.Tensor,
191
+ bias: Optional[torch.Tensor] = None,
192
+ *,
193
+ apply_silu: bool = True,
194
+ out: Optional[torch.Tensor] = None,
195
+ state_out: Optional[torch.Tensor] = None,
196
+ ) -> tuple[torch.Tensor, torch.Tensor]:
197
+ if out is None:
198
+ out = torch.empty_like(x_new)
199
+ if state_out is None:
200
+ state_out = torch.empty_like(state_in)
201
+ has_bias = bias is not None
202
+ if bias is None:
203
+ bias = _empty_bias_like(x_new)
204
+ ops.causal_conv1d_update_inout_bf16(
205
+ x_new, w, bias, state_in, state_out, out, bool(has_bias), bool(apply_silu)
206
+ )
207
+ return out, state_out
208
+
209
+
210
+ def causal_conv1d_update_chunk_bf16(
211
+ x: torch.Tensor,
212
+ w: torch.Tensor,
213
+ state: torch.Tensor,
214
+ bias: Optional[torch.Tensor] = None,
215
+ *,
216
+ apply_silu: bool = True,
217
+ out: Optional[torch.Tensor] = None,
218
+ ) -> torch.Tensor:
219
+ if out is None:
220
+ out = torch.empty_like(x)
221
+ has_bias = bias is not None
222
+ if bias is None:
223
+ bias = _empty_bias_like(x)
224
+ ops.causal_conv1d_update_chunk_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
225
+ return out
226
+
227
+
228
+ def causal_conv1d_update_chunk_parallel_bf16(
229
+ x: torch.Tensor,
230
+ w: torch.Tensor,
231
+ state: torch.Tensor,
232
+ bias: Optional[torch.Tensor] = None,
233
+ *,
234
+ apply_silu: bool = True,
235
+ out: Optional[torch.Tensor] = None,
236
+ ) -> torch.Tensor:
237
+ if out is None:
238
+ out = torch.empty_like(x)
239
+ has_bias = bias is not None
240
+ if bias is None:
241
+ bias = _empty_bias_like(x)
242
+ ops.causal_conv1d_update_chunk_parallel_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
243
+ return out
244
+
245
+
246
+ def causal_conv1d_update_chunk_parallel_gqa_bf16(
247
+ x: torch.Tensor,
248
+ w: torch.Tensor,
249
+ state: torch.Tensor,
250
+ bias: Optional[torch.Tensor] = None,
251
+ *,
252
+ apply_silu: bool = True,
253
+ q16: Optional[torch.Tensor] = None,
254
+ k16: Optional[torch.Tensor] = None,
255
+ v48: Optional[torch.Tensor] = None,
256
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
257
+ b, s, _ = x.shape
258
+ if q16 is None:
259
+ q16 = torch.empty((b, s, 16, 128), device=x.device, dtype=torch.bfloat16)
260
+ if k16 is None:
261
+ k16 = torch.empty_like(q16)
262
+ if v48 is None:
263
+ v48 = torch.empty((b, s, 48, 128), device=x.device, dtype=torch.bfloat16)
264
+ has_bias = bias is not None
265
+ if bias is None:
266
+ bias = _empty_bias_like(x)
267
+ ops.causal_conv1d_update_chunk_parallel_gqa_bf16(
268
+ x, w, bias, state, q16, k16, v48, bool(has_bias), bool(apply_silu)
269
+ )
270
+ return q16, k16, v48
271
+
272
+
273
+ def causal_conv1d_update_steps_gqa_bf16(
274
+ x: torch.Tensor,
275
+ w: torch.Tensor,
276
+ state: torch.Tensor,
277
+ bias: torch.Tensor,
278
+ *,
279
+ apply_silu: bool = True,
280
+ q16: Optional[torch.Tensor] = None,
281
+ k16: Optional[torch.Tensor] = None,
282
+ v48: Optional[torch.Tensor] = None,
283
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
284
+ s = x.shape[0]
285
+ if q16 is None:
286
+ q16 = torch.empty((s, 2048), device=x.device, dtype=torch.bfloat16)
287
+ if k16 is None:
288
+ k16 = torch.empty_like(q16)
289
+ if v48 is None:
290
+ v48 = torch.empty((s, 6144), device=x.device, dtype=torch.bfloat16)
291
+ ops.causal_conv1d_update_steps_gqa_bf16(
292
+ x, w, bias, state, q16, k16, v48, bool(apply_silu)
293
+ )
294
+ return q16, k16, v48
295
+
296
+
297
+ __all__ = [
298
+ "causal_conv1d_bf16",
299
+ "causal_conv1d_update_bf16",
300
+ "causal_conv1d_update_inout_bf16",
301
+ "causal_conv1d_update_chunk_bf16",
302
+ "causal_conv1d_update_chunk_parallel_bf16",
303
+ "causal_conv1d_update_chunk_parallel_gqa_bf16",
304
+ "causal_conv1d_update_steps_gqa_bf16",
305
+ ]
build/torch212-cxx11-cu130-x86_64-linux/_causal_conv1d_state_cuda_7de0b39.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44c7f76f9ecb2e63ff2b622140c06fe47676ee8cafbfbc8c53dfa3d9b1b57809
3
+ size 1256392
build/torch212-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_state_cuda_7de0b39
3
+ ops = torch.ops._causal_conv1d_state_cuda_7de0b39
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_state_cuda_7de0b39::{op_name}"
build/torch212-cxx11-cu130-x86_64-linux/causal_conv1d_state/__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,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d-state",
3
+ "id": "_causal_conv1d_state_cuda_7de0b39",
4
+ "version": 2,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "11.0",
12
+ "12.0",
13
+ "12.1+PTX",
14
+ "7.5",
15
+ "8.0",
16
+ "8.6",
17
+ "8.7",
18
+ "8.9",
19
+ "9.0"
20
+ ]
21
+ }
22
+ }
build/torch212-cxx11-cu132-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,305 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FlashRT causal Conv1D state 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
+ def _empty_bias_like(x: torch.Tensor) -> torch.Tensor:
13
+ return torch.empty((0,), device=x.device, dtype=torch.bfloat16)
14
+
15
+
16
+ def _check_conv_shapes(x: torch.Tensor, w: torch.Tensor, bias: torch.Tensor, has_bias: bool, out: torch.Tensor) -> None:
17
+ if x.dim() != 3:
18
+ raise RuntimeError("x must have shape (B,S,C)")
19
+ if w.dim() != 2 or w.shape[0] != x.shape[2] or w.shape[1] < 2 or w.shape[1] > 8:
20
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
21
+ if has_bias and bias.shape != (x.shape[2],):
22
+ raise RuntimeError("bias must have shape (C,)")
23
+ if out.shape != x.shape:
24
+ raise RuntimeError("out must match x shape")
25
+
26
+
27
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_bf16"))
28
+ def _causal_conv1d_bf16_fake(
29
+ x: torch.Tensor,
30
+ w: torch.Tensor,
31
+ bias: torch.Tensor,
32
+ out: torch.Tensor,
33
+ has_bias: bool = True,
34
+ apply_silu: bool = True,
35
+ ) -> None:
36
+ _check_conv_shapes(x, w, bias, has_bias, out)
37
+ return None
38
+
39
+
40
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_bf16"))
41
+ def _causal_conv1d_update_bf16_fake(
42
+ x_new: torch.Tensor,
43
+ w: torch.Tensor,
44
+ bias: torch.Tensor,
45
+ state: torch.Tensor,
46
+ out: torch.Tensor,
47
+ has_bias: bool = True,
48
+ apply_silu: bool = True,
49
+ ) -> None:
50
+ if x_new.dim() != 2:
51
+ raise RuntimeError("x_new must have shape (B,C)")
52
+ b, c = x_new.shape
53
+ if w.dim() != 2 or w.shape[0] != c or w.shape[1] < 2 or w.shape[1] > 8:
54
+ raise RuntimeError("w must have shape (C,K), 2 <= K <= 8")
55
+ if has_bias and bias.shape != (c,):
56
+ raise RuntimeError("bias must have shape (C,)")
57
+ if state.shape != (b, c, w.shape[1] - 1):
58
+ raise RuntimeError("state must have shape (B,C,K-1)")
59
+ if out.shape != x_new.shape:
60
+ raise RuntimeError("out must match x_new shape")
61
+ return None
62
+
63
+
64
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_inout_bf16"))
65
+ def _causal_conv1d_update_inout_bf16_fake(
66
+ x_new: torch.Tensor,
67
+ w: torch.Tensor,
68
+ bias: torch.Tensor,
69
+ state_in: torch.Tensor,
70
+ state_out: torch.Tensor,
71
+ out: torch.Tensor,
72
+ has_bias: bool = True,
73
+ apply_silu: bool = True,
74
+ ) -> None:
75
+ _causal_conv1d_update_bf16_fake(x_new, w, bias, state_in, out, has_bias, apply_silu)
76
+ if state_out.shape != state_in.shape:
77
+ raise RuntimeError("state_out shape mismatch")
78
+ return None
79
+
80
+
81
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_bf16"))
82
+ def _causal_conv1d_update_chunk_bf16_fake(
83
+ x: torch.Tensor,
84
+ w: torch.Tensor,
85
+ bias: torch.Tensor,
86
+ state: torch.Tensor,
87
+ out: torch.Tensor,
88
+ has_bias: bool = True,
89
+ apply_silu: bool = True,
90
+ ) -> None:
91
+ _check_conv_shapes(x, w, bias, has_bias, out)
92
+ if state.shape != (x.shape[0], x.shape[2], w.shape[1] - 1):
93
+ raise RuntimeError("state must have shape (B,C,K-1)")
94
+ return None
95
+
96
+
97
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_bf16"))
98
+ def _causal_conv1d_update_chunk_parallel_bf16_fake(
99
+ x: torch.Tensor,
100
+ w: torch.Tensor,
101
+ bias: torch.Tensor,
102
+ state: torch.Tensor,
103
+ out: torch.Tensor,
104
+ has_bias: bool = True,
105
+ apply_silu: bool = True,
106
+ ) -> None:
107
+ _causal_conv1d_update_chunk_bf16_fake(x, w, bias, state, out, has_bias, apply_silu)
108
+ return None
109
+
110
+
111
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_chunk_parallel_gqa_bf16"))
112
+ def _causal_conv1d_update_chunk_parallel_gqa_bf16_fake(
113
+ x: torch.Tensor,
114
+ w: torch.Tensor,
115
+ bias: torch.Tensor,
116
+ state: torch.Tensor,
117
+ q16: torch.Tensor,
118
+ k16: torch.Tensor,
119
+ v48: torch.Tensor,
120
+ has_bias: bool = True,
121
+ apply_silu: bool = True,
122
+ ) -> None:
123
+ if x.dim() != 3 or x.shape[2] != 10240:
124
+ raise RuntimeError("GQA split variant expects x shape (B,S,10240)")
125
+ if w.shape != (10240, w.shape[1]) or w.shape[1] < 2 or w.shape[1] > 8:
126
+ raise RuntimeError("w must have shape (10240,K), 2 <= K <= 8")
127
+ b, s, _ = x.shape
128
+ if state.shape != (b, 10240, w.shape[1] - 1):
129
+ raise RuntimeError("state must have shape (B,10240,K-1)")
130
+ if q16.shape != (b, s, 16, 128) or k16.shape != q16.shape or v48.shape != (b, s, 48, 128):
131
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
132
+ if has_bias and bias.shape != (10240,):
133
+ raise RuntimeError("bias must have shape (10240,)")
134
+ return None
135
+
136
+
137
+ @torch.library.register_fake(add_op_namespace_prefix("causal_conv1d_update_steps_gqa_bf16"))
138
+ def _causal_conv1d_update_steps_gqa_bf16_fake(
139
+ x, w, bias, state, q16, k16, v48, apply_silu: bool = True
140
+ ) -> None:
141
+ del apply_silu
142
+ if x.dim() != 2 or x.shape[1] != 10240:
143
+ raise RuntimeError("x must have shape (S,10240)")
144
+ s = x.shape[0]
145
+ if w.shape != (10240, 4) or bias.shape != (10240,) or state.shape != (10240, 3):
146
+ raise RuntimeError("w/bias/state shape contract failed")
147
+ if q16.shape != (s, 2048) or k16.shape != q16.shape or v48.shape != (s, 6144):
148
+ raise RuntimeError("q16/k16/v48 output shape mismatch")
149
+ return None
150
+
151
+
152
+ def causal_conv1d_bf16(
153
+ x: torch.Tensor,
154
+ w: torch.Tensor,
155
+ bias: Optional[torch.Tensor] = None,
156
+ *,
157
+ apply_silu: bool = True,
158
+ out: Optional[torch.Tensor] = None,
159
+ ) -> torch.Tensor:
160
+ if out is None:
161
+ out = torch.empty_like(x)
162
+ has_bias = bias is not None
163
+ if bias is None:
164
+ bias = _empty_bias_like(x)
165
+ ops.causal_conv1d_bf16(x, w, bias, out, bool(has_bias), bool(apply_silu))
166
+ return out
167
+
168
+
169
+ def causal_conv1d_update_bf16(
170
+ x_new: torch.Tensor,
171
+ w: torch.Tensor,
172
+ state: torch.Tensor,
173
+ bias: Optional[torch.Tensor] = None,
174
+ *,
175
+ apply_silu: bool = True,
176
+ out: Optional[torch.Tensor] = None,
177
+ ) -> torch.Tensor:
178
+ if out is None:
179
+ out = torch.empty_like(x_new)
180
+ has_bias = bias is not None
181
+ if bias is None:
182
+ bias = _empty_bias_like(x_new)
183
+ ops.causal_conv1d_update_bf16(x_new, w, bias, state, out, bool(has_bias), bool(apply_silu))
184
+ return out
185
+
186
+
187
+ def causal_conv1d_update_inout_bf16(
188
+ x_new: torch.Tensor,
189
+ w: torch.Tensor,
190
+ state_in: torch.Tensor,
191
+ bias: Optional[torch.Tensor] = None,
192
+ *,
193
+ apply_silu: bool = True,
194
+ out: Optional[torch.Tensor] = None,
195
+ state_out: Optional[torch.Tensor] = None,
196
+ ) -> tuple[torch.Tensor, torch.Tensor]:
197
+ if out is None:
198
+ out = torch.empty_like(x_new)
199
+ if state_out is None:
200
+ state_out = torch.empty_like(state_in)
201
+ has_bias = bias is not None
202
+ if bias is None:
203
+ bias = _empty_bias_like(x_new)
204
+ ops.causal_conv1d_update_inout_bf16(
205
+ x_new, w, bias, state_in, state_out, out, bool(has_bias), bool(apply_silu)
206
+ )
207
+ return out, state_out
208
+
209
+
210
+ def causal_conv1d_update_chunk_bf16(
211
+ x: torch.Tensor,
212
+ w: torch.Tensor,
213
+ state: torch.Tensor,
214
+ bias: Optional[torch.Tensor] = None,
215
+ *,
216
+ apply_silu: bool = True,
217
+ out: Optional[torch.Tensor] = None,
218
+ ) -> torch.Tensor:
219
+ if out is None:
220
+ out = torch.empty_like(x)
221
+ has_bias = bias is not None
222
+ if bias is None:
223
+ bias = _empty_bias_like(x)
224
+ ops.causal_conv1d_update_chunk_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
225
+ return out
226
+
227
+
228
+ def causal_conv1d_update_chunk_parallel_bf16(
229
+ x: torch.Tensor,
230
+ w: torch.Tensor,
231
+ state: torch.Tensor,
232
+ bias: Optional[torch.Tensor] = None,
233
+ *,
234
+ apply_silu: bool = True,
235
+ out: Optional[torch.Tensor] = None,
236
+ ) -> torch.Tensor:
237
+ if out is None:
238
+ out = torch.empty_like(x)
239
+ has_bias = bias is not None
240
+ if bias is None:
241
+ bias = _empty_bias_like(x)
242
+ ops.causal_conv1d_update_chunk_parallel_bf16(x, w, bias, state, out, bool(has_bias), bool(apply_silu))
243
+ return out
244
+
245
+
246
+ def causal_conv1d_update_chunk_parallel_gqa_bf16(
247
+ x: torch.Tensor,
248
+ w: torch.Tensor,
249
+ state: torch.Tensor,
250
+ bias: Optional[torch.Tensor] = None,
251
+ *,
252
+ apply_silu: bool = True,
253
+ q16: Optional[torch.Tensor] = None,
254
+ k16: Optional[torch.Tensor] = None,
255
+ v48: Optional[torch.Tensor] = None,
256
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
257
+ b, s, _ = x.shape
258
+ if q16 is None:
259
+ q16 = torch.empty((b, s, 16, 128), device=x.device, dtype=torch.bfloat16)
260
+ if k16 is None:
261
+ k16 = torch.empty_like(q16)
262
+ if v48 is None:
263
+ v48 = torch.empty((b, s, 48, 128), device=x.device, dtype=torch.bfloat16)
264
+ has_bias = bias is not None
265
+ if bias is None:
266
+ bias = _empty_bias_like(x)
267
+ ops.causal_conv1d_update_chunk_parallel_gqa_bf16(
268
+ x, w, bias, state, q16, k16, v48, bool(has_bias), bool(apply_silu)
269
+ )
270
+ return q16, k16, v48
271
+
272
+
273
+ def causal_conv1d_update_steps_gqa_bf16(
274
+ x: torch.Tensor,
275
+ w: torch.Tensor,
276
+ state: torch.Tensor,
277
+ bias: torch.Tensor,
278
+ *,
279
+ apply_silu: bool = True,
280
+ q16: Optional[torch.Tensor] = None,
281
+ k16: Optional[torch.Tensor] = None,
282
+ v48: Optional[torch.Tensor] = None,
283
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
284
+ s = x.shape[0]
285
+ if q16 is None:
286
+ q16 = torch.empty((s, 2048), device=x.device, dtype=torch.bfloat16)
287
+ if k16 is None:
288
+ k16 = torch.empty_like(q16)
289
+ if v48 is None:
290
+ v48 = torch.empty((s, 6144), device=x.device, dtype=torch.bfloat16)
291
+ ops.causal_conv1d_update_steps_gqa_bf16(
292
+ x, w, bias, state, q16, k16, v48, bool(apply_silu)
293
+ )
294
+ return q16, k16, v48
295
+
296
+
297
+ __all__ = [
298
+ "causal_conv1d_bf16",
299
+ "causal_conv1d_update_bf16",
300
+ "causal_conv1d_update_inout_bf16",
301
+ "causal_conv1d_update_chunk_bf16",
302
+ "causal_conv1d_update_chunk_parallel_bf16",
303
+ "causal_conv1d_update_chunk_parallel_gqa_bf16",
304
+ "causal_conv1d_update_steps_gqa_bf16",
305
+ ]
build/torch212-cxx11-cu132-x86_64-linux/_causal_conv1d_state_cuda_7de0b39.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9212fc523105db6c9ad1ed857cb2d1c9ef6e89587982d9a9c580ff1cf7a6bc9
3
+ size 1264584
build/torch212-cxx11-cu132-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_state_cuda_7de0b39
3
+ ops = torch.ops._causal_conv1d_state_cuda_7de0b39
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_state_cuda_7de0b39::{op_name}"
build/torch212-cxx11-cu132-x86_64-linux/causal_conv1d_state/__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,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d-state",
3
+ "id": "_causal_conv1d_state_cuda_7de0b39",
4
+ "version": 2,
5
+ "license": "Apache-2.0",
6
+ "python-depends": [],
7
+ "backend": {
8
+ "type": "cuda",
9
+ "archs": [
10
+ "10.0",
11
+ "11.0",
12
+ "12.0",
13
+ "12.1+PTX",
14
+ "7.5",
15
+ "8.0",
16
+ "8.6",
17
+ "8.7",
18
+ "8.9",
19
+ "9.0"
20
+ ]
21
+ }
22
+ }