kernels-bot commited on
Commit
1f215a5
·
verified ·
1 Parent(s): 512a4a9

Uploaded using `kernel-builder`.

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. build/torch212-cxx11-cu126-x86_64-linux/__init__.py +12 -0
  2. build/torch212-cxx11-cu126-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  3. build/torch212-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  4. build/torch212-cxx11-cu126-x86_64-linux/causal_conv1d_interface.py +242 -0
  5. build/torch212-cxx11-cu126-x86_64-linux/causal_conv1d_varlen.py +86 -0
  6. build/torch212-cxx11-cu126-x86_64-linux/cpp_functions.py +96 -0
  7. build/torch212-cxx11-cu126-x86_64-linux/layers.py +50 -0
  8. build/torch212-cxx11-cu126-x86_64-linux/metadata.json +44 -0
  9. build/torch212-cxx11-cu126-x86_64-linux/metadata.json.sigstore +1 -0
  10. build/torch212-cxx11-cu130-x86_64-linux/__init__.py +12 -0
  11. build/torch212-cxx11-cu130-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  12. build/torch212-cxx11-cu130-x86_64-linux/_ops.py +9 -0
  13. build/torch212-cxx11-cu130-x86_64-linux/causal_conv1d_interface.py +242 -0
  14. build/torch212-cxx11-cu130-x86_64-linux/causal_conv1d_varlen.py +86 -0
  15. build/torch212-cxx11-cu130-x86_64-linux/cpp_functions.py +96 -0
  16. build/torch212-cxx11-cu130-x86_64-linux/layers.py +50 -0
  17. build/torch212-cxx11-cu130-x86_64-linux/metadata.json +47 -0
  18. build/torch212-cxx11-cu130-x86_64-linux/metadata.json.sigstore +1 -0
  19. build/torch212-cxx11-cu132-x86_64-linux/__init__.py +12 -0
  20. build/torch212-cxx11-cu132-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  21. build/torch212-cxx11-cu132-x86_64-linux/_ops.py +9 -0
  22. build/torch212-cxx11-cu132-x86_64-linux/causal_conv1d_interface.py +242 -0
  23. build/torch212-cxx11-cu132-x86_64-linux/causal_conv1d_varlen.py +86 -0
  24. build/torch212-cxx11-cu132-x86_64-linux/cpp_functions.py +96 -0
  25. build/torch212-cxx11-cu132-x86_64-linux/layers.py +50 -0
  26. build/torch212-cxx11-cu132-x86_64-linux/metadata.json +47 -0
  27. build/torch212-cxx11-cu132-x86_64-linux/metadata.json.sigstore +1 -0
  28. build/torch213-cxx11-cu126-x86_64-linux/__init__.py +12 -0
  29. build/torch213-cxx11-cu126-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  30. build/torch213-cxx11-cu126-x86_64-linux/_ops.py +9 -0
  31. build/torch213-cxx11-cu126-x86_64-linux/causal_conv1d_interface.py +242 -0
  32. build/torch213-cxx11-cu126-x86_64-linux/causal_conv1d_varlen.py +86 -0
  33. build/torch213-cxx11-cu126-x86_64-linux/cpp_functions.py +96 -0
  34. build/torch213-cxx11-cu126-x86_64-linux/layers.py +50 -0
  35. build/torch213-cxx11-cu126-x86_64-linux/metadata.json +44 -0
  36. build/torch213-cxx11-cu126-x86_64-linux/metadata.json.sigstore +1 -0
  37. build/torch213-cxx11-cu130-x86_64-linux/__init__.py +12 -0
  38. build/torch213-cxx11-cu130-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  39. build/torch213-cxx11-cu130-x86_64-linux/_ops.py +9 -0
  40. build/torch213-cxx11-cu130-x86_64-linux/causal_conv1d_interface.py +242 -0
  41. build/torch213-cxx11-cu130-x86_64-linux/causal_conv1d_varlen.py +86 -0
  42. build/torch213-cxx11-cu130-x86_64-linux/cpp_functions.py +96 -0
  43. build/torch213-cxx11-cu130-x86_64-linux/layers.py +50 -0
  44. build/torch213-cxx11-cu130-x86_64-linux/metadata.json +47 -0
  45. build/torch213-cxx11-cu130-x86_64-linux/metadata.json.sigstore +1 -0
  46. build/torch213-cxx11-cu132-x86_64-linux/__init__.py +12 -0
  47. build/torch213-cxx11-cu132-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  48. build/torch213-cxx11-cu132-x86_64-linux/_ops.py +9 -0
  49. build/torch213-cxx11-cu132-x86_64-linux/causal_conv1d_interface.py +242 -0
  50. build/torch213-cxx11-cu132-x86_64-linux/causal_conv1d_varlen.py +86 -0
build/torch212-cxx11-cu126-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+ from .causal_conv1d_interface import causal_conv1d_fn, causal_conv1d_update
3
+ from .causal_conv1d_varlen import causal_conv1d_varlen_states
4
+
5
+ __all__ = [
6
+ # wrappers
7
+ "layers",
8
+ # originals
9
+ "causal_conv1d_fn",
10
+ "causal_conv1d_update",
11
+ "causal_conv1d_varlen_states",
12
+ ]
build/torch212-cxx11-cu126-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f174415bc0621baf2c673f90cbd4a9087212e2a8d93e9d4ab661c27506ed9119
3
+ size 78812288
build/torch212-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_cuda_056e28b
3
+ ops = torch.ops._causal_conv1d_cuda_056e28b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_cuda_056e28b::{op_name}"
build/torch212-cxx11-cu126-x86_64-linux/causal_conv1d_interface.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ from .cpp_functions import causal_conv1d_fwd_function, causal_conv1d_bwd_function, causal_conv1d_update_function
7
+
8
+
9
+ class CausalConv1dFn(torch.autograd.Function):
10
+ @staticmethod
11
+ def forward(
12
+ ctx,
13
+ x,
14
+ weight,
15
+ bias=None,
16
+ seq_idx=None,
17
+ initial_states=None,
18
+ return_final_states=False,
19
+ final_states_out=None,
20
+ activation=None,
21
+ ):
22
+ if activation not in [None, "silu", "swish"]:
23
+ raise NotImplementedError("activation must be None, silu, or swish")
24
+ if x.stride(2) != 1 and x.stride(1) != 1:
25
+ x = x.contiguous()
26
+ bias = bias.contiguous() if bias is not None else None
27
+ if seq_idx is not None:
28
+ assert (
29
+ initial_states is None
30
+ ), "initial_states must be None if seq_idx is not None"
31
+ assert (
32
+ not return_final_states
33
+ ), "If seq_idx is not None, we don't return final_states_out"
34
+ seq_idx = seq_idx.contiguous() if seq_idx is not None else None
35
+ if initial_states is not None and (
36
+ initial_states.stride(2) != 1 and initial_states.stride(1) != 1
37
+ ):
38
+ initial_states = initial_states.contiguous()
39
+ if return_final_states:
40
+ assert (
41
+ x.stride(1) == 1
42
+ ), "Only channel-last layout support returning final_states_out"
43
+ if final_states_out is not None:
44
+ assert (
45
+ final_states_out.stride(2) == 1 or final_states_out.stride(1) == 1
46
+ )
47
+ else:
48
+ batch, dim, seqlen = x.shape
49
+ width = weight.shape[1]
50
+ final_states_out = torch.empty(
51
+ batch, width - 1, dim, device=x.device, dtype=x.dtype
52
+ ).transpose(1, 2)
53
+ else:
54
+ final_states_out = None
55
+ ctx.activation = activation in ["silu", "swish"]
56
+ out = causal_conv1d_fwd_function(
57
+ x, weight, bias, seq_idx, initial_states, final_states_out, ctx.activation
58
+ )
59
+ ctx.save_for_backward(x, weight, bias, seq_idx, initial_states)
60
+ ctx.return_final_states = return_final_states
61
+ ctx.return_dinitial_states = (
62
+ initial_states is not None and initial_states.requires_grad
63
+ )
64
+ return out if not return_final_states else (out, final_states_out)
65
+
66
+ @staticmethod
67
+ def backward(ctx, dout, *args):
68
+ x, weight, bias, seq_idx, initial_states = ctx.saved_tensors
69
+ dfinal_states = args[0] if ctx.return_final_states else None
70
+ if dout.stride(2) != 1 and dout.stride(1) != 1:
71
+ dout = dout.contiguous()
72
+ # The kernel supports passing in a pre-allocated dx (e.g., in case we want to fuse the
73
+ # backward of conv1d with the backward of chunk).
74
+ # Here we just pass in None and dx will be allocated in the C++ code.
75
+ dx, dweight, dbias, dinitial_states = causal_conv1d_bwd_function(
76
+ x,
77
+ weight,
78
+ bias,
79
+ dout,
80
+ seq_idx,
81
+ initial_states,
82
+ dfinal_states,
83
+ None,
84
+ ctx.return_dinitial_states,
85
+ ctx.activation,
86
+ )
87
+ return (
88
+ dx,
89
+ dweight,
90
+ dbias if bias is not None else None,
91
+ None,
92
+ dinitial_states if initial_states is not None else None,
93
+ None,
94
+ None,
95
+ None,
96
+ )
97
+
98
+
99
+ def causal_conv1d_fn(
100
+ x,
101
+ weight,
102
+ bias=None,
103
+ seq_idx=None,
104
+ initial_states=None,
105
+ return_final_states=False,
106
+ final_states_out=None,
107
+ activation=None,
108
+ ):
109
+ """
110
+ x: (batch, dim, seqlen)
111
+ weight: (dim, width)
112
+ bias: (dim,)
113
+ seq_idx: (batch, seqlen)
114
+ initial_states: (batch, dim, width - 1)
115
+ final_states_out: (batch, dim, width - 1), to be written to
116
+ activation: either None or "silu" or "swish"
117
+
118
+ out: (batch, dim, seqlen)
119
+ """
120
+ return CausalConv1dFn.apply(
121
+ x,
122
+ weight,
123
+ bias,
124
+ seq_idx,
125
+ initial_states,
126
+ return_final_states,
127
+ final_states_out,
128
+ activation,
129
+ )
130
+
131
+
132
+ def causal_conv1d_ref(
133
+ x,
134
+ weight,
135
+ bias=None,
136
+ initial_states=None,
137
+ return_final_states=False,
138
+ final_states_out=None,
139
+ activation=None,
140
+ ):
141
+ """
142
+ x: (batch, dim, seqlen)
143
+ weight: (dim, width)
144
+ bias: (dim,)
145
+ initial_states: (batch, dim, width - 1)
146
+ final_states_out: (batch, dim, width - 1)
147
+
148
+ out: (batch, dim, seqlen)
149
+ """
150
+ if activation not in [None, "silu", "swish"]:
151
+ raise NotImplementedError("activation must be None, silu, or swish")
152
+ dtype_in = x.dtype
153
+ x = x.to(weight.dtype)
154
+ seqlen = x.shape[-1]
155
+ dim, width = weight.shape
156
+ if initial_states is None:
157
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
158
+ else:
159
+ x = torch.cat([initial_states, x], dim=-1)
160
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=0, groups=dim)
161
+ out = out[..., :seqlen]
162
+ if return_final_states:
163
+ final_states = F.pad(x, (width - 1 - x.shape[-1], 0)).to(
164
+ dtype_in
165
+ ) # (batch, dim, width - 1)
166
+ if final_states_out is not None:
167
+ final_states_out.copy_(final_states)
168
+ else:
169
+ final_states_out = final_states
170
+ out = (out if activation is None else F.silu(out)).to(dtype=dtype_in)
171
+ return out if not return_final_states else (out, final_states_out)
172
+
173
+
174
+ def causal_conv1d_update(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None, conv_state_indices=None):
175
+ """
176
+ x: (batch, dim) or (batch, dim, seqlen)
177
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
178
+ weight: (dim, width)
179
+ bias: (dim,)
180
+ cache_seqlens: (batch,), dtype int32.
181
+ If not None, the conv_state is treated as a circular buffer.
182
+ The conv_state will be updated by copying x to the conv_state starting at the index
183
+ @cache_seqlens % state_len.
184
+ conv_state_indices: (batch,), dtype int32
185
+ If None, the conv_state is a larger tensor along the batch dim,
186
+ and we are selecting the batch coords specified by conv_state_indices.
187
+ Useful for a continuous batching scenario.
188
+
189
+ out: (batch, dim) or (batch, dim, seqlen)
190
+ """
191
+ if activation not in [None, "silu", "swish"]:
192
+ raise NotImplementedError("activation must be None, silu, or swish")
193
+ activation = activation in ["silu", "swish"]
194
+ unsqueeze = x.dim() == 2
195
+ if unsqueeze:
196
+ x = x.unsqueeze(-1)
197
+ out = causal_conv1d_update_function(
198
+ x, conv_state, weight, bias, activation, cache_seqlens, conv_state_indices
199
+ )
200
+ if unsqueeze:
201
+ out = out.squeeze(-1)
202
+ return out
203
+
204
+
205
+ def causal_conv1d_update_ref(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None):
206
+ """
207
+ x: (batch, dim) or (batch, dim, seqlen)
208
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
209
+ weight: (dim, width)
210
+ bias: (dim,)
211
+ cache_seqlens: (batch,), dtype int32.
212
+ If not None, the conv_state is treated as a circular buffer.
213
+ The conv_state will be updated by copying x to the conv_state starting at the index
214
+ @cache_seqlens % state_len before performing the convolution.
215
+
216
+ out: (batch, dim) or (batch, dim, seqlen)
217
+ """
218
+ if activation not in [None, "silu", "swish"]:
219
+ raise NotImplementedError("activation must be None, silu, or swish")
220
+ dtype_in = x.dtype
221
+ unsqueeze = x.dim() == 2
222
+ if unsqueeze:
223
+ x = x.unsqueeze(-1)
224
+ batch, dim, seqlen = x.shape
225
+ width = weight.shape[1]
226
+ state_len = conv_state.shape[-1]
227
+ assert conv_state.shape == (batch, dim, state_len)
228
+ assert weight.shape == (dim, width)
229
+ if cache_seqlens is None:
230
+ x_new = torch.cat([conv_state, x], dim=-1).to(weight.dtype) # (batch, dim, state_len + seqlen)
231
+ conv_state.copy_(x_new[:, :, -state_len:])
232
+ else:
233
+ width_idx = torch.arange(-(width - 1), 0, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
234
+ width_idx = torch.remainder(width_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
235
+ x_new = torch.cat([conv_state.gather(2, width_idx), x], dim=-1).to(weight.dtype)
236
+ copy_idx = torch.arange(seqlen, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
237
+ copy_idx = torch.remainder(copy_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
238
+ conv_state.scatter_(2, copy_idx, x)
239
+ out = F.conv1d(x_new, weight.unsqueeze(1), bias, padding=0, groups=dim)[:, :, -seqlen:]
240
+ if unsqueeze:
241
+ out = out.squeeze(-1)
242
+ return (out if activation is None else F.silu(out)).to(dtype=dtype_in)
build/torch212-cxx11-cu126-x86_64-linux/causal_conv1d_varlen.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor
3
+
4
+ import triton
5
+ import triton.language as tl
6
+
7
+
8
+ @triton.jit
9
+ def _causal_conv1d_varlen_states(
10
+ X,
11
+ CU_SEQLENS,
12
+ STATES,
13
+ state_len,
14
+ dim,
15
+ stride_x_seqlen, stride_x_dim,
16
+ stride_states_batch, stride_states_seqlen, stride_states_dim,
17
+ BLOCK_M: tl.constexpr,
18
+ BLOCK_N: tl.constexpr
19
+ ):
20
+ batch_idx = tl.program_id(2)
21
+ STATES += batch_idx * stride_states_batch
22
+ end_idx = tl.load(CU_SEQLENS + batch_idx + 1)
23
+ start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len)
24
+ rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
25
+ cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)
26
+ x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] * stride_x_dim,
27
+ mask=(rows[:, None] >= start_idx) & (cols[None, :] < dim),
28
+ other=0)
29
+ rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
30
+ tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[None, :] * stride_states_dim,
31
+ x,
32
+ mask=(rows_states[:, None] >= 0) & (cols[None, :] < dim))
33
+
34
+
35
+ def causal_conv1d_varlen_states(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
36
+ """
37
+ Forward pass only, does not support backward pass.
38
+ Parameters:
39
+ x: (total_tokens, dim)
40
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
41
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
42
+ If some of those elements belong to a different sequence, the value of the states will be zero.
43
+ Return:
44
+ states: (batch, dim, state_len)
45
+ """
46
+ _, dim = x.shape
47
+ batch = cu_seqlens.shape[0] - 1
48
+ cu_seqlens = cu_seqlens.contiguous()
49
+ states = torch.empty(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
50
+ BLOCK_M = min(triton.next_power_of_2(state_len), 16)
51
+ BLOCK_N = min(triton.next_power_of_2(dim), 256)
52
+ grid = (triton.cdiv(dim, BLOCK_N), triton.cdiv(state_len, BLOCK_M), batch)
53
+ with getattr(torch, x.device.type).device(x.device.index):
54
+ _causal_conv1d_varlen_states[grid](
55
+ x,
56
+ cu_seqlens,
57
+ states,
58
+ state_len,
59
+ dim,
60
+ x.stride(0), x.stride(1),
61
+ states.stride(0), states.stride(2), states.stride(1),
62
+ BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N
63
+ )
64
+ return states
65
+
66
+
67
+ def causal_conv1d_varlen_states_ref(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
68
+ """
69
+ Forward pass only, does not support backward pass.
70
+ Parameters:
71
+ x: (total_tokens, dim)
72
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
73
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
74
+ If some of those elements belong to a different sequence, the value of the states will be zero.
75
+ Return:
76
+ states: (batch, dim, state_len)
77
+ """
78
+ _, dim = x.shape
79
+ batch = cu_seqlens.shape[0] - 1
80
+ cu_seqlens = cu_seqlens.contiguous()
81
+ states = torch.zeros(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
82
+ for i in range(batch):
83
+ end_idx = cu_seqlens[i + 1]
84
+ start_idx = torch.maximum(cu_seqlens[i], end_idx - state_len)
85
+ states[i, :, -(end_idx - start_idx):] = x[start_idx:end_idx].T
86
+ return states
build/torch212-cxx11-cu126-x86_64-linux/cpp_functions.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+
5
+ from ._ops import ops
6
+
7
+ def causal_conv1d_fwd_function(
8
+ x: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ bias: torch.Tensor | None,
11
+ seq_idx: torch.Tensor | None,
12
+ initial_states: torch.Tensor | None,
13
+ final_states_out: torch.Tensor | None,
14
+ silu_activation: bool,
15
+ ) -> torch.Tensor:
16
+ out = torch.empty_like(x)
17
+ ops.causal_conv1d_fwd(
18
+ x=x,
19
+ weight=weight,
20
+ bias=bias,
21
+ seq_idx=seq_idx,
22
+ initial_states=initial_states,
23
+ out=out,
24
+ final_states_out=final_states_out,
25
+ silu_activation=silu_activation,
26
+ )
27
+ return out
28
+
29
+
30
+ def causal_conv1d_bwd_function(
31
+ x: torch.Tensor,
32
+ weight: torch.Tensor,
33
+ bias: torch.Tensor | None,
34
+ dout: torch.Tensor,
35
+ seq_idx: torch.Tensor | None,
36
+ initial_states: torch.Tensor | None,
37
+ dfinal_states: torch.Tensor | None,
38
+ dx: torch.Tensor | None,
39
+ return_dinitial_states: torch.Tensor,
40
+ silu_activation: bool,
41
+ ) -> tuple[torch.Tensor | None]:
42
+ batch_size, dim = x.size()[:2]
43
+ width = weight.size(-1)
44
+
45
+ if dx is None:
46
+ dx = torch.empty_like(x)
47
+ dweight = torch.zeros_like(weight, dtype=torch.float32)
48
+ dbias = None
49
+ if bias is not None:
50
+ dbias = torch.zeros_like(bias, dtype=torch.float32)
51
+ dinitial_states = None
52
+ if return_dinitial_states:
53
+ dinitial_states = torch.empty(batch_size, width - 1, dim, device=x.device, dtype=x.dtype).transpose(1, 2)
54
+
55
+ ops.causal_conv1d_bwd(
56
+ x=x,
57
+ weight=weight,
58
+ bias=bias,
59
+ dout=dout,
60
+ seq_idx=seq_idx,
61
+ initial_states=initial_states,
62
+ dfinal_states=dfinal_states,
63
+ dx=dx,
64
+ dweight=dweight,
65
+ dbias=dbias,
66
+ dinitial_states=dinitial_states,
67
+ silu_activation=silu_activation,
68
+ )
69
+
70
+ dweight = dweight.type_as(weight)
71
+ if dbias is not None:
72
+ dbias = dbias.type_as(bias)
73
+ return dx, dweight, dbias, dinitial_states
74
+
75
+
76
+ def causal_conv1d_update_function(
77
+ x: torch.Tensor,
78
+ conv_state: torch.Tensor,
79
+ weight: torch.Tensor,
80
+ bias: torch.Tensor | None,
81
+ silu_activation: bool,
82
+ cache_seqlens: torch.Tensor | None,
83
+ conv_state_indices: torch.Tensor | None,
84
+ ) -> torch.Tensor:
85
+ out = torch.empty_like(x)
86
+ ops.causal_conv1d_update(
87
+ x=x,
88
+ conv_state=conv_state,
89
+ weight=weight,
90
+ bias=bias,
91
+ out=out,
92
+ silu_activation=silu_activation,
93
+ cache_seqlens=cache_seqlens,
94
+ conv_state_indices=conv_state_indices,
95
+ )
96
+ return out
build/torch212-cxx11-cu126-x86_64-linux/layers.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ from .causal_conv1d_interface import causal_conv1d_fn as kernel_causal_conv1d_fn
5
+ from .causal_conv1d_interface import causal_conv1d_update as kernel_causal_conv1d_update
6
+
7
+
8
+ class causal_conv1d_fn(nn.Module):
9
+ def forward(
10
+ self,
11
+ hidden_states: torch.Tensor,
12
+ weight: torch.Tensor,
13
+ bias: torch.Tensor | None = None,
14
+ activation: str | None = None,
15
+ **kwargs,
16
+ ):
17
+ # For varlen
18
+ seq_idx = kwargs.pop("seq_idx", None)
19
+
20
+ return kernel_causal_conv1d_fn(
21
+ x=hidden_states,
22
+ weight=weight,
23
+ bias=bias,
24
+ activation=activation,
25
+ seq_idx=seq_idx,
26
+ )
27
+
28
+
29
+ class causal_conv1d_update(nn.Module):
30
+ def forward(
31
+ self,
32
+ hidden_states: torch.Tensor,
33
+ conv_state: torch.Tensor,
34
+ weight: torch.Tensor,
35
+ bias: torch.Tensor | None = None,
36
+ activation: str | None = None,
37
+ ):
38
+ return kernel_causal_conv1d_update(
39
+ x=hidden_states,
40
+ conv_state=conv_state,
41
+ weight=weight,
42
+ bias=bias,
43
+ activation=activation,
44
+ )
45
+
46
+
47
+ __all__ = [
48
+ "causal_conv1d_fn",
49
+ "causal_conv1d_update",
50
+ ]
build/torch212-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d",
3
+ "id": "_causal_conv1d_cuda_056e28b",
4
+ "version": 2,
5
+ "license": "BSD-3-Clause",
6
+ "python-depends": [],
7
+ "kernel-depends": [],
8
+ "backend": {
9
+ "type": "cuda",
10
+ "archs": [
11
+ "7.0",
12
+ "7.2",
13
+ "7.5",
14
+ "8.0",
15
+ "8.6",
16
+ "8.7",
17
+ "8.9",
18
+ "9.0+PTX"
19
+ ]
20
+ },
21
+ "digest": {
22
+ "algorithm": "sha256",
23
+ "files": {
24
+ "__init__.py": "ybfee7cD5pV/RtZZSki1skLZM+COZVoqTa+IlL+zY7E=",
25
+ "_causal_conv1d_cuda_056e28b.abi3.so": "8XRBW8BiG68sZz+Qy9SpCHIS4qjZPp1KtmHCdQbtkRk=",
26
+ "_ops.py": "in6wiEQzq3wMOxiS5jap8cHfMQFJoUmFV73UTM6S8S4=",
27
+ "causal_conv1d_interface.py": "Mm0fBbamT4dihp+Z53RzIFM/dn5Y8nLu1vJ4W4W53jQ=",
28
+ "causal_conv1d_varlen.py": "j6tdAEf/x0aBoNx3mEA9qo4xAxmH6fuUUdVnq7tuGgM=",
29
+ "cpp_functions.py": "gUG0/NiMaAmAHLZQ4TnnD5LyKJp9G/BlINOFXXcnlU8=",
30
+ "layers.py": "RH7iOTcjqtn3buFO7fGHfC/Pgu47eaX97ANzfwLD6C8="
31
+ }
32
+ },
33
+ "provenance": {
34
+ "kernel-builder": {
35
+ "version": "0.17.0-dev0",
36
+ "commit": "081dcd473f8eca27226eef1f9c47c45b86c756b5",
37
+ "dirty": false
38
+ },
39
+ "kernel": {
40
+ "commit": "056e28b85220c032b4dc1bb3dadebddd56dc228e",
41
+ "dirty": false
42
+ }
43
+ }
44
+ }
build/torch212-cxx11-cu126-x86_64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"media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EEAYO/MAEYBDgMNnJlcG86aHVnZ2luZ2ZhY2Uva2VybmVscy1jb21tdW5pdHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBigYKKwYBBAHWeQIEAgR8BHoAeAB2AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzMu3MAAAQDAEcwRQIhAPDwxhx6LitdPUJzBKQ3UpWgf0wdfF9U7TlG33vujN5NAiBul6DyVJub05Hz9zDp82qAJufawD/LMyHhV8XSfjNVSzAKBggqhkjOPQQDAwNnADBkAjAM2bbW6fKK4DbtGgaoMkwWzc5SJ73cv93qW/acrcQBDlDaYO6tS3FEjFlHPbMFf5UCMGawfyiBCp5JH3ZTHZW23zpghZgQbeCd1nlnkbFLfrSosyanJB9NliNLt7bzyhIvbA=="}, "tlogEntries":[{"logIndex":"2712272739", "logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="}, "kindVersion":{"kind":"hashedrekord", "version":"0.0.1"}, "integratedTime":"1788531754", "inclusionPromise":{"signedEntryTimestamp":"MEYCIQD8srDq+MHTdVtlET9nlBIxRovCp6nnbUlVOrydHYo7uQIhAIIyi8uZvABuK/caUZg+9I0KXDkHBoSMO31q07qA+xwS"}, "inclusionProof":{"logIndex":"2590368477", "rootHash":"UWIza+5vwcjkcoaWAVFoxGRGfH+FSU17UEQhwACPatU=", "treeSize":"2590369486", "hashes":["1U11euJ9tOhPEFratAmpG5jvfAjickDCreYmBijU5SQ=", "S3uT5c7zKfDKFgc1qsSo0M3vUXas9d8UH43unGonvDE=", "C8FX0x1l7O6RRBo4mtSrbRlHJB4sOKBFv2Qrbf7id1I=", "LFXwUgL1WUbdVBfWa1ec7Br0lk9bhYuAch5UztUJjRI=", "SqQQwp8ftKUS8E7LXVt4vaGDNwjlwKYIyrPNauQ90X0=", "cFnFw51DhaJRsQ6ylnnpBRrayhUXP2lXJymcHizb/MI=", "zlx3RivqVtxl2pUJb0/AvPue3POksFPLxSkFoj/oBHA=", "L53shECZ2Dt19SXshsVZXgKPbyn8xh7JujI6k9YM4ls=", "zHyvrUWl+DArck+G7I0w6gtAV9tiYJWAASXiOc1UaNg=", "cZDpUl+6xSnn8yG0dI4YWAwhtkD8K/yUZrm0JkW1ys8=", "VI3m9U5kLhiizApcU6yjOQD/h+HNInVZln8XgxSvZQs=", "dpE4JeS09wbniSRpzbHmp3WEjZfaXFuaxQ/Jz4h8Qdo=", "5BBv7rWK6NFgtdHnmpxaOG4IgQ2e23dxOnb7iVqIJfs=", "CVXlwy6p/0g8OGYc+N5iYlD4qo/oIV4lgJstV8/jX9Y=", "JLnTjrlsTfbD8CvvizQuzVwJPXlC98tLzdnXZ1HqaTI=", "wgA+dB9j8L++Xwb+XT+v0evEwWqMLyd201Sc69PSLzg=", "N+foNlyVQOzU7HZsPPSKIQU/1+E+tmJj33u2r6dwmBs=", "I1FtczpUgFViy1Ae7CAfwglj2nSpp5nZrcsYauARxMs=", "fnPrvt7afEuTlIhaMcrGUdu9+heAmk4jOJ3+Br8/B8M=", "eXSLrLqKSxRTixSP/k4YimriB2lufao6trqTrsxxlyg=", "SndbMKVtcTenAkwi2JBfGzD+mhexp1qJbRIY+A1JRIU=", "xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="], "checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n2590369486\nUWIza+5vwcjkcoaWAVFoxGRGfH+FSU17UEQhwACPatU=\n\n— rekor.sigstore.dev wNI9ajBFAiAcQLtXU1hYSx6+jWcqZy3yEgfRRnjCnG1DNntiC6xSzwIhAK6C8508tsFmNK5xfhFHX5TE/Mtea7zsV7XyuUpXLcY7\n"}}, "canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiI5NmM3YWU1MjNhNWJ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3JlLmRldjEgMB4GA1UEAxMXc2lnc3RvcmUtdHNhLXNlbGZzaWduZWQCFDoTVC8MkGHuvMFDL8uKjosqI4sMMAsGCWCGSAFlAwQCAaCB/DAaBgkqhkiG9w0BCQMxDQYLKoZIhvcNAQkQAQQwHAYJKoZIhvcNAQkFMQ8XDTI2MDkwNDE0MjIzMVowLwYJKoZIhvcNAQkEMSIEILLQs9CfWuJfGbLxMw0ym/UC0qjM5HvvQz8XIxHJK7HLMIGOBgsqhkiG9w0BCRACLzF/MH0wezB5BCCF+Se8B6tiysO0Q1bBDvyBssaIP9p6uebYcNnROs0FtzBVMD2kOzA5MRUwEwYDVQQKEwxzaWdzdG9yZS5kZXYxIDAeBgNVBAMTF3NpZ3N0b3JlLXRzYS1zZWxmc2lnbmVkAhQ6E1QvDJBh7rzBQy/Lio6LKiOLDDAKBggqhkjOPQQDAgRmMGQCMHquz3uZXN7inPbI/ErpH4YRtusV2g+CYm2hpssYL7HD1fLz8IOWLDufOyTUcRPEEwIwLO/4uX5Zz9IR+8w0EGkA917kLaML7sWIyF/7F4byny+x4p3xhfO13fgN5nlTEeHv"}]}}, "messageSignature":{"messageDigest":{"algorithm":"SHA2_256", "digest":"lseuUjpbudzLmi4Mi1clU3DkdVYnnX+tKMEXlpo0z+w="}, "signature":"MEQCIAanvN1EZ/wLa1zIoVG7PI7sKroYXWeK46Ec5ioK5IGjAiBjQN1pR5DrU80ehU4q3HTm2kft14gSvkScXg3Rvgu9cw=="}}
build/torch212-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+ from .causal_conv1d_interface import causal_conv1d_fn, causal_conv1d_update
3
+ from .causal_conv1d_varlen import causal_conv1d_varlen_states
4
+
5
+ __all__ = [
6
+ # wrappers
7
+ "layers",
8
+ # originals
9
+ "causal_conv1d_fn",
10
+ "causal_conv1d_update",
11
+ "causal_conv1d_varlen_states",
12
+ ]
build/torch212-cxx11-cu130-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:da62650066ff7531150c70726936f53e2587bfd22926ffd9052d144bede61a87
3
+ size 74854784
build/torch212-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_cuda_056e28b
3
+ ops = torch.ops._causal_conv1d_cuda_056e28b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_cuda_056e28b::{op_name}"
build/torch212-cxx11-cu130-x86_64-linux/causal_conv1d_interface.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ from .cpp_functions import causal_conv1d_fwd_function, causal_conv1d_bwd_function, causal_conv1d_update_function
7
+
8
+
9
+ class CausalConv1dFn(torch.autograd.Function):
10
+ @staticmethod
11
+ def forward(
12
+ ctx,
13
+ x,
14
+ weight,
15
+ bias=None,
16
+ seq_idx=None,
17
+ initial_states=None,
18
+ return_final_states=False,
19
+ final_states_out=None,
20
+ activation=None,
21
+ ):
22
+ if activation not in [None, "silu", "swish"]:
23
+ raise NotImplementedError("activation must be None, silu, or swish")
24
+ if x.stride(2) != 1 and x.stride(1) != 1:
25
+ x = x.contiguous()
26
+ bias = bias.contiguous() if bias is not None else None
27
+ if seq_idx is not None:
28
+ assert (
29
+ initial_states is None
30
+ ), "initial_states must be None if seq_idx is not None"
31
+ assert (
32
+ not return_final_states
33
+ ), "If seq_idx is not None, we don't return final_states_out"
34
+ seq_idx = seq_idx.contiguous() if seq_idx is not None else None
35
+ if initial_states is not None and (
36
+ initial_states.stride(2) != 1 and initial_states.stride(1) != 1
37
+ ):
38
+ initial_states = initial_states.contiguous()
39
+ if return_final_states:
40
+ assert (
41
+ x.stride(1) == 1
42
+ ), "Only channel-last layout support returning final_states_out"
43
+ if final_states_out is not None:
44
+ assert (
45
+ final_states_out.stride(2) == 1 or final_states_out.stride(1) == 1
46
+ )
47
+ else:
48
+ batch, dim, seqlen = x.shape
49
+ width = weight.shape[1]
50
+ final_states_out = torch.empty(
51
+ batch, width - 1, dim, device=x.device, dtype=x.dtype
52
+ ).transpose(1, 2)
53
+ else:
54
+ final_states_out = None
55
+ ctx.activation = activation in ["silu", "swish"]
56
+ out = causal_conv1d_fwd_function(
57
+ x, weight, bias, seq_idx, initial_states, final_states_out, ctx.activation
58
+ )
59
+ ctx.save_for_backward(x, weight, bias, seq_idx, initial_states)
60
+ ctx.return_final_states = return_final_states
61
+ ctx.return_dinitial_states = (
62
+ initial_states is not None and initial_states.requires_grad
63
+ )
64
+ return out if not return_final_states else (out, final_states_out)
65
+
66
+ @staticmethod
67
+ def backward(ctx, dout, *args):
68
+ x, weight, bias, seq_idx, initial_states = ctx.saved_tensors
69
+ dfinal_states = args[0] if ctx.return_final_states else None
70
+ if dout.stride(2) != 1 and dout.stride(1) != 1:
71
+ dout = dout.contiguous()
72
+ # The kernel supports passing in a pre-allocated dx (e.g., in case we want to fuse the
73
+ # backward of conv1d with the backward of chunk).
74
+ # Here we just pass in None and dx will be allocated in the C++ code.
75
+ dx, dweight, dbias, dinitial_states = causal_conv1d_bwd_function(
76
+ x,
77
+ weight,
78
+ bias,
79
+ dout,
80
+ seq_idx,
81
+ initial_states,
82
+ dfinal_states,
83
+ None,
84
+ ctx.return_dinitial_states,
85
+ ctx.activation,
86
+ )
87
+ return (
88
+ dx,
89
+ dweight,
90
+ dbias if bias is not None else None,
91
+ None,
92
+ dinitial_states if initial_states is not None else None,
93
+ None,
94
+ None,
95
+ None,
96
+ )
97
+
98
+
99
+ def causal_conv1d_fn(
100
+ x,
101
+ weight,
102
+ bias=None,
103
+ seq_idx=None,
104
+ initial_states=None,
105
+ return_final_states=False,
106
+ final_states_out=None,
107
+ activation=None,
108
+ ):
109
+ """
110
+ x: (batch, dim, seqlen)
111
+ weight: (dim, width)
112
+ bias: (dim,)
113
+ seq_idx: (batch, seqlen)
114
+ initial_states: (batch, dim, width - 1)
115
+ final_states_out: (batch, dim, width - 1), to be written to
116
+ activation: either None or "silu" or "swish"
117
+
118
+ out: (batch, dim, seqlen)
119
+ """
120
+ return CausalConv1dFn.apply(
121
+ x,
122
+ weight,
123
+ bias,
124
+ seq_idx,
125
+ initial_states,
126
+ return_final_states,
127
+ final_states_out,
128
+ activation,
129
+ )
130
+
131
+
132
+ def causal_conv1d_ref(
133
+ x,
134
+ weight,
135
+ bias=None,
136
+ initial_states=None,
137
+ return_final_states=False,
138
+ final_states_out=None,
139
+ activation=None,
140
+ ):
141
+ """
142
+ x: (batch, dim, seqlen)
143
+ weight: (dim, width)
144
+ bias: (dim,)
145
+ initial_states: (batch, dim, width - 1)
146
+ final_states_out: (batch, dim, width - 1)
147
+
148
+ out: (batch, dim, seqlen)
149
+ """
150
+ if activation not in [None, "silu", "swish"]:
151
+ raise NotImplementedError("activation must be None, silu, or swish")
152
+ dtype_in = x.dtype
153
+ x = x.to(weight.dtype)
154
+ seqlen = x.shape[-1]
155
+ dim, width = weight.shape
156
+ if initial_states is None:
157
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
158
+ else:
159
+ x = torch.cat([initial_states, x], dim=-1)
160
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=0, groups=dim)
161
+ out = out[..., :seqlen]
162
+ if return_final_states:
163
+ final_states = F.pad(x, (width - 1 - x.shape[-1], 0)).to(
164
+ dtype_in
165
+ ) # (batch, dim, width - 1)
166
+ if final_states_out is not None:
167
+ final_states_out.copy_(final_states)
168
+ else:
169
+ final_states_out = final_states
170
+ out = (out if activation is None else F.silu(out)).to(dtype=dtype_in)
171
+ return out if not return_final_states else (out, final_states_out)
172
+
173
+
174
+ def causal_conv1d_update(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None, conv_state_indices=None):
175
+ """
176
+ x: (batch, dim) or (batch, dim, seqlen)
177
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
178
+ weight: (dim, width)
179
+ bias: (dim,)
180
+ cache_seqlens: (batch,), dtype int32.
181
+ If not None, the conv_state is treated as a circular buffer.
182
+ The conv_state will be updated by copying x to the conv_state starting at the index
183
+ @cache_seqlens % state_len.
184
+ conv_state_indices: (batch,), dtype int32
185
+ If None, the conv_state is a larger tensor along the batch dim,
186
+ and we are selecting the batch coords specified by conv_state_indices.
187
+ Useful for a continuous batching scenario.
188
+
189
+ out: (batch, dim) or (batch, dim, seqlen)
190
+ """
191
+ if activation not in [None, "silu", "swish"]:
192
+ raise NotImplementedError("activation must be None, silu, or swish")
193
+ activation = activation in ["silu", "swish"]
194
+ unsqueeze = x.dim() == 2
195
+ if unsqueeze:
196
+ x = x.unsqueeze(-1)
197
+ out = causal_conv1d_update_function(
198
+ x, conv_state, weight, bias, activation, cache_seqlens, conv_state_indices
199
+ )
200
+ if unsqueeze:
201
+ out = out.squeeze(-1)
202
+ return out
203
+
204
+
205
+ def causal_conv1d_update_ref(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None):
206
+ """
207
+ x: (batch, dim) or (batch, dim, seqlen)
208
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
209
+ weight: (dim, width)
210
+ bias: (dim,)
211
+ cache_seqlens: (batch,), dtype int32.
212
+ If not None, the conv_state is treated as a circular buffer.
213
+ The conv_state will be updated by copying x to the conv_state starting at the index
214
+ @cache_seqlens % state_len before performing the convolution.
215
+
216
+ out: (batch, dim) or (batch, dim, seqlen)
217
+ """
218
+ if activation not in [None, "silu", "swish"]:
219
+ raise NotImplementedError("activation must be None, silu, or swish")
220
+ dtype_in = x.dtype
221
+ unsqueeze = x.dim() == 2
222
+ if unsqueeze:
223
+ x = x.unsqueeze(-1)
224
+ batch, dim, seqlen = x.shape
225
+ width = weight.shape[1]
226
+ state_len = conv_state.shape[-1]
227
+ assert conv_state.shape == (batch, dim, state_len)
228
+ assert weight.shape == (dim, width)
229
+ if cache_seqlens is None:
230
+ x_new = torch.cat([conv_state, x], dim=-1).to(weight.dtype) # (batch, dim, state_len + seqlen)
231
+ conv_state.copy_(x_new[:, :, -state_len:])
232
+ else:
233
+ width_idx = torch.arange(-(width - 1), 0, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
234
+ width_idx = torch.remainder(width_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
235
+ x_new = torch.cat([conv_state.gather(2, width_idx), x], dim=-1).to(weight.dtype)
236
+ copy_idx = torch.arange(seqlen, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
237
+ copy_idx = torch.remainder(copy_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
238
+ conv_state.scatter_(2, copy_idx, x)
239
+ out = F.conv1d(x_new, weight.unsqueeze(1), bias, padding=0, groups=dim)[:, :, -seqlen:]
240
+ if unsqueeze:
241
+ out = out.squeeze(-1)
242
+ return (out if activation is None else F.silu(out)).to(dtype=dtype_in)
build/torch212-cxx11-cu130-x86_64-linux/causal_conv1d_varlen.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor
3
+
4
+ import triton
5
+ import triton.language as tl
6
+
7
+
8
+ @triton.jit
9
+ def _causal_conv1d_varlen_states(
10
+ X,
11
+ CU_SEQLENS,
12
+ STATES,
13
+ state_len,
14
+ dim,
15
+ stride_x_seqlen, stride_x_dim,
16
+ stride_states_batch, stride_states_seqlen, stride_states_dim,
17
+ BLOCK_M: tl.constexpr,
18
+ BLOCK_N: tl.constexpr
19
+ ):
20
+ batch_idx = tl.program_id(2)
21
+ STATES += batch_idx * stride_states_batch
22
+ end_idx = tl.load(CU_SEQLENS + batch_idx + 1)
23
+ start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len)
24
+ rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
25
+ cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)
26
+ x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] * stride_x_dim,
27
+ mask=(rows[:, None] >= start_idx) & (cols[None, :] < dim),
28
+ other=0)
29
+ rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
30
+ tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[None, :] * stride_states_dim,
31
+ x,
32
+ mask=(rows_states[:, None] >= 0) & (cols[None, :] < dim))
33
+
34
+
35
+ def causal_conv1d_varlen_states(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
36
+ """
37
+ Forward pass only, does not support backward pass.
38
+ Parameters:
39
+ x: (total_tokens, dim)
40
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
41
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
42
+ If some of those elements belong to a different sequence, the value of the states will be zero.
43
+ Return:
44
+ states: (batch, dim, state_len)
45
+ """
46
+ _, dim = x.shape
47
+ batch = cu_seqlens.shape[0] - 1
48
+ cu_seqlens = cu_seqlens.contiguous()
49
+ states = torch.empty(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
50
+ BLOCK_M = min(triton.next_power_of_2(state_len), 16)
51
+ BLOCK_N = min(triton.next_power_of_2(dim), 256)
52
+ grid = (triton.cdiv(dim, BLOCK_N), triton.cdiv(state_len, BLOCK_M), batch)
53
+ with getattr(torch, x.device.type).device(x.device.index):
54
+ _causal_conv1d_varlen_states[grid](
55
+ x,
56
+ cu_seqlens,
57
+ states,
58
+ state_len,
59
+ dim,
60
+ x.stride(0), x.stride(1),
61
+ states.stride(0), states.stride(2), states.stride(1),
62
+ BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N
63
+ )
64
+ return states
65
+
66
+
67
+ def causal_conv1d_varlen_states_ref(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
68
+ """
69
+ Forward pass only, does not support backward pass.
70
+ Parameters:
71
+ x: (total_tokens, dim)
72
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
73
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
74
+ If some of those elements belong to a different sequence, the value of the states will be zero.
75
+ Return:
76
+ states: (batch, dim, state_len)
77
+ """
78
+ _, dim = x.shape
79
+ batch = cu_seqlens.shape[0] - 1
80
+ cu_seqlens = cu_seqlens.contiguous()
81
+ states = torch.zeros(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
82
+ for i in range(batch):
83
+ end_idx = cu_seqlens[i + 1]
84
+ start_idx = torch.maximum(cu_seqlens[i], end_idx - state_len)
85
+ states[i, :, -(end_idx - start_idx):] = x[start_idx:end_idx].T
86
+ return states
build/torch212-cxx11-cu130-x86_64-linux/cpp_functions.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+
5
+ from ._ops import ops
6
+
7
+ def causal_conv1d_fwd_function(
8
+ x: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ bias: torch.Tensor | None,
11
+ seq_idx: torch.Tensor | None,
12
+ initial_states: torch.Tensor | None,
13
+ final_states_out: torch.Tensor | None,
14
+ silu_activation: bool,
15
+ ) -> torch.Tensor:
16
+ out = torch.empty_like(x)
17
+ ops.causal_conv1d_fwd(
18
+ x=x,
19
+ weight=weight,
20
+ bias=bias,
21
+ seq_idx=seq_idx,
22
+ initial_states=initial_states,
23
+ out=out,
24
+ final_states_out=final_states_out,
25
+ silu_activation=silu_activation,
26
+ )
27
+ return out
28
+
29
+
30
+ def causal_conv1d_bwd_function(
31
+ x: torch.Tensor,
32
+ weight: torch.Tensor,
33
+ bias: torch.Tensor | None,
34
+ dout: torch.Tensor,
35
+ seq_idx: torch.Tensor | None,
36
+ initial_states: torch.Tensor | None,
37
+ dfinal_states: torch.Tensor | None,
38
+ dx: torch.Tensor | None,
39
+ return_dinitial_states: torch.Tensor,
40
+ silu_activation: bool,
41
+ ) -> tuple[torch.Tensor | None]:
42
+ batch_size, dim = x.size()[:2]
43
+ width = weight.size(-1)
44
+
45
+ if dx is None:
46
+ dx = torch.empty_like(x)
47
+ dweight = torch.zeros_like(weight, dtype=torch.float32)
48
+ dbias = None
49
+ if bias is not None:
50
+ dbias = torch.zeros_like(bias, dtype=torch.float32)
51
+ dinitial_states = None
52
+ if return_dinitial_states:
53
+ dinitial_states = torch.empty(batch_size, width - 1, dim, device=x.device, dtype=x.dtype).transpose(1, 2)
54
+
55
+ ops.causal_conv1d_bwd(
56
+ x=x,
57
+ weight=weight,
58
+ bias=bias,
59
+ dout=dout,
60
+ seq_idx=seq_idx,
61
+ initial_states=initial_states,
62
+ dfinal_states=dfinal_states,
63
+ dx=dx,
64
+ dweight=dweight,
65
+ dbias=dbias,
66
+ dinitial_states=dinitial_states,
67
+ silu_activation=silu_activation,
68
+ )
69
+
70
+ dweight = dweight.type_as(weight)
71
+ if dbias is not None:
72
+ dbias = dbias.type_as(bias)
73
+ return dx, dweight, dbias, dinitial_states
74
+
75
+
76
+ def causal_conv1d_update_function(
77
+ x: torch.Tensor,
78
+ conv_state: torch.Tensor,
79
+ weight: torch.Tensor,
80
+ bias: torch.Tensor | None,
81
+ silu_activation: bool,
82
+ cache_seqlens: torch.Tensor | None,
83
+ conv_state_indices: torch.Tensor | None,
84
+ ) -> torch.Tensor:
85
+ out = torch.empty_like(x)
86
+ ops.causal_conv1d_update(
87
+ x=x,
88
+ conv_state=conv_state,
89
+ weight=weight,
90
+ bias=bias,
91
+ out=out,
92
+ silu_activation=silu_activation,
93
+ cache_seqlens=cache_seqlens,
94
+ conv_state_indices=conv_state_indices,
95
+ )
96
+ return out
build/torch212-cxx11-cu130-x86_64-linux/layers.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ from .causal_conv1d_interface import causal_conv1d_fn as kernel_causal_conv1d_fn
5
+ from .causal_conv1d_interface import causal_conv1d_update as kernel_causal_conv1d_update
6
+
7
+
8
+ class causal_conv1d_fn(nn.Module):
9
+ def forward(
10
+ self,
11
+ hidden_states: torch.Tensor,
12
+ weight: torch.Tensor,
13
+ bias: torch.Tensor | None = None,
14
+ activation: str | None = None,
15
+ **kwargs,
16
+ ):
17
+ # For varlen
18
+ seq_idx = kwargs.pop("seq_idx", None)
19
+
20
+ return kernel_causal_conv1d_fn(
21
+ x=hidden_states,
22
+ weight=weight,
23
+ bias=bias,
24
+ activation=activation,
25
+ seq_idx=seq_idx,
26
+ )
27
+
28
+
29
+ class causal_conv1d_update(nn.Module):
30
+ def forward(
31
+ self,
32
+ hidden_states: torch.Tensor,
33
+ conv_state: torch.Tensor,
34
+ weight: torch.Tensor,
35
+ bias: torch.Tensor | None = None,
36
+ activation: str | None = None,
37
+ ):
38
+ return kernel_causal_conv1d_update(
39
+ x=hidden_states,
40
+ conv_state=conv_state,
41
+ weight=weight,
42
+ bias=bias,
43
+ activation=activation,
44
+ )
45
+
46
+
47
+ __all__ = [
48
+ "causal_conv1d_fn",
49
+ "causal_conv1d_update",
50
+ ]
build/torch212-cxx11-cu130-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d",
3
+ "id": "_causal_conv1d_cuda_056e28b",
4
+ "version": 2,
5
+ "license": "BSD-3-Clause",
6
+ "python-depends": [],
7
+ "kernel-depends": [],
8
+ "backend": {
9
+ "type": "cuda",
10
+ "archs": [
11
+ "10.0",
12
+ "10.3",
13
+ "11.0",
14
+ "12.0",
15
+ "12.1+PTX",
16
+ "7.5",
17
+ "8.0",
18
+ "8.6",
19
+ "8.7",
20
+ "8.9",
21
+ "9.0"
22
+ ]
23
+ },
24
+ "digest": {
25
+ "algorithm": "sha256",
26
+ "files": {
27
+ "__init__.py": "ybfee7cD5pV/RtZZSki1skLZM+COZVoqTa+IlL+zY7E=",
28
+ "_causal_conv1d_cuda_056e28b.abi3.so": "2mJlAGb/dTEVDHByaTb1PiWHv9IpJv/ZBS0US+3mGoc=",
29
+ "_ops.py": "in6wiEQzq3wMOxiS5jap8cHfMQFJoUmFV73UTM6S8S4=",
30
+ "causal_conv1d_interface.py": "Mm0fBbamT4dihp+Z53RzIFM/dn5Y8nLu1vJ4W4W53jQ=",
31
+ "causal_conv1d_varlen.py": "j6tdAEf/x0aBoNx3mEA9qo4xAxmH6fuUUdVnq7tuGgM=",
32
+ "cpp_functions.py": "gUG0/NiMaAmAHLZQ4TnnD5LyKJp9G/BlINOFXXcnlU8=",
33
+ "layers.py": "RH7iOTcjqtn3buFO7fGHfC/Pgu47eaX97ANzfwLD6C8="
34
+ }
35
+ },
36
+ "provenance": {
37
+ "kernel-builder": {
38
+ "version": "0.17.0-dev0",
39
+ "commit": "081dcd473f8eca27226eef1f9c47c45b86c756b5",
40
+ "dirty": false
41
+ },
42
+ "kernel": {
43
+ "commit": "056e28b85220c032b4dc1bb3dadebddd56dc228e",
44
+ "dirty": false
45
+ }
46
+ }
47
+ }
build/torch212-cxx11-cu130-x86_64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json", "verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtGgAwIBAgIUEm/GUtOGnQ/TZx10GxzB6EJLhn4wCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQyMjQwWhcNMjYwOTA0MTQzMjQwWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqJV5VOwl8yW6JQjfZ/PG77lcXEzXKU3v1v/MT5FVdMLL6GWrexBOKmJ8u3QCe4bXPNLqaK04sCyJzQ+2NTD2eKOCBfAwggXsMA4G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spQAiP7XnXstYs020/wFiqP28TBx6+/Y3LOn6UOvoXxHnQXeA67Wl1+oovCV4="}, "tlogEntries":[{"logIndex":"2712273997", "logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="}, "kindVersion":{"kind":"hashedrekord", "version":"0.0.1"}, "integratedTime":"1788531760", "inclusionPromise":{"signedEntryTimestamp":"MEUCIQDtinQAMuOlw9xe/C5kA0zoK7RWJH7h6y+pwV5tcfrj4wIgB3x5Gplwj4Vzk7I7PR2Vh3YVbMn6iHnxDQX9VO4ujq8="}, "inclusionProof":{"logIndex":"2590369735", "rootHash":"GwN1lo+P762wCRUXBMgV+ZZ5pDyrIrcZ+NBBYiM6cu0=", "treeSize":"2590370072", "hashes":["NUQR60N3WmIklku4sDxfu8N+4EYGonKDVS21uwhSGM4=", "Nw5/2KB+QECeFVCB/fxBEgS3AfftGXw+bFhIqLaf0I4=", "8KQIDhFJUjJhzm798P/qWaGMwv8/M4EK7msTwVsLgxk=", "1upZntVx11ut1j4XOdwqQgsho+new3/n94Kd/Btu8Rk=", "iuqQjnrr2PYBw3HqoMMoz4ln6ORKfOOvET3+JuSG31g=", "Pl+olzORMn0kCQFecRdVGG6owx5O5wD2YTpOnjrnHo4=", "ae1yX0AUsNipoQGV7sbYYvLK9AWsrYLwEtaSoNCVdMI=", "oMkpIme9WSTQOT5qYhUV4Cd2Pi1lskhQRzjL4AaBDZQ=", "BpRRvj4YPNwp78pQYHVU3OoA0akcy+APi1IcoBkSSSE=", "9sXHSOooXpYfC0khLe96eESh1it1z6+Gv4HmQVQZSJY=", "H7BK9I9wa5CBbs3MI2doHIqZy8u92kQ0N3kdMehlcUk=", "QhJJ+LR/jN7V5M/WjcsQUqO2uxxa26oJxajbA4whHIc=", "dpE4JeS09wbniSRpzbHmp3WEjZfaXFuaxQ/Jz4h8Qdo=", "5BBv7rWK6NFgtdHnmpxaOG4IgQ2e23dxOnb7iVqIJfs=", "CVXlwy6p/0g8OGYc+N5iYlD4qo/oIV4lgJstV8/jX9Y=", "JLnTjrlsTfbD8CvvizQuzVwJPXlC98tLzdnXZ1HqaTI=", "wgA+dB9j8L++Xwb+XT+v0evEwWqMLyd201Sc69PSLzg=", "N+foNlyVQOzU7HZsPPSKIQU/1+E+tmJj33u2r6dwmBs=", "I1FtczpUgFViy1Ae7CAfwglj2nSpp5nZrcsYauARxMs=", "fnPrvt7afEuTlIhaMcrGUdu9+heAmk4jOJ3+Br8/B8M=", "eXSLrLqKSxRTixSP/k4YimriB2lufao6trqTrsxxlyg=", "SndbMKVtcTenAkwi2JBfGzD+mhexp1qJbRIY+A1JRIU=", "xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="], "checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n2590370072\nGwN1lo+P762wCRUXBMgV+ZZ5pDyrIrcZ+NBBYiM6cu0=\n\n— rekor.sigstore.dev wNI9ajBFAiEA9Sbu9RMrgP0ZXGqxBYElJ2m1361QAWYhEx9VOabnYP8CIHn8neeo3gM7zuqDOc2o6pPr1+FlwKled7+yeMsfbVd9\n"}}, "canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJmNjJlZTM2MzE2ZmQxN2EyM2MzOGEzOGI3YzE3NWM1NzRmNjllMzQxMTVlYzgyOGUwZTA5YmI3MDVhMWJmZTViIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FVUNJSFFqaTRBUXBLME10SFpjSHFpQ05EcmhLT25PZU80cHU4OGc1LzJDRWhXSkFpRUEyUG5LR2tFc0RHYmkvdlpDbjM3eVd4em9PbnNlQ1h4a1A1QWd1bitnNG1nPSIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBG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IP9p6uebYcNnROs0FtzBVMD2kOzA5MRUwEwYDVQQKEwxzaWdzdG9yZS5kZXYxIDAeBgNVBAMTF3NpZ3N0b3JlLXRzYS1zZWxmc2lnbmVkAhQ6E1QvDJBh7rzBQy/Lio6LKiOLDDAKBggqhkjOPQQDAgRmMGQCMDZB7TMxI2hDlLSAGpKWxI4CysIzTLCdos7ODJFr5Yp7gIXsLNqUUKIHbQd6/YvUAgIwB7TttD6Ug2MjT7d0aGVHQxy29IRBxCRyJ8GSwF3CsXd5iHd6KPaCZfJ6Wh0Ll9Yn"}]}}, "messageSignature":{"messageDigest":{"algorithm":"SHA2_256", "digest":"9i7jYxb9F6I8OKOLfBdcV09p40EV7IKODgm7cFob/ls="}, "signature":"MEUCIHQji4AQpK0MtHZcHqiCNDrhKOnOeO4pu88g5/2CEhWJAiEA2PnKGkEsDGbi/vZCn37yWxzoOnseCXxkP5Agun+g4mg="}}
build/torch212-cxx11-cu132-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+ from .causal_conv1d_interface import causal_conv1d_fn, causal_conv1d_update
3
+ from .causal_conv1d_varlen import causal_conv1d_varlen_states
4
+
5
+ __all__ = [
6
+ # wrappers
7
+ "layers",
8
+ # originals
9
+ "causal_conv1d_fn",
10
+ "causal_conv1d_update",
11
+ "causal_conv1d_varlen_states",
12
+ ]
build/torch212-cxx11-cu132-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4166b274afb2be743b59de6eaaea5a5eae5cb11db779a6a105a3af403df8c70d
3
+ size 75006088
build/torch212-cxx11-cu132-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_cuda_056e28b
3
+ ops = torch.ops._causal_conv1d_cuda_056e28b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_cuda_056e28b::{op_name}"
build/torch212-cxx11-cu132-x86_64-linux/causal_conv1d_interface.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ from .cpp_functions import causal_conv1d_fwd_function, causal_conv1d_bwd_function, causal_conv1d_update_function
7
+
8
+
9
+ class CausalConv1dFn(torch.autograd.Function):
10
+ @staticmethod
11
+ def forward(
12
+ ctx,
13
+ x,
14
+ weight,
15
+ bias=None,
16
+ seq_idx=None,
17
+ initial_states=None,
18
+ return_final_states=False,
19
+ final_states_out=None,
20
+ activation=None,
21
+ ):
22
+ if activation not in [None, "silu", "swish"]:
23
+ raise NotImplementedError("activation must be None, silu, or swish")
24
+ if x.stride(2) != 1 and x.stride(1) != 1:
25
+ x = x.contiguous()
26
+ bias = bias.contiguous() if bias is not None else None
27
+ if seq_idx is not None:
28
+ assert (
29
+ initial_states is None
30
+ ), "initial_states must be None if seq_idx is not None"
31
+ assert (
32
+ not return_final_states
33
+ ), "If seq_idx is not None, we don't return final_states_out"
34
+ seq_idx = seq_idx.contiguous() if seq_idx is not None else None
35
+ if initial_states is not None and (
36
+ initial_states.stride(2) != 1 and initial_states.stride(1) != 1
37
+ ):
38
+ initial_states = initial_states.contiguous()
39
+ if return_final_states:
40
+ assert (
41
+ x.stride(1) == 1
42
+ ), "Only channel-last layout support returning final_states_out"
43
+ if final_states_out is not None:
44
+ assert (
45
+ final_states_out.stride(2) == 1 or final_states_out.stride(1) == 1
46
+ )
47
+ else:
48
+ batch, dim, seqlen = x.shape
49
+ width = weight.shape[1]
50
+ final_states_out = torch.empty(
51
+ batch, width - 1, dim, device=x.device, dtype=x.dtype
52
+ ).transpose(1, 2)
53
+ else:
54
+ final_states_out = None
55
+ ctx.activation = activation in ["silu", "swish"]
56
+ out = causal_conv1d_fwd_function(
57
+ x, weight, bias, seq_idx, initial_states, final_states_out, ctx.activation
58
+ )
59
+ ctx.save_for_backward(x, weight, bias, seq_idx, initial_states)
60
+ ctx.return_final_states = return_final_states
61
+ ctx.return_dinitial_states = (
62
+ initial_states is not None and initial_states.requires_grad
63
+ )
64
+ return out if not return_final_states else (out, final_states_out)
65
+
66
+ @staticmethod
67
+ def backward(ctx, dout, *args):
68
+ x, weight, bias, seq_idx, initial_states = ctx.saved_tensors
69
+ dfinal_states = args[0] if ctx.return_final_states else None
70
+ if dout.stride(2) != 1 and dout.stride(1) != 1:
71
+ dout = dout.contiguous()
72
+ # The kernel supports passing in a pre-allocated dx (e.g., in case we want to fuse the
73
+ # backward of conv1d with the backward of chunk).
74
+ # Here we just pass in None and dx will be allocated in the C++ code.
75
+ dx, dweight, dbias, dinitial_states = causal_conv1d_bwd_function(
76
+ x,
77
+ weight,
78
+ bias,
79
+ dout,
80
+ seq_idx,
81
+ initial_states,
82
+ dfinal_states,
83
+ None,
84
+ ctx.return_dinitial_states,
85
+ ctx.activation,
86
+ )
87
+ return (
88
+ dx,
89
+ dweight,
90
+ dbias if bias is not None else None,
91
+ None,
92
+ dinitial_states if initial_states is not None else None,
93
+ None,
94
+ None,
95
+ None,
96
+ )
97
+
98
+
99
+ def causal_conv1d_fn(
100
+ x,
101
+ weight,
102
+ bias=None,
103
+ seq_idx=None,
104
+ initial_states=None,
105
+ return_final_states=False,
106
+ final_states_out=None,
107
+ activation=None,
108
+ ):
109
+ """
110
+ x: (batch, dim, seqlen)
111
+ weight: (dim, width)
112
+ bias: (dim,)
113
+ seq_idx: (batch, seqlen)
114
+ initial_states: (batch, dim, width - 1)
115
+ final_states_out: (batch, dim, width - 1), to be written to
116
+ activation: either None or "silu" or "swish"
117
+
118
+ out: (batch, dim, seqlen)
119
+ """
120
+ return CausalConv1dFn.apply(
121
+ x,
122
+ weight,
123
+ bias,
124
+ seq_idx,
125
+ initial_states,
126
+ return_final_states,
127
+ final_states_out,
128
+ activation,
129
+ )
130
+
131
+
132
+ def causal_conv1d_ref(
133
+ x,
134
+ weight,
135
+ bias=None,
136
+ initial_states=None,
137
+ return_final_states=False,
138
+ final_states_out=None,
139
+ activation=None,
140
+ ):
141
+ """
142
+ x: (batch, dim, seqlen)
143
+ weight: (dim, width)
144
+ bias: (dim,)
145
+ initial_states: (batch, dim, width - 1)
146
+ final_states_out: (batch, dim, width - 1)
147
+
148
+ out: (batch, dim, seqlen)
149
+ """
150
+ if activation not in [None, "silu", "swish"]:
151
+ raise NotImplementedError("activation must be None, silu, or swish")
152
+ dtype_in = x.dtype
153
+ x = x.to(weight.dtype)
154
+ seqlen = x.shape[-1]
155
+ dim, width = weight.shape
156
+ if initial_states is None:
157
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
158
+ else:
159
+ x = torch.cat([initial_states, x], dim=-1)
160
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=0, groups=dim)
161
+ out = out[..., :seqlen]
162
+ if return_final_states:
163
+ final_states = F.pad(x, (width - 1 - x.shape[-1], 0)).to(
164
+ dtype_in
165
+ ) # (batch, dim, width - 1)
166
+ if final_states_out is not None:
167
+ final_states_out.copy_(final_states)
168
+ else:
169
+ final_states_out = final_states
170
+ out = (out if activation is None else F.silu(out)).to(dtype=dtype_in)
171
+ return out if not return_final_states else (out, final_states_out)
172
+
173
+
174
+ def causal_conv1d_update(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None, conv_state_indices=None):
175
+ """
176
+ x: (batch, dim) or (batch, dim, seqlen)
177
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
178
+ weight: (dim, width)
179
+ bias: (dim,)
180
+ cache_seqlens: (batch,), dtype int32.
181
+ If not None, the conv_state is treated as a circular buffer.
182
+ The conv_state will be updated by copying x to the conv_state starting at the index
183
+ @cache_seqlens % state_len.
184
+ conv_state_indices: (batch,), dtype int32
185
+ If None, the conv_state is a larger tensor along the batch dim,
186
+ and we are selecting the batch coords specified by conv_state_indices.
187
+ Useful for a continuous batching scenario.
188
+
189
+ out: (batch, dim) or (batch, dim, seqlen)
190
+ """
191
+ if activation not in [None, "silu", "swish"]:
192
+ raise NotImplementedError("activation must be None, silu, or swish")
193
+ activation = activation in ["silu", "swish"]
194
+ unsqueeze = x.dim() == 2
195
+ if unsqueeze:
196
+ x = x.unsqueeze(-1)
197
+ out = causal_conv1d_update_function(
198
+ x, conv_state, weight, bias, activation, cache_seqlens, conv_state_indices
199
+ )
200
+ if unsqueeze:
201
+ out = out.squeeze(-1)
202
+ return out
203
+
204
+
205
+ def causal_conv1d_update_ref(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None):
206
+ """
207
+ x: (batch, dim) or (batch, dim, seqlen)
208
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
209
+ weight: (dim, width)
210
+ bias: (dim,)
211
+ cache_seqlens: (batch,), dtype int32.
212
+ If not None, the conv_state is treated as a circular buffer.
213
+ The conv_state will be updated by copying x to the conv_state starting at the index
214
+ @cache_seqlens % state_len before performing the convolution.
215
+
216
+ out: (batch, dim) or (batch, dim, seqlen)
217
+ """
218
+ if activation not in [None, "silu", "swish"]:
219
+ raise NotImplementedError("activation must be None, silu, or swish")
220
+ dtype_in = x.dtype
221
+ unsqueeze = x.dim() == 2
222
+ if unsqueeze:
223
+ x = x.unsqueeze(-1)
224
+ batch, dim, seqlen = x.shape
225
+ width = weight.shape[1]
226
+ state_len = conv_state.shape[-1]
227
+ assert conv_state.shape == (batch, dim, state_len)
228
+ assert weight.shape == (dim, width)
229
+ if cache_seqlens is None:
230
+ x_new = torch.cat([conv_state, x], dim=-1).to(weight.dtype) # (batch, dim, state_len + seqlen)
231
+ conv_state.copy_(x_new[:, :, -state_len:])
232
+ else:
233
+ width_idx = torch.arange(-(width - 1), 0, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
234
+ width_idx = torch.remainder(width_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
235
+ x_new = torch.cat([conv_state.gather(2, width_idx), x], dim=-1).to(weight.dtype)
236
+ copy_idx = torch.arange(seqlen, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
237
+ copy_idx = torch.remainder(copy_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
238
+ conv_state.scatter_(2, copy_idx, x)
239
+ out = F.conv1d(x_new, weight.unsqueeze(1), bias, padding=0, groups=dim)[:, :, -seqlen:]
240
+ if unsqueeze:
241
+ out = out.squeeze(-1)
242
+ return (out if activation is None else F.silu(out)).to(dtype=dtype_in)
build/torch212-cxx11-cu132-x86_64-linux/causal_conv1d_varlen.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor
3
+
4
+ import triton
5
+ import triton.language as tl
6
+
7
+
8
+ @triton.jit
9
+ def _causal_conv1d_varlen_states(
10
+ X,
11
+ CU_SEQLENS,
12
+ STATES,
13
+ state_len,
14
+ dim,
15
+ stride_x_seqlen, stride_x_dim,
16
+ stride_states_batch, stride_states_seqlen, stride_states_dim,
17
+ BLOCK_M: tl.constexpr,
18
+ BLOCK_N: tl.constexpr
19
+ ):
20
+ batch_idx = tl.program_id(2)
21
+ STATES += batch_idx * stride_states_batch
22
+ end_idx = tl.load(CU_SEQLENS + batch_idx + 1)
23
+ start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len)
24
+ rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
25
+ cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)
26
+ x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] * stride_x_dim,
27
+ mask=(rows[:, None] >= start_idx) & (cols[None, :] < dim),
28
+ other=0)
29
+ rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
30
+ tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[None, :] * stride_states_dim,
31
+ x,
32
+ mask=(rows_states[:, None] >= 0) & (cols[None, :] < dim))
33
+
34
+
35
+ def causal_conv1d_varlen_states(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
36
+ """
37
+ Forward pass only, does not support backward pass.
38
+ Parameters:
39
+ x: (total_tokens, dim)
40
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
41
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
42
+ If some of those elements belong to a different sequence, the value of the states will be zero.
43
+ Return:
44
+ states: (batch, dim, state_len)
45
+ """
46
+ _, dim = x.shape
47
+ batch = cu_seqlens.shape[0] - 1
48
+ cu_seqlens = cu_seqlens.contiguous()
49
+ states = torch.empty(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
50
+ BLOCK_M = min(triton.next_power_of_2(state_len), 16)
51
+ BLOCK_N = min(triton.next_power_of_2(dim), 256)
52
+ grid = (triton.cdiv(dim, BLOCK_N), triton.cdiv(state_len, BLOCK_M), batch)
53
+ with getattr(torch, x.device.type).device(x.device.index):
54
+ _causal_conv1d_varlen_states[grid](
55
+ x,
56
+ cu_seqlens,
57
+ states,
58
+ state_len,
59
+ dim,
60
+ x.stride(0), x.stride(1),
61
+ states.stride(0), states.stride(2), states.stride(1),
62
+ BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N
63
+ )
64
+ return states
65
+
66
+
67
+ def causal_conv1d_varlen_states_ref(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
68
+ """
69
+ Forward pass only, does not support backward pass.
70
+ Parameters:
71
+ x: (total_tokens, dim)
72
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
73
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
74
+ If some of those elements belong to a different sequence, the value of the states will be zero.
75
+ Return:
76
+ states: (batch, dim, state_len)
77
+ """
78
+ _, dim = x.shape
79
+ batch = cu_seqlens.shape[0] - 1
80
+ cu_seqlens = cu_seqlens.contiguous()
81
+ states = torch.zeros(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
82
+ for i in range(batch):
83
+ end_idx = cu_seqlens[i + 1]
84
+ start_idx = torch.maximum(cu_seqlens[i], end_idx - state_len)
85
+ states[i, :, -(end_idx - start_idx):] = x[start_idx:end_idx].T
86
+ return states
build/torch212-cxx11-cu132-x86_64-linux/cpp_functions.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+
5
+ from ._ops import ops
6
+
7
+ def causal_conv1d_fwd_function(
8
+ x: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ bias: torch.Tensor | None,
11
+ seq_idx: torch.Tensor | None,
12
+ initial_states: torch.Tensor | None,
13
+ final_states_out: torch.Tensor | None,
14
+ silu_activation: bool,
15
+ ) -> torch.Tensor:
16
+ out = torch.empty_like(x)
17
+ ops.causal_conv1d_fwd(
18
+ x=x,
19
+ weight=weight,
20
+ bias=bias,
21
+ seq_idx=seq_idx,
22
+ initial_states=initial_states,
23
+ out=out,
24
+ final_states_out=final_states_out,
25
+ silu_activation=silu_activation,
26
+ )
27
+ return out
28
+
29
+
30
+ def causal_conv1d_bwd_function(
31
+ x: torch.Tensor,
32
+ weight: torch.Tensor,
33
+ bias: torch.Tensor | None,
34
+ dout: torch.Tensor,
35
+ seq_idx: torch.Tensor | None,
36
+ initial_states: torch.Tensor | None,
37
+ dfinal_states: torch.Tensor | None,
38
+ dx: torch.Tensor | None,
39
+ return_dinitial_states: torch.Tensor,
40
+ silu_activation: bool,
41
+ ) -> tuple[torch.Tensor | None]:
42
+ batch_size, dim = x.size()[:2]
43
+ width = weight.size(-1)
44
+
45
+ if dx is None:
46
+ dx = torch.empty_like(x)
47
+ dweight = torch.zeros_like(weight, dtype=torch.float32)
48
+ dbias = None
49
+ if bias is not None:
50
+ dbias = torch.zeros_like(bias, dtype=torch.float32)
51
+ dinitial_states = None
52
+ if return_dinitial_states:
53
+ dinitial_states = torch.empty(batch_size, width - 1, dim, device=x.device, dtype=x.dtype).transpose(1, 2)
54
+
55
+ ops.causal_conv1d_bwd(
56
+ x=x,
57
+ weight=weight,
58
+ bias=bias,
59
+ dout=dout,
60
+ seq_idx=seq_idx,
61
+ initial_states=initial_states,
62
+ dfinal_states=dfinal_states,
63
+ dx=dx,
64
+ dweight=dweight,
65
+ dbias=dbias,
66
+ dinitial_states=dinitial_states,
67
+ silu_activation=silu_activation,
68
+ )
69
+
70
+ dweight = dweight.type_as(weight)
71
+ if dbias is not None:
72
+ dbias = dbias.type_as(bias)
73
+ return dx, dweight, dbias, dinitial_states
74
+
75
+
76
+ def causal_conv1d_update_function(
77
+ x: torch.Tensor,
78
+ conv_state: torch.Tensor,
79
+ weight: torch.Tensor,
80
+ bias: torch.Tensor | None,
81
+ silu_activation: bool,
82
+ cache_seqlens: torch.Tensor | None,
83
+ conv_state_indices: torch.Tensor | None,
84
+ ) -> torch.Tensor:
85
+ out = torch.empty_like(x)
86
+ ops.causal_conv1d_update(
87
+ x=x,
88
+ conv_state=conv_state,
89
+ weight=weight,
90
+ bias=bias,
91
+ out=out,
92
+ silu_activation=silu_activation,
93
+ cache_seqlens=cache_seqlens,
94
+ conv_state_indices=conv_state_indices,
95
+ )
96
+ return out
build/torch212-cxx11-cu132-x86_64-linux/layers.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ from .causal_conv1d_interface import causal_conv1d_fn as kernel_causal_conv1d_fn
5
+ from .causal_conv1d_interface import causal_conv1d_update as kernel_causal_conv1d_update
6
+
7
+
8
+ class causal_conv1d_fn(nn.Module):
9
+ def forward(
10
+ self,
11
+ hidden_states: torch.Tensor,
12
+ weight: torch.Tensor,
13
+ bias: torch.Tensor | None = None,
14
+ activation: str | None = None,
15
+ **kwargs,
16
+ ):
17
+ # For varlen
18
+ seq_idx = kwargs.pop("seq_idx", None)
19
+
20
+ return kernel_causal_conv1d_fn(
21
+ x=hidden_states,
22
+ weight=weight,
23
+ bias=bias,
24
+ activation=activation,
25
+ seq_idx=seq_idx,
26
+ )
27
+
28
+
29
+ class causal_conv1d_update(nn.Module):
30
+ def forward(
31
+ self,
32
+ hidden_states: torch.Tensor,
33
+ conv_state: torch.Tensor,
34
+ weight: torch.Tensor,
35
+ bias: torch.Tensor | None = None,
36
+ activation: str | None = None,
37
+ ):
38
+ return kernel_causal_conv1d_update(
39
+ x=hidden_states,
40
+ conv_state=conv_state,
41
+ weight=weight,
42
+ bias=bias,
43
+ activation=activation,
44
+ )
45
+
46
+
47
+ __all__ = [
48
+ "causal_conv1d_fn",
49
+ "causal_conv1d_update",
50
+ ]
build/torch212-cxx11-cu132-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d",
3
+ "id": "_causal_conv1d_cuda_056e28b",
4
+ "version": 2,
5
+ "license": "BSD-3-Clause",
6
+ "python-depends": [],
7
+ "kernel-depends": [],
8
+ "backend": {
9
+ "type": "cuda",
10
+ "archs": [
11
+ "10.0",
12
+ "10.3",
13
+ "11.0",
14
+ "12.0",
15
+ "12.1+PTX",
16
+ "7.5",
17
+ "8.0",
18
+ "8.6",
19
+ "8.7",
20
+ "8.9",
21
+ "9.0"
22
+ ]
23
+ },
24
+ "digest": {
25
+ "algorithm": "sha256",
26
+ "files": {
27
+ "__init__.py": "ybfee7cD5pV/RtZZSki1skLZM+COZVoqTa+IlL+zY7E=",
28
+ "_causal_conv1d_cuda_056e28b.abi3.so": "QWaydK+yvnQ7Wd5uqupaXq5csR23eaahBaOvQD34xw0=",
29
+ "_ops.py": "in6wiEQzq3wMOxiS5jap8cHfMQFJoUmFV73UTM6S8S4=",
30
+ "causal_conv1d_interface.py": "Mm0fBbamT4dihp+Z53RzIFM/dn5Y8nLu1vJ4W4W53jQ=",
31
+ "causal_conv1d_varlen.py": "j6tdAEf/x0aBoNx3mEA9qo4xAxmH6fuUUdVnq7tuGgM=",
32
+ "cpp_functions.py": "gUG0/NiMaAmAHLZQ4TnnD5LyKJp9G/BlINOFXXcnlU8=",
33
+ "layers.py": "RH7iOTcjqtn3buFO7fGHfC/Pgu47eaX97ANzfwLD6C8="
34
+ }
35
+ },
36
+ "provenance": {
37
+ "kernel-builder": {
38
+ "version": "0.17.0-dev0",
39
+ "commit": "081dcd473f8eca27226eef1f9c47c45b86c756b5",
40
+ "dirty": false
41
+ },
42
+ "kernel": {
43
+ "commit": "056e28b85220c032b4dc1bb3dadebddd56dc228e",
44
+ "dirty": false
45
+ }
46
+ }
47
+ }
build/torch212-cxx11-cu132-x86_64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json", "verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtGgAwIBAgIUYAZG70VALPMX6ABwAPwtXzkyJCowCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQyMjQzWhcNMjYwOTA0MTQzMjQzWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEk+NZmSY+bKzK5t3gD9vxLLWxY1Bt2t1KRedfw7vaxS/VPuHBGvARLd+njOKIINBe1GqMERLSuvi1QT1xIcEbXaOCBfAwggXsMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUashmpWljW3TDR86zpOepwGqRPu0wHwYDVR0jBBgwFoAU39Ppz1YkEZb5qNjpKFWixi4YZD8wawYDVR0RAQH/BGEwX4ZdaHR0cHM6Ly9naXRodWIuY29tL2h1Z2dpbmdmYWNlL2tlcm5lbHMtY29tbXVuaXR5Ly5naXRodWIvd29ya2Zsb3dzL2J1aWxkLnlhbWxAcmVmcy9oZWFkcy9tYWluMDkGCisGAQQBg78wAQEEK2h0dHBzOi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rZXJuZWxzLWNvbW11bml0eS8uZ2l0aHViL3dvcmtmbG93cy9idWlsZC55YW1sQHJlZnMvaGVhZHMvbWFpbjA4BgorBgEEAYO/MAETBCoMKDA1NmUyOGI4NTIyMGMwMzJiNGRjMWJiM2RhZGViZGRkNTZkYzIyOGUwIQYKKwYBBAGDvzABFAQTDBF3b3JrZmxvd19kaXNwYXRjaDBkBgorBgEEAYO/MAEVBFYMVGh0dHBzOi8vZ2l0aHViLmNvbS9odWdnaW5nZmFjZS9rZXJuZWxzLWNvbW11bml0eS9hY3Rpb25zL3J1bnMvMzM4ODA5ODMwMzcvYXR0ZW1wdHMvMTAWBgorBgEEAYO/MAEWBAgMBnB1YmxpYzBGBgorBgEEAYO/MAEYBDgMNnJlcG86aHVnZ2luZ2ZhY2Uva2VybmVscy1jb21tdW5pdHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBigYKKwYBBAHWeQIEAgR8BHoAeAB2AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzM6ZIAAAQDAEcwRQIhAK38m0kCX8dDW3bBriXofhEqtovhwWhnfCZqxFHt0SZ+AiBx6E4EeJrEeRHMzE21jJBIGZEGnUdTLbP4/VZfx/n59DAKBggqhkjOPQQDAwNoADBlAjB0SKkBxIco3oOeP2dTLwhRhEI/Tv3Wmqr4WngHGOPTdnXFHZblXk8JNyRfMjm1i6kCMQCYwQOyI5rNPAThDjWDbwKAZ4tx5kmaQajddXnkY+Q2to8xhg2zJdC+LTBvfkPEZ4Q="}, "tlogEntries":[{"logIndex":"2712274654", "logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="}, "kindVersion":{"kind":"hashedrekord", "version":"0.0.1"}, "integratedTime":"1788531764", "inclusionPromise":{"signedEntryTimestamp":"MEYCIQDh6OJ6lpnWXKyO2xxBP0wqWIQRNznencR+8W2K6+h1KgIhAO2bafJAxXX7PRPjT+EJwol93nImtyXHXgjZ24ISjCXQ"}, "inclusionProof":{"logIndex":"2590370392", "rootHash":"Kg2lr4U+FftmnFCjjSRwCDlOQ+YUraf143fYI61JyoQ=", "treeSize":"2590370495", "hashes":["jZa0UWh6rc6JyxF1zh12P0TrSojcA44zX3yDmkvuz7Y=", "EMQs3fR0TZWFn5t9WJ7Kw5o2oC8hfWHIILJE9rrX1Ng=", "T/Rr/B6UND0XNePfS+0zV58kmUYmgor574+TaKQZ9fw=", "8hGwLt/JJMJxVAf2SAwvKiBwwqKwihIARALT30tNgMs=", "RoR53FZk/O1jwxxwztQHdrsPDMz1EG1reQClkAScJRY=", "CtpWe866rpU7oBxd3Ga4PZi5HXcc+KARAj3CmxL4dPs=", "wQuI88fXxNVhR/6N0uw9GpZGNPUC/f7GaNLqwBisoY4=", "CGgrayrnC7lQqGXXevaCxlDgrvMfOraDd0LwueLmMZ8=", "A7DmwgbRSrc2LD36Ce5iqpi/zjfceiCQMFKHmZVjcEA=", "an7xDmqrJ5PN89Dsx6EqYZmD0qEyAoXB9zuf+Z0A9kc=", "dpE4JeS09wbniSRpzbHmp3WEjZfaXFuaxQ/Jz4h8Qdo=", "5BBv7rWK6NFgtdHnmpxaOG4IgQ2e23dxOnb7iVqIJfs=", "CVXlwy6p/0g8OGYc+N5iYlD4qo/oIV4lgJstV8/jX9Y=", "JLnTjrlsTfbD8CvvizQuzVwJPXlC98tLzdnXZ1HqaTI=", "wgA+dB9j8L++Xwb+XT+v0evEwWqMLyd201Sc69PSLzg=", "N+foNlyVQOzU7HZsPPSKIQU/1+E+tmJj33u2r6dwmBs=", "I1FtczpUgFViy1Ae7CAfwglj2nSpp5nZrcsYauARxMs=", "fnPrvt7afEuTlIhaMcrGUdu9+heAmk4jOJ3+Br8/B8M=", "eXSLrLqKSxRTixSP/k4YimriB2lufao6trqTrsxxlyg=", "SndbMKVtcTenAkwi2JBfGzD+mhexp1qJbRIY+A1JRIU=", "xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="], "checkpoint":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CLuJAZgV9PI0h3R8ZLLZLjskDKmlAiBYDWYd3ioWNQakJ9CfGJzfcK7qn78+v96VaNmoAB35zw=="}}
build/torch213-cxx11-cu126-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+ from .causal_conv1d_interface import causal_conv1d_fn, causal_conv1d_update
3
+ from .causal_conv1d_varlen import causal_conv1d_varlen_states
4
+
5
+ __all__ = [
6
+ # wrappers
7
+ "layers",
8
+ # originals
9
+ "causal_conv1d_fn",
10
+ "causal_conv1d_update",
11
+ "causal_conv1d_varlen_states",
12
+ ]
build/torch213-cxx11-cu126-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f21eb7a4c65dd97d54d45d014ae2c122b8f026cc186b83da7418157ae421dd34
3
+ size 78812136
build/torch213-cxx11-cu126-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_cuda_056e28b
3
+ ops = torch.ops._causal_conv1d_cuda_056e28b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_cuda_056e28b::{op_name}"
build/torch213-cxx11-cu126-x86_64-linux/causal_conv1d_interface.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ from .cpp_functions import causal_conv1d_fwd_function, causal_conv1d_bwd_function, causal_conv1d_update_function
7
+
8
+
9
+ class CausalConv1dFn(torch.autograd.Function):
10
+ @staticmethod
11
+ def forward(
12
+ ctx,
13
+ x,
14
+ weight,
15
+ bias=None,
16
+ seq_idx=None,
17
+ initial_states=None,
18
+ return_final_states=False,
19
+ final_states_out=None,
20
+ activation=None,
21
+ ):
22
+ if activation not in [None, "silu", "swish"]:
23
+ raise NotImplementedError("activation must be None, silu, or swish")
24
+ if x.stride(2) != 1 and x.stride(1) != 1:
25
+ x = x.contiguous()
26
+ bias = bias.contiguous() if bias is not None else None
27
+ if seq_idx is not None:
28
+ assert (
29
+ initial_states is None
30
+ ), "initial_states must be None if seq_idx is not None"
31
+ assert (
32
+ not return_final_states
33
+ ), "If seq_idx is not None, we don't return final_states_out"
34
+ seq_idx = seq_idx.contiguous() if seq_idx is not None else None
35
+ if initial_states is not None and (
36
+ initial_states.stride(2) != 1 and initial_states.stride(1) != 1
37
+ ):
38
+ initial_states = initial_states.contiguous()
39
+ if return_final_states:
40
+ assert (
41
+ x.stride(1) == 1
42
+ ), "Only channel-last layout support returning final_states_out"
43
+ if final_states_out is not None:
44
+ assert (
45
+ final_states_out.stride(2) == 1 or final_states_out.stride(1) == 1
46
+ )
47
+ else:
48
+ batch, dim, seqlen = x.shape
49
+ width = weight.shape[1]
50
+ final_states_out = torch.empty(
51
+ batch, width - 1, dim, device=x.device, dtype=x.dtype
52
+ ).transpose(1, 2)
53
+ else:
54
+ final_states_out = None
55
+ ctx.activation = activation in ["silu", "swish"]
56
+ out = causal_conv1d_fwd_function(
57
+ x, weight, bias, seq_idx, initial_states, final_states_out, ctx.activation
58
+ )
59
+ ctx.save_for_backward(x, weight, bias, seq_idx, initial_states)
60
+ ctx.return_final_states = return_final_states
61
+ ctx.return_dinitial_states = (
62
+ initial_states is not None and initial_states.requires_grad
63
+ )
64
+ return out if not return_final_states else (out, final_states_out)
65
+
66
+ @staticmethod
67
+ def backward(ctx, dout, *args):
68
+ x, weight, bias, seq_idx, initial_states = ctx.saved_tensors
69
+ dfinal_states = args[0] if ctx.return_final_states else None
70
+ if dout.stride(2) != 1 and dout.stride(1) != 1:
71
+ dout = dout.contiguous()
72
+ # The kernel supports passing in a pre-allocated dx (e.g., in case we want to fuse the
73
+ # backward of conv1d with the backward of chunk).
74
+ # Here we just pass in None and dx will be allocated in the C++ code.
75
+ dx, dweight, dbias, dinitial_states = causal_conv1d_bwd_function(
76
+ x,
77
+ weight,
78
+ bias,
79
+ dout,
80
+ seq_idx,
81
+ initial_states,
82
+ dfinal_states,
83
+ None,
84
+ ctx.return_dinitial_states,
85
+ ctx.activation,
86
+ )
87
+ return (
88
+ dx,
89
+ dweight,
90
+ dbias if bias is not None else None,
91
+ None,
92
+ dinitial_states if initial_states is not None else None,
93
+ None,
94
+ None,
95
+ None,
96
+ )
97
+
98
+
99
+ def causal_conv1d_fn(
100
+ x,
101
+ weight,
102
+ bias=None,
103
+ seq_idx=None,
104
+ initial_states=None,
105
+ return_final_states=False,
106
+ final_states_out=None,
107
+ activation=None,
108
+ ):
109
+ """
110
+ x: (batch, dim, seqlen)
111
+ weight: (dim, width)
112
+ bias: (dim,)
113
+ seq_idx: (batch, seqlen)
114
+ initial_states: (batch, dim, width - 1)
115
+ final_states_out: (batch, dim, width - 1), to be written to
116
+ activation: either None or "silu" or "swish"
117
+
118
+ out: (batch, dim, seqlen)
119
+ """
120
+ return CausalConv1dFn.apply(
121
+ x,
122
+ weight,
123
+ bias,
124
+ seq_idx,
125
+ initial_states,
126
+ return_final_states,
127
+ final_states_out,
128
+ activation,
129
+ )
130
+
131
+
132
+ def causal_conv1d_ref(
133
+ x,
134
+ weight,
135
+ bias=None,
136
+ initial_states=None,
137
+ return_final_states=False,
138
+ final_states_out=None,
139
+ activation=None,
140
+ ):
141
+ """
142
+ x: (batch, dim, seqlen)
143
+ weight: (dim, width)
144
+ bias: (dim,)
145
+ initial_states: (batch, dim, width - 1)
146
+ final_states_out: (batch, dim, width - 1)
147
+
148
+ out: (batch, dim, seqlen)
149
+ """
150
+ if activation not in [None, "silu", "swish"]:
151
+ raise NotImplementedError("activation must be None, silu, or swish")
152
+ dtype_in = x.dtype
153
+ x = x.to(weight.dtype)
154
+ seqlen = x.shape[-1]
155
+ dim, width = weight.shape
156
+ if initial_states is None:
157
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
158
+ else:
159
+ x = torch.cat([initial_states, x], dim=-1)
160
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=0, groups=dim)
161
+ out = out[..., :seqlen]
162
+ if return_final_states:
163
+ final_states = F.pad(x, (width - 1 - x.shape[-1], 0)).to(
164
+ dtype_in
165
+ ) # (batch, dim, width - 1)
166
+ if final_states_out is not None:
167
+ final_states_out.copy_(final_states)
168
+ else:
169
+ final_states_out = final_states
170
+ out = (out if activation is None else F.silu(out)).to(dtype=dtype_in)
171
+ return out if not return_final_states else (out, final_states_out)
172
+
173
+
174
+ def causal_conv1d_update(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None, conv_state_indices=None):
175
+ """
176
+ x: (batch, dim) or (batch, dim, seqlen)
177
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
178
+ weight: (dim, width)
179
+ bias: (dim,)
180
+ cache_seqlens: (batch,), dtype int32.
181
+ If not None, the conv_state is treated as a circular buffer.
182
+ The conv_state will be updated by copying x to the conv_state starting at the index
183
+ @cache_seqlens % state_len.
184
+ conv_state_indices: (batch,), dtype int32
185
+ If None, the conv_state is a larger tensor along the batch dim,
186
+ and we are selecting the batch coords specified by conv_state_indices.
187
+ Useful for a continuous batching scenario.
188
+
189
+ out: (batch, dim) or (batch, dim, seqlen)
190
+ """
191
+ if activation not in [None, "silu", "swish"]:
192
+ raise NotImplementedError("activation must be None, silu, or swish")
193
+ activation = activation in ["silu", "swish"]
194
+ unsqueeze = x.dim() == 2
195
+ if unsqueeze:
196
+ x = x.unsqueeze(-1)
197
+ out = causal_conv1d_update_function(
198
+ x, conv_state, weight, bias, activation, cache_seqlens, conv_state_indices
199
+ )
200
+ if unsqueeze:
201
+ out = out.squeeze(-1)
202
+ return out
203
+
204
+
205
+ def causal_conv1d_update_ref(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None):
206
+ """
207
+ x: (batch, dim) or (batch, dim, seqlen)
208
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
209
+ weight: (dim, width)
210
+ bias: (dim,)
211
+ cache_seqlens: (batch,), dtype int32.
212
+ If not None, the conv_state is treated as a circular buffer.
213
+ The conv_state will be updated by copying x to the conv_state starting at the index
214
+ @cache_seqlens % state_len before performing the convolution.
215
+
216
+ out: (batch, dim) or (batch, dim, seqlen)
217
+ """
218
+ if activation not in [None, "silu", "swish"]:
219
+ raise NotImplementedError("activation must be None, silu, or swish")
220
+ dtype_in = x.dtype
221
+ unsqueeze = x.dim() == 2
222
+ if unsqueeze:
223
+ x = x.unsqueeze(-1)
224
+ batch, dim, seqlen = x.shape
225
+ width = weight.shape[1]
226
+ state_len = conv_state.shape[-1]
227
+ assert conv_state.shape == (batch, dim, state_len)
228
+ assert weight.shape == (dim, width)
229
+ if cache_seqlens is None:
230
+ x_new = torch.cat([conv_state, x], dim=-1).to(weight.dtype) # (batch, dim, state_len + seqlen)
231
+ conv_state.copy_(x_new[:, :, -state_len:])
232
+ else:
233
+ width_idx = torch.arange(-(width - 1), 0, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
234
+ width_idx = torch.remainder(width_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
235
+ x_new = torch.cat([conv_state.gather(2, width_idx), x], dim=-1).to(weight.dtype)
236
+ copy_idx = torch.arange(seqlen, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
237
+ copy_idx = torch.remainder(copy_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
238
+ conv_state.scatter_(2, copy_idx, x)
239
+ out = F.conv1d(x_new, weight.unsqueeze(1), bias, padding=0, groups=dim)[:, :, -seqlen:]
240
+ if unsqueeze:
241
+ out = out.squeeze(-1)
242
+ return (out if activation is None else F.silu(out)).to(dtype=dtype_in)
build/torch213-cxx11-cu126-x86_64-linux/causal_conv1d_varlen.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor
3
+
4
+ import triton
5
+ import triton.language as tl
6
+
7
+
8
+ @triton.jit
9
+ def _causal_conv1d_varlen_states(
10
+ X,
11
+ CU_SEQLENS,
12
+ STATES,
13
+ state_len,
14
+ dim,
15
+ stride_x_seqlen, stride_x_dim,
16
+ stride_states_batch, stride_states_seqlen, stride_states_dim,
17
+ BLOCK_M: tl.constexpr,
18
+ BLOCK_N: tl.constexpr
19
+ ):
20
+ batch_idx = tl.program_id(2)
21
+ STATES += batch_idx * stride_states_batch
22
+ end_idx = tl.load(CU_SEQLENS + batch_idx + 1)
23
+ start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len)
24
+ rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
25
+ cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)
26
+ x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] * stride_x_dim,
27
+ mask=(rows[:, None] >= start_idx) & (cols[None, :] < dim),
28
+ other=0)
29
+ rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
30
+ tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[None, :] * stride_states_dim,
31
+ x,
32
+ mask=(rows_states[:, None] >= 0) & (cols[None, :] < dim))
33
+
34
+
35
+ def causal_conv1d_varlen_states(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
36
+ """
37
+ Forward pass only, does not support backward pass.
38
+ Parameters:
39
+ x: (total_tokens, dim)
40
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
41
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
42
+ If some of those elements belong to a different sequence, the value of the states will be zero.
43
+ Return:
44
+ states: (batch, dim, state_len)
45
+ """
46
+ _, dim = x.shape
47
+ batch = cu_seqlens.shape[0] - 1
48
+ cu_seqlens = cu_seqlens.contiguous()
49
+ states = torch.empty(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
50
+ BLOCK_M = min(triton.next_power_of_2(state_len), 16)
51
+ BLOCK_N = min(triton.next_power_of_2(dim), 256)
52
+ grid = (triton.cdiv(dim, BLOCK_N), triton.cdiv(state_len, BLOCK_M), batch)
53
+ with getattr(torch, x.device.type).device(x.device.index):
54
+ _causal_conv1d_varlen_states[grid](
55
+ x,
56
+ cu_seqlens,
57
+ states,
58
+ state_len,
59
+ dim,
60
+ x.stride(0), x.stride(1),
61
+ states.stride(0), states.stride(2), states.stride(1),
62
+ BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N
63
+ )
64
+ return states
65
+
66
+
67
+ def causal_conv1d_varlen_states_ref(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
68
+ """
69
+ Forward pass only, does not support backward pass.
70
+ Parameters:
71
+ x: (total_tokens, dim)
72
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
73
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
74
+ If some of those elements belong to a different sequence, the value of the states will be zero.
75
+ Return:
76
+ states: (batch, dim, state_len)
77
+ """
78
+ _, dim = x.shape
79
+ batch = cu_seqlens.shape[0] - 1
80
+ cu_seqlens = cu_seqlens.contiguous()
81
+ states = torch.zeros(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
82
+ for i in range(batch):
83
+ end_idx = cu_seqlens[i + 1]
84
+ start_idx = torch.maximum(cu_seqlens[i], end_idx - state_len)
85
+ states[i, :, -(end_idx - start_idx):] = x[start_idx:end_idx].T
86
+ return states
build/torch213-cxx11-cu126-x86_64-linux/cpp_functions.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+
5
+ from ._ops import ops
6
+
7
+ def causal_conv1d_fwd_function(
8
+ x: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ bias: torch.Tensor | None,
11
+ seq_idx: torch.Tensor | None,
12
+ initial_states: torch.Tensor | None,
13
+ final_states_out: torch.Tensor | None,
14
+ silu_activation: bool,
15
+ ) -> torch.Tensor:
16
+ out = torch.empty_like(x)
17
+ ops.causal_conv1d_fwd(
18
+ x=x,
19
+ weight=weight,
20
+ bias=bias,
21
+ seq_idx=seq_idx,
22
+ initial_states=initial_states,
23
+ out=out,
24
+ final_states_out=final_states_out,
25
+ silu_activation=silu_activation,
26
+ )
27
+ return out
28
+
29
+
30
+ def causal_conv1d_bwd_function(
31
+ x: torch.Tensor,
32
+ weight: torch.Tensor,
33
+ bias: torch.Tensor | None,
34
+ dout: torch.Tensor,
35
+ seq_idx: torch.Tensor | None,
36
+ initial_states: torch.Tensor | None,
37
+ dfinal_states: torch.Tensor | None,
38
+ dx: torch.Tensor | None,
39
+ return_dinitial_states: torch.Tensor,
40
+ silu_activation: bool,
41
+ ) -> tuple[torch.Tensor | None]:
42
+ batch_size, dim = x.size()[:2]
43
+ width = weight.size(-1)
44
+
45
+ if dx is None:
46
+ dx = torch.empty_like(x)
47
+ dweight = torch.zeros_like(weight, dtype=torch.float32)
48
+ dbias = None
49
+ if bias is not None:
50
+ dbias = torch.zeros_like(bias, dtype=torch.float32)
51
+ dinitial_states = None
52
+ if return_dinitial_states:
53
+ dinitial_states = torch.empty(batch_size, width - 1, dim, device=x.device, dtype=x.dtype).transpose(1, 2)
54
+
55
+ ops.causal_conv1d_bwd(
56
+ x=x,
57
+ weight=weight,
58
+ bias=bias,
59
+ dout=dout,
60
+ seq_idx=seq_idx,
61
+ initial_states=initial_states,
62
+ dfinal_states=dfinal_states,
63
+ dx=dx,
64
+ dweight=dweight,
65
+ dbias=dbias,
66
+ dinitial_states=dinitial_states,
67
+ silu_activation=silu_activation,
68
+ )
69
+
70
+ dweight = dweight.type_as(weight)
71
+ if dbias is not None:
72
+ dbias = dbias.type_as(bias)
73
+ return dx, dweight, dbias, dinitial_states
74
+
75
+
76
+ def causal_conv1d_update_function(
77
+ x: torch.Tensor,
78
+ conv_state: torch.Tensor,
79
+ weight: torch.Tensor,
80
+ bias: torch.Tensor | None,
81
+ silu_activation: bool,
82
+ cache_seqlens: torch.Tensor | None,
83
+ conv_state_indices: torch.Tensor | None,
84
+ ) -> torch.Tensor:
85
+ out = torch.empty_like(x)
86
+ ops.causal_conv1d_update(
87
+ x=x,
88
+ conv_state=conv_state,
89
+ weight=weight,
90
+ bias=bias,
91
+ out=out,
92
+ silu_activation=silu_activation,
93
+ cache_seqlens=cache_seqlens,
94
+ conv_state_indices=conv_state_indices,
95
+ )
96
+ return out
build/torch213-cxx11-cu126-x86_64-linux/layers.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ from .causal_conv1d_interface import causal_conv1d_fn as kernel_causal_conv1d_fn
5
+ from .causal_conv1d_interface import causal_conv1d_update as kernel_causal_conv1d_update
6
+
7
+
8
+ class causal_conv1d_fn(nn.Module):
9
+ def forward(
10
+ self,
11
+ hidden_states: torch.Tensor,
12
+ weight: torch.Tensor,
13
+ bias: torch.Tensor | None = None,
14
+ activation: str | None = None,
15
+ **kwargs,
16
+ ):
17
+ # For varlen
18
+ seq_idx = kwargs.pop("seq_idx", None)
19
+
20
+ return kernel_causal_conv1d_fn(
21
+ x=hidden_states,
22
+ weight=weight,
23
+ bias=bias,
24
+ activation=activation,
25
+ seq_idx=seq_idx,
26
+ )
27
+
28
+
29
+ class causal_conv1d_update(nn.Module):
30
+ def forward(
31
+ self,
32
+ hidden_states: torch.Tensor,
33
+ conv_state: torch.Tensor,
34
+ weight: torch.Tensor,
35
+ bias: torch.Tensor | None = None,
36
+ activation: str | None = None,
37
+ ):
38
+ return kernel_causal_conv1d_update(
39
+ x=hidden_states,
40
+ conv_state=conv_state,
41
+ weight=weight,
42
+ bias=bias,
43
+ activation=activation,
44
+ )
45
+
46
+
47
+ __all__ = [
48
+ "causal_conv1d_fn",
49
+ "causal_conv1d_update",
50
+ ]
build/torch213-cxx11-cu126-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d",
3
+ "id": "_causal_conv1d_cuda_056e28b",
4
+ "version": 2,
5
+ "license": "BSD-3-Clause",
6
+ "python-depends": [],
7
+ "kernel-depends": [],
8
+ "backend": {
9
+ "type": "cuda",
10
+ "archs": [
11
+ "7.0",
12
+ "7.2",
13
+ "7.5",
14
+ "8.0",
15
+ "8.6",
16
+ "8.7",
17
+ "8.9",
18
+ "9.0+PTX"
19
+ ]
20
+ },
21
+ "digest": {
22
+ "algorithm": "sha256",
23
+ "files": {
24
+ "__init__.py": "ybfee7cD5pV/RtZZSki1skLZM+COZVoqTa+IlL+zY7E=",
25
+ "_causal_conv1d_cuda_056e28b.abi3.so": "8h63pMZd2X1U1F0BSuLBIrjwJswYa4PadBgVeuQh3TQ=",
26
+ "_ops.py": "in6wiEQzq3wMOxiS5jap8cHfMQFJoUmFV73UTM6S8S4=",
27
+ "causal_conv1d_interface.py": "Mm0fBbamT4dihp+Z53RzIFM/dn5Y8nLu1vJ4W4W53jQ=",
28
+ "causal_conv1d_varlen.py": "j6tdAEf/x0aBoNx3mEA9qo4xAxmH6fuUUdVnq7tuGgM=",
29
+ "cpp_functions.py": "gUG0/NiMaAmAHLZQ4TnnD5LyKJp9G/BlINOFXXcnlU8=",
30
+ "layers.py": "RH7iOTcjqtn3buFO7fGHfC/Pgu47eaX97ANzfwLD6C8="
31
+ }
32
+ },
33
+ "provenance": {
34
+ "kernel-builder": {
35
+ "version": "0.17.0-dev0",
36
+ "commit": "081dcd473f8eca27226eef1f9c47c45b86c756b5",
37
+ "dirty": false
38
+ },
39
+ "kernel": {
40
+ "commit": "056e28b85220c032b4dc1bb3dadebddd56dc228e",
41
+ "dirty": false
42
+ }
43
+ }
44
+ }
build/torch213-cxx11-cu126-x86_64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json", "verificationMaterial":{"certificate":{"rawBytes":"MIIHSTCCB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dHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBiQYKKwYBBAHWeQIEAgR7BHkAdwB1AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzM8PkAAAQDAEYwRAIgPlqgkirqsnGD526jzoDauqThlzdqP2y1fOSsFpQiAt8CIFAWtI2Jcp7I8tZ9nZnlg8FPVKvmJGsQVIy+TuwQhdfsMAoGCCqGSM49BAMDA2cAMGQCMHpyjroXuk7Itte7Vle0VonOEJuixoLD9ScFZyTGCmq1wJTpkpQau8agFW6Ofi39PwIwU1YQY01F8MfQp6eSn5tfNWgpNzOtEj5MUImq3KVmFrfpZ9rka6A8pqCAF4PDpiyA"}, "tlogEntries":[{"logIndex":"2712275010", "logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="}, "kindVersion":{"kind":"hashedrekord", "version":"0.0.1"}, "integratedTime":"1788531765", "inclusionPromise":{"signedEntryTimestamp":"MEYCIQCoEQXv6CZ0h7sbt8KJ18ENZJjSTuP5/0hXAG/oSkQFxAIhAMkJPs0/BpNa3zMKUrZakWOQ8HtZBu0kifcflHIrhd2J"}, "inclusionProof":{"logIndex":"2590370748", "rootHash":"WOJLb40JriEpuLbrlz/LQ2ON2KZ63diIlkyYJTO/V00=", "treeSize":"2590371118", "hashes":["hoCwHV5wS2eX/GEAEYnRA32fARQgHdQI0NgY9gpsxck=", "DzhieRVOg5oDP9nufVqjN/xs+TCiaUmdMD53txGNuj8=", "xNQW5rvIe6HsBxQ584Tt0yO28Z5Kg/XU5pgVhCYEi2k=", "jt8hmsedaygU1zcccj2AkWYwOYhPRhZvMonuKb19UiQ=", "Fz/nPuKIZRFOvxwHgpV6RSBMZZNC7OEEuIQHk0LVOYI=", "4FGqcl05Fiv3t/BwnWcFl7hjF5mj8fbRiMOszVejPRA=", "N48MgevKmVgqqIUhg510nDYN6OX9j8KSH/voGD6kX8w=", "kD8wHY8/mWQf9NSx1KlBvrv/pCjwnpcGizYj75j9/1Y=", "V7TZwsfTzq2H/ncdMBBxWAa/YpFiAOmK4N7fGo+7YH0=", "A7DmwgbRSrc2LD36Ce5iqpi/zjfceiCQMFKHmZVjcEA=", "ux91q8ob/83kyNNg3zkFrSzwdug06vebJ9S2BIdw0z0=", "an7xDmqrJ5PN89Dsx6EqYZmD0qEyAoXB9zuf+Z0A9kc=", "dpE4JeS09wbniSRpzbHmp3WEjZfaXFuaxQ/Jz4h8Qdo=", "5BBv7rWK6NFgtdHnmpxaOG4IgQ2e23dxOnb7iVqIJfs=", "CVXlwy6p/0g8OGYc+N5iYlD4qo/oIV4lgJstV8/jX9Y=", "JLnTjrlsTfbD8CvvizQuzVwJPXlC98tLzdnXZ1HqaTI=", "wgA+dB9j8L++Xwb+XT+v0evEwWqMLyd201Sc69PSLzg=", "N+foNlyVQOzU7HZsPPSKIQU/1+E+tmJj33u2r6dwmBs=", "I1FtczpUgFViy1Ae7CAfwglj2nSpp5nZrcsYauARxMs=", "fnPrvt7afEuTlIhaMcrGUdu9+heAmk4jOJ3+Br8/B8M=", "eXSLrLqKSxRTixSP/k4YimriB2lufao6trqTrsxxlyg=", "SndbMKVtcTenAkwi2JBfGzD+mhexp1qJbRIY+A1JRIU=", "xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="], "checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n2590371118\nWOJLb40JriEpuLbrlz/LQ2ON2KZ63diIlkyYJTO/V00=\n\n— rekor.sigstore.dev wNI9ajBFAiAd8xsy+pEONo4M6B960TxtTwa4GSAkmyQa9EbRbu0fxQIhAJkyFwVHEtEpNvo5T1NG/bQEcvAINjFrndZSq4yTVaYF\n"}}, "canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiI5NTZkZD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pZ3N0b3JlLmRldjEgMB4GA1UEAxMXc2lnc3RvcmUtdHNhLXNlbGZzaWduZWQCFDoTVC8MkGHuvMFDL8uKjosqI4sMMAsGCWCGSAFlAwQCAaCB/DAaBgkqhkiG9w0BCQMxDQYLKoZIhvcNAQkQAQQwHAYJKoZIhvcNAQkFMQ8XDTI2MDkwNDE0MjI0NVowLwYJKoZIhvcNAQkEMSIEIHnA9HVgYJMUrqjDANy9gy5N+bDW/DCFCLhj3ajj1IWUMIGOBgsqhkiG9w0BCRACLzF/MH0wezB5BCCF+Se8B6tiysO0Q1bBDvyBssaIP9p6uebYcNnROs0FtzBVMD2kOzA5MRUwEwYDVQQKEwxzaWdzdG9yZS5kZXYxIDAeBgNVBAMTF3NpZ3N0b3JlLXRzYS1zZWxmc2lnbmVkAhQ6E1QvDJBh7rzBQy/Lio6LKiOLDDAKBggqhkjOPQQDAgRoMGYCMQCZbxfe1smZvPl76BDtLzO/UD9RYjrf8cAVVOsykfT62iuAFyy2lkAgEpxJL6KHmEYCMQDUp28X/vEUZRrAYEbx/vGyTudTjf+ak7XqFSxHXVJjPCTv4y6eaBx6BnEBNrSVVWo="}]}}, "messageSignature":{"messageDigest":{"algorithm":"SHA2_256", "digest":"lW3Z3Hv8JtusC1wEE1GE0vTxQwSS/wg761aAw3KuTOo="}, "signature":"MEUCIQCrITPdAA0NHyM919qexsZskClmgrWiXTb9L1dBHUnlvwIgcfEP10ULn3E426lZd+Jto9801/8vQJHwqpVZkHZ8hvk="}}
build/torch213-cxx11-cu130-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+ from .causal_conv1d_interface import causal_conv1d_fn, causal_conv1d_update
3
+ from .causal_conv1d_varlen import causal_conv1d_varlen_states
4
+
5
+ __all__ = [
6
+ # wrappers
7
+ "layers",
8
+ # originals
9
+ "causal_conv1d_fn",
10
+ "causal_conv1d_update",
11
+ "causal_conv1d_varlen_states",
12
+ ]
build/torch213-cxx11-cu130-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ccc666dc1cf38c3114cf46a41c893a5516d0fc6d68b5c144356e76df05ff08e
3
+ size 74854720
build/torch213-cxx11-cu130-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_cuda_056e28b
3
+ ops = torch.ops._causal_conv1d_cuda_056e28b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_cuda_056e28b::{op_name}"
build/torch213-cxx11-cu130-x86_64-linux/causal_conv1d_interface.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ from .cpp_functions import causal_conv1d_fwd_function, causal_conv1d_bwd_function, causal_conv1d_update_function
7
+
8
+
9
+ class CausalConv1dFn(torch.autograd.Function):
10
+ @staticmethod
11
+ def forward(
12
+ ctx,
13
+ x,
14
+ weight,
15
+ bias=None,
16
+ seq_idx=None,
17
+ initial_states=None,
18
+ return_final_states=False,
19
+ final_states_out=None,
20
+ activation=None,
21
+ ):
22
+ if activation not in [None, "silu", "swish"]:
23
+ raise NotImplementedError("activation must be None, silu, or swish")
24
+ if x.stride(2) != 1 and x.stride(1) != 1:
25
+ x = x.contiguous()
26
+ bias = bias.contiguous() if bias is not None else None
27
+ if seq_idx is not None:
28
+ assert (
29
+ initial_states is None
30
+ ), "initial_states must be None if seq_idx is not None"
31
+ assert (
32
+ not return_final_states
33
+ ), "If seq_idx is not None, we don't return final_states_out"
34
+ seq_idx = seq_idx.contiguous() if seq_idx is not None else None
35
+ if initial_states is not None and (
36
+ initial_states.stride(2) != 1 and initial_states.stride(1) != 1
37
+ ):
38
+ initial_states = initial_states.contiguous()
39
+ if return_final_states:
40
+ assert (
41
+ x.stride(1) == 1
42
+ ), "Only channel-last layout support returning final_states_out"
43
+ if final_states_out is not None:
44
+ assert (
45
+ final_states_out.stride(2) == 1 or final_states_out.stride(1) == 1
46
+ )
47
+ else:
48
+ batch, dim, seqlen = x.shape
49
+ width = weight.shape[1]
50
+ final_states_out = torch.empty(
51
+ batch, width - 1, dim, device=x.device, dtype=x.dtype
52
+ ).transpose(1, 2)
53
+ else:
54
+ final_states_out = None
55
+ ctx.activation = activation in ["silu", "swish"]
56
+ out = causal_conv1d_fwd_function(
57
+ x, weight, bias, seq_idx, initial_states, final_states_out, ctx.activation
58
+ )
59
+ ctx.save_for_backward(x, weight, bias, seq_idx, initial_states)
60
+ ctx.return_final_states = return_final_states
61
+ ctx.return_dinitial_states = (
62
+ initial_states is not None and initial_states.requires_grad
63
+ )
64
+ return out if not return_final_states else (out, final_states_out)
65
+
66
+ @staticmethod
67
+ def backward(ctx, dout, *args):
68
+ x, weight, bias, seq_idx, initial_states = ctx.saved_tensors
69
+ dfinal_states = args[0] if ctx.return_final_states else None
70
+ if dout.stride(2) != 1 and dout.stride(1) != 1:
71
+ dout = dout.contiguous()
72
+ # The kernel supports passing in a pre-allocated dx (e.g., in case we want to fuse the
73
+ # backward of conv1d with the backward of chunk).
74
+ # Here we just pass in None and dx will be allocated in the C++ code.
75
+ dx, dweight, dbias, dinitial_states = causal_conv1d_bwd_function(
76
+ x,
77
+ weight,
78
+ bias,
79
+ dout,
80
+ seq_idx,
81
+ initial_states,
82
+ dfinal_states,
83
+ None,
84
+ ctx.return_dinitial_states,
85
+ ctx.activation,
86
+ )
87
+ return (
88
+ dx,
89
+ dweight,
90
+ dbias if bias is not None else None,
91
+ None,
92
+ dinitial_states if initial_states is not None else None,
93
+ None,
94
+ None,
95
+ None,
96
+ )
97
+
98
+
99
+ def causal_conv1d_fn(
100
+ x,
101
+ weight,
102
+ bias=None,
103
+ seq_idx=None,
104
+ initial_states=None,
105
+ return_final_states=False,
106
+ final_states_out=None,
107
+ activation=None,
108
+ ):
109
+ """
110
+ x: (batch, dim, seqlen)
111
+ weight: (dim, width)
112
+ bias: (dim,)
113
+ seq_idx: (batch, seqlen)
114
+ initial_states: (batch, dim, width - 1)
115
+ final_states_out: (batch, dim, width - 1), to be written to
116
+ activation: either None or "silu" or "swish"
117
+
118
+ out: (batch, dim, seqlen)
119
+ """
120
+ return CausalConv1dFn.apply(
121
+ x,
122
+ weight,
123
+ bias,
124
+ seq_idx,
125
+ initial_states,
126
+ return_final_states,
127
+ final_states_out,
128
+ activation,
129
+ )
130
+
131
+
132
+ def causal_conv1d_ref(
133
+ x,
134
+ weight,
135
+ bias=None,
136
+ initial_states=None,
137
+ return_final_states=False,
138
+ final_states_out=None,
139
+ activation=None,
140
+ ):
141
+ """
142
+ x: (batch, dim, seqlen)
143
+ weight: (dim, width)
144
+ bias: (dim,)
145
+ initial_states: (batch, dim, width - 1)
146
+ final_states_out: (batch, dim, width - 1)
147
+
148
+ out: (batch, dim, seqlen)
149
+ """
150
+ if activation not in [None, "silu", "swish"]:
151
+ raise NotImplementedError("activation must be None, silu, or swish")
152
+ dtype_in = x.dtype
153
+ x = x.to(weight.dtype)
154
+ seqlen = x.shape[-1]
155
+ dim, width = weight.shape
156
+ if initial_states is None:
157
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
158
+ else:
159
+ x = torch.cat([initial_states, x], dim=-1)
160
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=0, groups=dim)
161
+ out = out[..., :seqlen]
162
+ if return_final_states:
163
+ final_states = F.pad(x, (width - 1 - x.shape[-1], 0)).to(
164
+ dtype_in
165
+ ) # (batch, dim, width - 1)
166
+ if final_states_out is not None:
167
+ final_states_out.copy_(final_states)
168
+ else:
169
+ final_states_out = final_states
170
+ out = (out if activation is None else F.silu(out)).to(dtype=dtype_in)
171
+ return out if not return_final_states else (out, final_states_out)
172
+
173
+
174
+ def causal_conv1d_update(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None, conv_state_indices=None):
175
+ """
176
+ x: (batch, dim) or (batch, dim, seqlen)
177
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
178
+ weight: (dim, width)
179
+ bias: (dim,)
180
+ cache_seqlens: (batch,), dtype int32.
181
+ If not None, the conv_state is treated as a circular buffer.
182
+ The conv_state will be updated by copying x to the conv_state starting at the index
183
+ @cache_seqlens % state_len.
184
+ conv_state_indices: (batch,), dtype int32
185
+ If None, the conv_state is a larger tensor along the batch dim,
186
+ and we are selecting the batch coords specified by conv_state_indices.
187
+ Useful for a continuous batching scenario.
188
+
189
+ out: (batch, dim) or (batch, dim, seqlen)
190
+ """
191
+ if activation not in [None, "silu", "swish"]:
192
+ raise NotImplementedError("activation must be None, silu, or swish")
193
+ activation = activation in ["silu", "swish"]
194
+ unsqueeze = x.dim() == 2
195
+ if unsqueeze:
196
+ x = x.unsqueeze(-1)
197
+ out = causal_conv1d_update_function(
198
+ x, conv_state, weight, bias, activation, cache_seqlens, conv_state_indices
199
+ )
200
+ if unsqueeze:
201
+ out = out.squeeze(-1)
202
+ return out
203
+
204
+
205
+ def causal_conv1d_update_ref(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None):
206
+ """
207
+ x: (batch, dim) or (batch, dim, seqlen)
208
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
209
+ weight: (dim, width)
210
+ bias: (dim,)
211
+ cache_seqlens: (batch,), dtype int32.
212
+ If not None, the conv_state is treated as a circular buffer.
213
+ The conv_state will be updated by copying x to the conv_state starting at the index
214
+ @cache_seqlens % state_len before performing the convolution.
215
+
216
+ out: (batch, dim) or (batch, dim, seqlen)
217
+ """
218
+ if activation not in [None, "silu", "swish"]:
219
+ raise NotImplementedError("activation must be None, silu, or swish")
220
+ dtype_in = x.dtype
221
+ unsqueeze = x.dim() == 2
222
+ if unsqueeze:
223
+ x = x.unsqueeze(-1)
224
+ batch, dim, seqlen = x.shape
225
+ width = weight.shape[1]
226
+ state_len = conv_state.shape[-1]
227
+ assert conv_state.shape == (batch, dim, state_len)
228
+ assert weight.shape == (dim, width)
229
+ if cache_seqlens is None:
230
+ x_new = torch.cat([conv_state, x], dim=-1).to(weight.dtype) # (batch, dim, state_len + seqlen)
231
+ conv_state.copy_(x_new[:, :, -state_len:])
232
+ else:
233
+ width_idx = torch.arange(-(width - 1), 0, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
234
+ width_idx = torch.remainder(width_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
235
+ x_new = torch.cat([conv_state.gather(2, width_idx), x], dim=-1).to(weight.dtype)
236
+ copy_idx = torch.arange(seqlen, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
237
+ copy_idx = torch.remainder(copy_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
238
+ conv_state.scatter_(2, copy_idx, x)
239
+ out = F.conv1d(x_new, weight.unsqueeze(1), bias, padding=0, groups=dim)[:, :, -seqlen:]
240
+ if unsqueeze:
241
+ out = out.squeeze(-1)
242
+ return (out if activation is None else F.silu(out)).to(dtype=dtype_in)
build/torch213-cxx11-cu130-x86_64-linux/causal_conv1d_varlen.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor
3
+
4
+ import triton
5
+ import triton.language as tl
6
+
7
+
8
+ @triton.jit
9
+ def _causal_conv1d_varlen_states(
10
+ X,
11
+ CU_SEQLENS,
12
+ STATES,
13
+ state_len,
14
+ dim,
15
+ stride_x_seqlen, stride_x_dim,
16
+ stride_states_batch, stride_states_seqlen, stride_states_dim,
17
+ BLOCK_M: tl.constexpr,
18
+ BLOCK_N: tl.constexpr
19
+ ):
20
+ batch_idx = tl.program_id(2)
21
+ STATES += batch_idx * stride_states_batch
22
+ end_idx = tl.load(CU_SEQLENS + batch_idx + 1)
23
+ start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len)
24
+ rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
25
+ cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)
26
+ x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] * stride_x_dim,
27
+ mask=(rows[:, None] >= start_idx) & (cols[None, :] < dim),
28
+ other=0)
29
+ rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
30
+ tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[None, :] * stride_states_dim,
31
+ x,
32
+ mask=(rows_states[:, None] >= 0) & (cols[None, :] < dim))
33
+
34
+
35
+ def causal_conv1d_varlen_states(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
36
+ """
37
+ Forward pass only, does not support backward pass.
38
+ Parameters:
39
+ x: (total_tokens, dim)
40
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
41
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
42
+ If some of those elements belong to a different sequence, the value of the states will be zero.
43
+ Return:
44
+ states: (batch, dim, state_len)
45
+ """
46
+ _, dim = x.shape
47
+ batch = cu_seqlens.shape[0] - 1
48
+ cu_seqlens = cu_seqlens.contiguous()
49
+ states = torch.empty(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
50
+ BLOCK_M = min(triton.next_power_of_2(state_len), 16)
51
+ BLOCK_N = min(triton.next_power_of_2(dim), 256)
52
+ grid = (triton.cdiv(dim, BLOCK_N), triton.cdiv(state_len, BLOCK_M), batch)
53
+ with getattr(torch, x.device.type).device(x.device.index):
54
+ _causal_conv1d_varlen_states[grid](
55
+ x,
56
+ cu_seqlens,
57
+ states,
58
+ state_len,
59
+ dim,
60
+ x.stride(0), x.stride(1),
61
+ states.stride(0), states.stride(2), states.stride(1),
62
+ BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N
63
+ )
64
+ return states
65
+
66
+
67
+ def causal_conv1d_varlen_states_ref(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
68
+ """
69
+ Forward pass only, does not support backward pass.
70
+ Parameters:
71
+ x: (total_tokens, dim)
72
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
73
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
74
+ If some of those elements belong to a different sequence, the value of the states will be zero.
75
+ Return:
76
+ states: (batch, dim, state_len)
77
+ """
78
+ _, dim = x.shape
79
+ batch = cu_seqlens.shape[0] - 1
80
+ cu_seqlens = cu_seqlens.contiguous()
81
+ states = torch.zeros(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
82
+ for i in range(batch):
83
+ end_idx = cu_seqlens[i + 1]
84
+ start_idx = torch.maximum(cu_seqlens[i], end_idx - state_len)
85
+ states[i, :, -(end_idx - start_idx):] = x[start_idx:end_idx].T
86
+ return states
build/torch213-cxx11-cu130-x86_64-linux/cpp_functions.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+
5
+ from ._ops import ops
6
+
7
+ def causal_conv1d_fwd_function(
8
+ x: torch.Tensor,
9
+ weight: torch.Tensor,
10
+ bias: torch.Tensor | None,
11
+ seq_idx: torch.Tensor | None,
12
+ initial_states: torch.Tensor | None,
13
+ final_states_out: torch.Tensor | None,
14
+ silu_activation: bool,
15
+ ) -> torch.Tensor:
16
+ out = torch.empty_like(x)
17
+ ops.causal_conv1d_fwd(
18
+ x=x,
19
+ weight=weight,
20
+ bias=bias,
21
+ seq_idx=seq_idx,
22
+ initial_states=initial_states,
23
+ out=out,
24
+ final_states_out=final_states_out,
25
+ silu_activation=silu_activation,
26
+ )
27
+ return out
28
+
29
+
30
+ def causal_conv1d_bwd_function(
31
+ x: torch.Tensor,
32
+ weight: torch.Tensor,
33
+ bias: torch.Tensor | None,
34
+ dout: torch.Tensor,
35
+ seq_idx: torch.Tensor | None,
36
+ initial_states: torch.Tensor | None,
37
+ dfinal_states: torch.Tensor | None,
38
+ dx: torch.Tensor | None,
39
+ return_dinitial_states: torch.Tensor,
40
+ silu_activation: bool,
41
+ ) -> tuple[torch.Tensor | None]:
42
+ batch_size, dim = x.size()[:2]
43
+ width = weight.size(-1)
44
+
45
+ if dx is None:
46
+ dx = torch.empty_like(x)
47
+ dweight = torch.zeros_like(weight, dtype=torch.float32)
48
+ dbias = None
49
+ if bias is not None:
50
+ dbias = torch.zeros_like(bias, dtype=torch.float32)
51
+ dinitial_states = None
52
+ if return_dinitial_states:
53
+ dinitial_states = torch.empty(batch_size, width - 1, dim, device=x.device, dtype=x.dtype).transpose(1, 2)
54
+
55
+ ops.causal_conv1d_bwd(
56
+ x=x,
57
+ weight=weight,
58
+ bias=bias,
59
+ dout=dout,
60
+ seq_idx=seq_idx,
61
+ initial_states=initial_states,
62
+ dfinal_states=dfinal_states,
63
+ dx=dx,
64
+ dweight=dweight,
65
+ dbias=dbias,
66
+ dinitial_states=dinitial_states,
67
+ silu_activation=silu_activation,
68
+ )
69
+
70
+ dweight = dweight.type_as(weight)
71
+ if dbias is not None:
72
+ dbias = dbias.type_as(bias)
73
+ return dx, dweight, dbias, dinitial_states
74
+
75
+
76
+ def causal_conv1d_update_function(
77
+ x: torch.Tensor,
78
+ conv_state: torch.Tensor,
79
+ weight: torch.Tensor,
80
+ bias: torch.Tensor | None,
81
+ silu_activation: bool,
82
+ cache_seqlens: torch.Tensor | None,
83
+ conv_state_indices: torch.Tensor | None,
84
+ ) -> torch.Tensor:
85
+ out = torch.empty_like(x)
86
+ ops.causal_conv1d_update(
87
+ x=x,
88
+ conv_state=conv_state,
89
+ weight=weight,
90
+ bias=bias,
91
+ out=out,
92
+ silu_activation=silu_activation,
93
+ cache_seqlens=cache_seqlens,
94
+ conv_state_indices=conv_state_indices,
95
+ )
96
+ return out
build/torch213-cxx11-cu130-x86_64-linux/layers.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ from .causal_conv1d_interface import causal_conv1d_fn as kernel_causal_conv1d_fn
5
+ from .causal_conv1d_interface import causal_conv1d_update as kernel_causal_conv1d_update
6
+
7
+
8
+ class causal_conv1d_fn(nn.Module):
9
+ def forward(
10
+ self,
11
+ hidden_states: torch.Tensor,
12
+ weight: torch.Tensor,
13
+ bias: torch.Tensor | None = None,
14
+ activation: str | None = None,
15
+ **kwargs,
16
+ ):
17
+ # For varlen
18
+ seq_idx = kwargs.pop("seq_idx", None)
19
+
20
+ return kernel_causal_conv1d_fn(
21
+ x=hidden_states,
22
+ weight=weight,
23
+ bias=bias,
24
+ activation=activation,
25
+ seq_idx=seq_idx,
26
+ )
27
+
28
+
29
+ class causal_conv1d_update(nn.Module):
30
+ def forward(
31
+ self,
32
+ hidden_states: torch.Tensor,
33
+ conv_state: torch.Tensor,
34
+ weight: torch.Tensor,
35
+ bias: torch.Tensor | None = None,
36
+ activation: str | None = None,
37
+ ):
38
+ return kernel_causal_conv1d_update(
39
+ x=hidden_states,
40
+ conv_state=conv_state,
41
+ weight=weight,
42
+ bias=bias,
43
+ activation=activation,
44
+ )
45
+
46
+
47
+ __all__ = [
48
+ "causal_conv1d_fn",
49
+ "causal_conv1d_update",
50
+ ]
build/torch213-cxx11-cu130-x86_64-linux/metadata.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "causal-conv1d",
3
+ "id": "_causal_conv1d_cuda_056e28b",
4
+ "version": 2,
5
+ "license": "BSD-3-Clause",
6
+ "python-depends": [],
7
+ "kernel-depends": [],
8
+ "backend": {
9
+ "type": "cuda",
10
+ "archs": [
11
+ "10.0",
12
+ "10.3",
13
+ "11.0",
14
+ "12.0",
15
+ "12.1+PTX",
16
+ "7.5",
17
+ "8.0",
18
+ "8.6",
19
+ "8.7",
20
+ "8.9",
21
+ "9.0"
22
+ ]
23
+ },
24
+ "digest": {
25
+ "algorithm": "sha256",
26
+ "files": {
27
+ "__init__.py": "ybfee7cD5pV/RtZZSki1skLZM+COZVoqTa+IlL+zY7E=",
28
+ "_causal_conv1d_cuda_056e28b.abi3.so": "TMxmbcHPOMMRTPRqQciTpVFtD8bWi1wUQ1bnbfBf8I4=",
29
+ "_ops.py": "in6wiEQzq3wMOxiS5jap8cHfMQFJoUmFV73UTM6S8S4=",
30
+ "causal_conv1d_interface.py": "Mm0fBbamT4dihp+Z53RzIFM/dn5Y8nLu1vJ4W4W53jQ=",
31
+ "causal_conv1d_varlen.py": "j6tdAEf/x0aBoNx3mEA9qo4xAxmH6fuUUdVnq7tuGgM=",
32
+ "cpp_functions.py": "gUG0/NiMaAmAHLZQ4TnnD5LyKJp9G/BlINOFXXcnlU8=",
33
+ "layers.py": "RH7iOTcjqtn3buFO7fGHfC/Pgu47eaX97ANzfwLD6C8="
34
+ }
35
+ },
36
+ "provenance": {
37
+ "kernel-builder": {
38
+ "version": "0.17.0-dev0",
39
+ "commit": "081dcd473f8eca27226eef1f9c47c45b86c756b5",
40
+ "dirty": false
41
+ },
42
+ "kernel": {
43
+ "commit": "056e28b85220c032b4dc1bb3dadebddd56dc228e",
44
+ "dirty": false
45
+ }
46
+ }
47
+ }
build/torch213-cxx11-cu130-x86_64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json", "verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtCgAwIBAgIUFng7IaiS6DcAEK1EHv1ld6FprIkwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQyMjUxWhcNMjYwOTA0MTQzMjUxWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEAfNwk9j+mov18tY+YJuYa8YNjGFXAj/Yc8dHrll/ZDcB6e0kgdwF3zfe0MYcj76deRrylfU5Af2TUG889jRmBKOC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VG2IxStxI1roTxRKn7vK+LLd63GvB8NL/ExA80zVVQQvOFCuHI7tgL7QTFACz10="}, "tlogEntries":[{"logIndex":"2712276137", "logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="}, "kindVersion":{"kind":"hashedrekord", "version":"0.0.1"}, "integratedTime":"1788531771", "inclusionPromise":{"signedEntryTimestamp":"MEUCIGadSeKmzAGHrjPxl8bvHa6we6oyrEZyQg9bt7TPHvAdAiEAgDnHb3btVNkHWMv9S6mW12K+5xU/mmD/Sm8TbAH1s1w="}, "inclusionProof":{"logIndex":"2590371875", "rootHash":"FD4RtxjaXvqzyhL8fK45M9POAwfrWoPNxZnrcPZzoHI=", "treeSize":"2590372130", "hashes":["+uFFkIpsyGgj6F1kqukEDjyAcqnU+6jOmz4DH/YfXvw=", "4R2actF4DeT013caMxcAIU5myT0vTkQNdKz8kdp8V7k=", "KZAa5Mt5ZNK/ZqE2UhfcILjRCACpIC6wwoXLqd/FcN4=", "mCKuzAGn4Em4TVoP0iLMrQ9UC5oof5FZxrfxdIeYwXI=", "rh2WhSLJ92WU4txzthkYBdIpxYN76cWiL0ng7EACAqs=", "Hns2juWMCyRqiF6cisfU31JLW8b3o3ph2U2ZqDezMbA=", "ER8h92bO0Kq6UpkuLrCoiifQ3SLokTc/N9trlL9RFTg=", "dWUoVFc56lw215SZWOa2tDKeAeerJBqHpb3xWAaaAuE=", "yU27m1URS+cvYLdBse4fR8NrFpYa5oddLjgt+GIbP6o=", "t8nRtM4piqY9M2vLuqc30bnlaHH5a1Mc5+3BX+VcR48=", "dpE4JeS09wbniSRpzbHmp3WEjZfaXFuaxQ/Jz4h8Qdo=", "5BBv7rWK6NFgtdHnmpxaOG4IgQ2e23dxOnb7iVqIJfs=", "CVXlwy6p/0g8OGYc+N5iYlD4qo/oIV4lgJstV8/jX9Y=", "JLnTjrlsTfbD8CvvizQuzVwJPXlC98tLzdnXZ1HqaTI=", "wgA+dB9j8L++Xwb+XT+v0evEwWqMLyd201Sc69PSLzg=", "N+foNlyVQOzU7HZsPPSKIQU/1+E+tmJj33u2r6dwmBs=", "I1FtczpUgFViy1Ae7CAfwglj2nSpp5nZrcsYauARxMs=", "fnPrvt7afEuTlIhaMcrGUdu9+heAmk4jOJ3+Br8/B8M=", "eXSLrLqKSxRTixSP/k4YimriB2lufao6trqTrsxxlyg=", "SndbMKVtcTenAkwi2JBfGzD+mhexp1qJbRIY+A1JRIU=", "xH/DCseLHr9eKoYT8qsORZK7zVdEGYWHuVtsVrD95wY="], "checkpoint":{"envelope":"rekor.sigstore.dev - 1193050959916656506\n2590372130\nFD4RtxjaXvqzyhL8fK45M9POAwfrWoPNxZnrcPZzoHI=\n\n— rekor.sigstore.dev wNI9ajBFAiATHYwVsYNgFh7kY2hKuMlICTcx6ZkaXVpY6cibhYsOvgIhAN1QAO4VXnHZsCKOwhfYnFuJ55el40A6pUa1Fmhlf6X3\n"}}, "canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJkYmUzYWY0NzEyMTM2OWJiMDNmNzIwMDEwOTVkNDI5ZTc0MDljNjVhZTFiNjAwYTJkNGI2MjhhMjZhZWMyMjRlIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUUR0b0o0MXllZFRJL3AwZ2lWM3dJMHRrZXB2NzZtREhGWXJta3oyanFwWEJ3SWhBSVNEclM0UkplSC9Wb25telhkWTRLeUlqMk5sT25Ra0lKc1BkY0JyZnB2SCIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sxSlNVaFRla05EUW5SRFowRjNTVUpCWjBsVlJtNW5OMGxoYVZNMlJHTkJSVXN4UlVoMk1XeGtOa1p3Y2tsc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LXRzYS1zZWxmc2lnbmVkAhQ6E1QvDJBh7rzBQy/Lio6LKiOLDDAKBggqhkjOPQQDAgRmMGQCMG1KfJ7CeRECYJoMm1nwzJxPmFAFP0nH7CNFnWZrtbF29lrVDS7BAmA51yBFPUkm2AIwFm920GCh78DpLL1tqnP/7d8GmD6vGPqtY1d7AvL+zRXjuBlvf9sy9JFALTUwYD+X"}]}}, "messageSignature":{"messageDigest":{"algorithm":"SHA2_256", "digest":"2+OvRxITabsD9yABCV1CnnQJxlrhtgCi1LYoomrsIk4="}, "signature":"MEYCIQDtoJ41yedTI/p0giV3wI0tkepv76mDHFYrmkz2jqpXBwIhAISDrS4RJeH/VonmzXdY4KyIj2NlOnQkIJsPdcBrfpvH"}}
build/torch213-cxx11-cu132-x86_64-linux/__init__.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from . import layers
2
+ from .causal_conv1d_interface import causal_conv1d_fn, causal_conv1d_update
3
+ from .causal_conv1d_varlen import causal_conv1d_varlen_states
4
+
5
+ __all__ = [
6
+ # wrappers
7
+ "layers",
8
+ # originals
9
+ "causal_conv1d_fn",
10
+ "causal_conv1d_update",
11
+ "causal_conv1d_varlen_states",
12
+ ]
build/torch213-cxx11-cu132-x86_64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c960e2218e9c78baad1940fca084f582fe5e1b8efc6aa375adb8cdee64195051
3
+ size 75006024
build/torch213-cxx11-cu132-x86_64-linux/_ops.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from . import _causal_conv1d_cuda_056e28b
3
+ ops = torch.ops._causal_conv1d_cuda_056e28b
4
+
5
+ def add_op_namespace_prefix(op_name: str):
6
+ """
7
+ Prefix op by namespace.
8
+ """
9
+ return f"_causal_conv1d_cuda_056e28b::{op_name}"
build/torch213-cxx11-cu132-x86_64-linux/causal_conv1d_interface.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) 2024, Tri Dao.
2
+
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ from .cpp_functions import causal_conv1d_fwd_function, causal_conv1d_bwd_function, causal_conv1d_update_function
7
+
8
+
9
+ class CausalConv1dFn(torch.autograd.Function):
10
+ @staticmethod
11
+ def forward(
12
+ ctx,
13
+ x,
14
+ weight,
15
+ bias=None,
16
+ seq_idx=None,
17
+ initial_states=None,
18
+ return_final_states=False,
19
+ final_states_out=None,
20
+ activation=None,
21
+ ):
22
+ if activation not in [None, "silu", "swish"]:
23
+ raise NotImplementedError("activation must be None, silu, or swish")
24
+ if x.stride(2) != 1 and x.stride(1) != 1:
25
+ x = x.contiguous()
26
+ bias = bias.contiguous() if bias is not None else None
27
+ if seq_idx is not None:
28
+ assert (
29
+ initial_states is None
30
+ ), "initial_states must be None if seq_idx is not None"
31
+ assert (
32
+ not return_final_states
33
+ ), "If seq_idx is not None, we don't return final_states_out"
34
+ seq_idx = seq_idx.contiguous() if seq_idx is not None else None
35
+ if initial_states is not None and (
36
+ initial_states.stride(2) != 1 and initial_states.stride(1) != 1
37
+ ):
38
+ initial_states = initial_states.contiguous()
39
+ if return_final_states:
40
+ assert (
41
+ x.stride(1) == 1
42
+ ), "Only channel-last layout support returning final_states_out"
43
+ if final_states_out is not None:
44
+ assert (
45
+ final_states_out.stride(2) == 1 or final_states_out.stride(1) == 1
46
+ )
47
+ else:
48
+ batch, dim, seqlen = x.shape
49
+ width = weight.shape[1]
50
+ final_states_out = torch.empty(
51
+ batch, width - 1, dim, device=x.device, dtype=x.dtype
52
+ ).transpose(1, 2)
53
+ else:
54
+ final_states_out = None
55
+ ctx.activation = activation in ["silu", "swish"]
56
+ out = causal_conv1d_fwd_function(
57
+ x, weight, bias, seq_idx, initial_states, final_states_out, ctx.activation
58
+ )
59
+ ctx.save_for_backward(x, weight, bias, seq_idx, initial_states)
60
+ ctx.return_final_states = return_final_states
61
+ ctx.return_dinitial_states = (
62
+ initial_states is not None and initial_states.requires_grad
63
+ )
64
+ return out if not return_final_states else (out, final_states_out)
65
+
66
+ @staticmethod
67
+ def backward(ctx, dout, *args):
68
+ x, weight, bias, seq_idx, initial_states = ctx.saved_tensors
69
+ dfinal_states = args[0] if ctx.return_final_states else None
70
+ if dout.stride(2) != 1 and dout.stride(1) != 1:
71
+ dout = dout.contiguous()
72
+ # The kernel supports passing in a pre-allocated dx (e.g., in case we want to fuse the
73
+ # backward of conv1d with the backward of chunk).
74
+ # Here we just pass in None and dx will be allocated in the C++ code.
75
+ dx, dweight, dbias, dinitial_states = causal_conv1d_bwd_function(
76
+ x,
77
+ weight,
78
+ bias,
79
+ dout,
80
+ seq_idx,
81
+ initial_states,
82
+ dfinal_states,
83
+ None,
84
+ ctx.return_dinitial_states,
85
+ ctx.activation,
86
+ )
87
+ return (
88
+ dx,
89
+ dweight,
90
+ dbias if bias is not None else None,
91
+ None,
92
+ dinitial_states if initial_states is not None else None,
93
+ None,
94
+ None,
95
+ None,
96
+ )
97
+
98
+
99
+ def causal_conv1d_fn(
100
+ x,
101
+ weight,
102
+ bias=None,
103
+ seq_idx=None,
104
+ initial_states=None,
105
+ return_final_states=False,
106
+ final_states_out=None,
107
+ activation=None,
108
+ ):
109
+ """
110
+ x: (batch, dim, seqlen)
111
+ weight: (dim, width)
112
+ bias: (dim,)
113
+ seq_idx: (batch, seqlen)
114
+ initial_states: (batch, dim, width - 1)
115
+ final_states_out: (batch, dim, width - 1), to be written to
116
+ activation: either None or "silu" or "swish"
117
+
118
+ out: (batch, dim, seqlen)
119
+ """
120
+ return CausalConv1dFn.apply(
121
+ x,
122
+ weight,
123
+ bias,
124
+ seq_idx,
125
+ initial_states,
126
+ return_final_states,
127
+ final_states_out,
128
+ activation,
129
+ )
130
+
131
+
132
+ def causal_conv1d_ref(
133
+ x,
134
+ weight,
135
+ bias=None,
136
+ initial_states=None,
137
+ return_final_states=False,
138
+ final_states_out=None,
139
+ activation=None,
140
+ ):
141
+ """
142
+ x: (batch, dim, seqlen)
143
+ weight: (dim, width)
144
+ bias: (dim,)
145
+ initial_states: (batch, dim, width - 1)
146
+ final_states_out: (batch, dim, width - 1)
147
+
148
+ out: (batch, dim, seqlen)
149
+ """
150
+ if activation not in [None, "silu", "swish"]:
151
+ raise NotImplementedError("activation must be None, silu, or swish")
152
+ dtype_in = x.dtype
153
+ x = x.to(weight.dtype)
154
+ seqlen = x.shape[-1]
155
+ dim, width = weight.shape
156
+ if initial_states is None:
157
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=width - 1, groups=dim)
158
+ else:
159
+ x = torch.cat([initial_states, x], dim=-1)
160
+ out = F.conv1d(x, weight.unsqueeze(1), bias, padding=0, groups=dim)
161
+ out = out[..., :seqlen]
162
+ if return_final_states:
163
+ final_states = F.pad(x, (width - 1 - x.shape[-1], 0)).to(
164
+ dtype_in
165
+ ) # (batch, dim, width - 1)
166
+ if final_states_out is not None:
167
+ final_states_out.copy_(final_states)
168
+ else:
169
+ final_states_out = final_states
170
+ out = (out if activation is None else F.silu(out)).to(dtype=dtype_in)
171
+ return out if not return_final_states else (out, final_states_out)
172
+
173
+
174
+ def causal_conv1d_update(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None, conv_state_indices=None):
175
+ """
176
+ x: (batch, dim) or (batch, dim, seqlen)
177
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
178
+ weight: (dim, width)
179
+ bias: (dim,)
180
+ cache_seqlens: (batch,), dtype int32.
181
+ If not None, the conv_state is treated as a circular buffer.
182
+ The conv_state will be updated by copying x to the conv_state starting at the index
183
+ @cache_seqlens % state_len.
184
+ conv_state_indices: (batch,), dtype int32
185
+ If None, the conv_state is a larger tensor along the batch dim,
186
+ and we are selecting the batch coords specified by conv_state_indices.
187
+ Useful for a continuous batching scenario.
188
+
189
+ out: (batch, dim) or (batch, dim, seqlen)
190
+ """
191
+ if activation not in [None, "silu", "swish"]:
192
+ raise NotImplementedError("activation must be None, silu, or swish")
193
+ activation = activation in ["silu", "swish"]
194
+ unsqueeze = x.dim() == 2
195
+ if unsqueeze:
196
+ x = x.unsqueeze(-1)
197
+ out = causal_conv1d_update_function(
198
+ x, conv_state, weight, bias, activation, cache_seqlens, conv_state_indices
199
+ )
200
+ if unsqueeze:
201
+ out = out.squeeze(-1)
202
+ return out
203
+
204
+
205
+ def causal_conv1d_update_ref(x, conv_state, weight, bias=None, activation=None, cache_seqlens=None):
206
+ """
207
+ x: (batch, dim) or (batch, dim, seqlen)
208
+ conv_state: (batch, dim, state_len), where state_len >= width - 1
209
+ weight: (dim, width)
210
+ bias: (dim,)
211
+ cache_seqlens: (batch,), dtype int32.
212
+ If not None, the conv_state is treated as a circular buffer.
213
+ The conv_state will be updated by copying x to the conv_state starting at the index
214
+ @cache_seqlens % state_len before performing the convolution.
215
+
216
+ out: (batch, dim) or (batch, dim, seqlen)
217
+ """
218
+ if activation not in [None, "silu", "swish"]:
219
+ raise NotImplementedError("activation must be None, silu, or swish")
220
+ dtype_in = x.dtype
221
+ unsqueeze = x.dim() == 2
222
+ if unsqueeze:
223
+ x = x.unsqueeze(-1)
224
+ batch, dim, seqlen = x.shape
225
+ width = weight.shape[1]
226
+ state_len = conv_state.shape[-1]
227
+ assert conv_state.shape == (batch, dim, state_len)
228
+ assert weight.shape == (dim, width)
229
+ if cache_seqlens is None:
230
+ x_new = torch.cat([conv_state, x], dim=-1).to(weight.dtype) # (batch, dim, state_len + seqlen)
231
+ conv_state.copy_(x_new[:, :, -state_len:])
232
+ else:
233
+ width_idx = torch.arange(-(width - 1), 0, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
234
+ width_idx = torch.remainder(width_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
235
+ x_new = torch.cat([conv_state.gather(2, width_idx), x], dim=-1).to(weight.dtype)
236
+ copy_idx = torch.arange(seqlen, dtype=torch.long, device=x.device).unsqueeze(0) + cache_seqlens.unsqueeze(1)
237
+ copy_idx = torch.remainder(copy_idx, state_len).unsqueeze(1).expand(-1, dim, -1)
238
+ conv_state.scatter_(2, copy_idx, x)
239
+ out = F.conv1d(x_new, weight.unsqueeze(1), bias, padding=0, groups=dim)[:, :, -seqlen:]
240
+ if unsqueeze:
241
+ out = out.squeeze(-1)
242
+ return (out if activation is None else F.silu(out)).to(dtype=dtype_in)
build/torch213-cxx11-cu132-x86_64-linux/causal_conv1d_varlen.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch import Tensor
3
+
4
+ import triton
5
+ import triton.language as tl
6
+
7
+
8
+ @triton.jit
9
+ def _causal_conv1d_varlen_states(
10
+ X,
11
+ CU_SEQLENS,
12
+ STATES,
13
+ state_len,
14
+ dim,
15
+ stride_x_seqlen, stride_x_dim,
16
+ stride_states_batch, stride_states_seqlen, stride_states_dim,
17
+ BLOCK_M: tl.constexpr,
18
+ BLOCK_N: tl.constexpr
19
+ ):
20
+ batch_idx = tl.program_id(2)
21
+ STATES += batch_idx * stride_states_batch
22
+ end_idx = tl.load(CU_SEQLENS + batch_idx + 1)
23
+ start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len)
24
+ rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
25
+ cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)
26
+ x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] * stride_x_dim,
27
+ mask=(rows[:, None] >= start_idx) & (cols[None, :] < dim),
28
+ other=0)
29
+ rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)
30
+ tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[None, :] * stride_states_dim,
31
+ x,
32
+ mask=(rows_states[:, None] >= 0) & (cols[None, :] < dim))
33
+
34
+
35
+ def causal_conv1d_varlen_states(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
36
+ """
37
+ Forward pass only, does not support backward pass.
38
+ Parameters:
39
+ x: (total_tokens, dim)
40
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
41
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
42
+ If some of those elements belong to a different sequence, the value of the states will be zero.
43
+ Return:
44
+ states: (batch, dim, state_len)
45
+ """
46
+ _, dim = x.shape
47
+ batch = cu_seqlens.shape[0] - 1
48
+ cu_seqlens = cu_seqlens.contiguous()
49
+ states = torch.empty(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
50
+ BLOCK_M = min(triton.next_power_of_2(state_len), 16)
51
+ BLOCK_N = min(triton.next_power_of_2(dim), 256)
52
+ grid = (triton.cdiv(dim, BLOCK_N), triton.cdiv(state_len, BLOCK_M), batch)
53
+ with getattr(torch, x.device.type).device(x.device.index):
54
+ _causal_conv1d_varlen_states[grid](
55
+ x,
56
+ cu_seqlens,
57
+ states,
58
+ state_len,
59
+ dim,
60
+ x.stride(0), x.stride(1),
61
+ states.stride(0), states.stride(2), states.stride(1),
62
+ BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N
63
+ )
64
+ return states
65
+
66
+
67
+ def causal_conv1d_varlen_states_ref(x: Tensor, cu_seqlens: Tensor, state_len: int) -> Tensor:
68
+ """
69
+ Forward pass only, does not support backward pass.
70
+ Parameters:
71
+ x: (total_tokens, dim)
72
+ cu_seqlens: (batch + 1), must already be sorted. The cumulative sum of the sequence lengths, starting from 0.
73
+ state_len: int. For each cu_seqlens, how many elements from x should be copied to the state.
74
+ If some of those elements belong to a different sequence, the value of the states will be zero.
75
+ Return:
76
+ states: (batch, dim, state_len)
77
+ """
78
+ _, dim = x.shape
79
+ batch = cu_seqlens.shape[0] - 1
80
+ cu_seqlens = cu_seqlens.contiguous()
81
+ states = torch.zeros(batch, state_len, dim, dtype=x.dtype, device=x.device).transpose(1, 2)
82
+ for i in range(batch):
83
+ end_idx = cu_seqlens[i + 1]
84
+ start_idx = torch.maximum(cu_seqlens[i], end_idx - state_len)
85
+ states[i, :, -(end_idx - start_idx):] = x[start_idx:end_idx].T
86
+ return states