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

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-aarch64-linux/__init__.py +12 -0
  2. build/torch212-cxx11-cu126-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  3. build/torch212-cxx11-cu126-aarch64-linux/_ops.py +9 -0
  4. build/torch212-cxx11-cu126-aarch64-linux/causal_conv1d_interface.py +242 -0
  5. build/torch212-cxx11-cu126-aarch64-linux/causal_conv1d_varlen.py +86 -0
  6. build/torch212-cxx11-cu126-aarch64-linux/cpp_functions.py +96 -0
  7. build/torch212-cxx11-cu126-aarch64-linux/layers.py +50 -0
  8. build/torch212-cxx11-cu126-aarch64-linux/metadata.json +44 -0
  9. build/torch212-cxx11-cu126-aarch64-linux/metadata.json.sigstore +1 -0
  10. build/torch212-cxx11-cu130-aarch64-linux/__init__.py +12 -0
  11. build/torch212-cxx11-cu130-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  12. build/torch212-cxx11-cu130-aarch64-linux/_ops.py +9 -0
  13. build/torch212-cxx11-cu130-aarch64-linux/causal_conv1d_interface.py +242 -0
  14. build/torch212-cxx11-cu130-aarch64-linux/causal_conv1d_varlen.py +86 -0
  15. build/torch212-cxx11-cu130-aarch64-linux/cpp_functions.py +96 -0
  16. build/torch212-cxx11-cu130-aarch64-linux/layers.py +50 -0
  17. build/torch212-cxx11-cu130-aarch64-linux/metadata.json +47 -0
  18. build/torch212-cxx11-cu130-aarch64-linux/metadata.json.sigstore +1 -0
  19. build/torch212-cxx11-cu132-aarch64-linux/__init__.py +12 -0
  20. build/torch212-cxx11-cu132-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  21. build/torch212-cxx11-cu132-aarch64-linux/_ops.py +9 -0
  22. build/torch212-cxx11-cu132-aarch64-linux/causal_conv1d_interface.py +242 -0
  23. build/torch212-cxx11-cu132-aarch64-linux/causal_conv1d_varlen.py +86 -0
  24. build/torch212-cxx11-cu132-aarch64-linux/cpp_functions.py +96 -0
  25. build/torch212-cxx11-cu132-aarch64-linux/layers.py +50 -0
  26. build/torch212-cxx11-cu132-aarch64-linux/metadata.json +47 -0
  27. build/torch212-cxx11-cu132-aarch64-linux/metadata.json.sigstore +1 -0
  28. build/torch213-cxx11-cu126-aarch64-linux/__init__.py +12 -0
  29. build/torch213-cxx11-cu126-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  30. build/torch213-cxx11-cu126-aarch64-linux/_ops.py +9 -0
  31. build/torch213-cxx11-cu126-aarch64-linux/causal_conv1d_interface.py +242 -0
  32. build/torch213-cxx11-cu126-aarch64-linux/causal_conv1d_varlen.py +86 -0
  33. build/torch213-cxx11-cu126-aarch64-linux/cpp_functions.py +96 -0
  34. build/torch213-cxx11-cu126-aarch64-linux/layers.py +50 -0
  35. build/torch213-cxx11-cu126-aarch64-linux/metadata.json +44 -0
  36. build/torch213-cxx11-cu126-aarch64-linux/metadata.json.sigstore +1 -0
  37. build/torch213-cxx11-cu130-aarch64-linux/__init__.py +12 -0
  38. build/torch213-cxx11-cu130-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  39. build/torch213-cxx11-cu130-aarch64-linux/_ops.py +9 -0
  40. build/torch213-cxx11-cu130-aarch64-linux/causal_conv1d_interface.py +242 -0
  41. build/torch213-cxx11-cu130-aarch64-linux/causal_conv1d_varlen.py +86 -0
  42. build/torch213-cxx11-cu130-aarch64-linux/cpp_functions.py +96 -0
  43. build/torch213-cxx11-cu130-aarch64-linux/layers.py +50 -0
  44. build/torch213-cxx11-cu130-aarch64-linux/metadata.json +47 -0
  45. build/torch213-cxx11-cu130-aarch64-linux/metadata.json.sigstore +1 -0
  46. build/torch213-cxx11-cu132-aarch64-linux/__init__.py +12 -0
  47. build/torch213-cxx11-cu132-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so +3 -0
  48. build/torch213-cxx11-cu132-aarch64-linux/_ops.py +9 -0
  49. build/torch213-cxx11-cu132-aarch64-linux/causal_conv1d_interface.py +242 -0
  50. build/torch213-cxx11-cu132-aarch64-linux/causal_conv1d_varlen.py +86 -0
build/torch212-cxx11-cu126-aarch64-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-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a438e8fbe2a8bf179fccaa5738cbc3d3696d2207b6a2ba5ef161ebcebac50ac
3
+ size 78911952
build/torch212-cxx11-cu126-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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": "ekOOj74qi/F5/Mqlc4y8PTaW0iB7aiul7xYevOusUKw=",
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-aarch64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"m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BgorBgEEAYO/MAEYBDgMNnJlcG86aHVnZ2luZ2ZhY2Uva2VybmVscy1jb21tdW5pdHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBiwYKKwYBBAHWeQIEAgR9BHsAeQB3AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzH+4wAAAQDAEgwRgIhAJBiF3l2I8nvvQcCK4f6tBpX4FF23/D1eZmHFHct9xdEAiEA3LaSWab+5EGu5PwO+MWM7Stop/8i6MIQQSQ0y4AJp4owCgYIKoZIzj0EAwMDaAAwZQIwHndYsbaHT5xa/6dshYwdU/1Ihs+sBls2I+FRxbhSXcxt/f53eIjQVEfb7GjHm8grAjEAtY8Rp9JXzgvaoH/H430fhqQf9fLL1avxebvvDEtKtE5oyEJT0L1Ro8AOxzVVEarC"},"tlogEntries":[{"logIndex":"2712206770","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1788531441","inclusionPromise":{"signedEntryTimestamp":"MEQCH3OrB5T9uqPjwrYaBorlK+d5/j96QiFXEsjIE0gP7zMCIQClO0Oh1UiYb5EO/kmpT7CZL1TjchF9hUY5VFBpimsV7Q=="},"inclusionProof":{"logIndex":"2590302508","rootHash":"dNSC2zhHBEloks7ZHoUnRaofBpbG28rCK7d4aT3A7c8=","treeSize":"2590302688","hashes":["I+CVSQOtmuKccwgZuKBONdCVEcailVdxVUnrrZ6IhWw=","VQzWAftcU6GhyrLQVMfvC7buOtTZWvl5gtpGEA+qEBE=","byh0tau9mN9C3+5s/mFds8SAh8dHpOhCXvthk/GLpVU=","VMkr1GEdvxuJrZxzPuuHj0VvDQCoH8ieLdGa/jbmDpA=","e6q38MDDetc1Kd/w6bGjtjSum4Hf8ejgX+Ep+byFFnc=","yUi4MwNjCxY8uQzo394W4vlfU+5//Bu7Q60vPlk5Dpg=","3xXk9Q8vetv0MSH2nLmACbznUDXHsaTz87tfHkjKQ80=","jp48I9+TwWbqE0BGWvyF+u5dAWLebmpOi+fltZI9hC0=","4kbZ3uoeMKtWhuQVYghcVMlVvFdvSwqMkTnkZfzyo3E=","r+69k0fOjzxcXnOwIlD352Kuyjs22Maer1/AFrceTYo=","ohrY7Q07dQsFxHshSCrWurSq9MSwWE8Ea+QdavE4zrM=","8Ne5O/slxyxV3WMOHVD3Kjoe/OUxlahj83eaPxftJ6U=","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\n2590302688\ndNSC2zhHBEloks7ZHoUnRaofBpbG28rCK7d4aT3A7c8=\n\n— rekor.sigstore.dev wNI9ajBEAiACBnn4LHo7HzddvTKk09GvBfTpDKGF9yBCjia0TqxDcgIgT/VMFFL6VUtuiuMEh/z/u6DOnVg1d7jIM5ecfUh/azs=\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiIzYTY4ZDMxMjRlMmUwNmVkNTI2Nzc4NTRhOGEyZTUxMTI0YTE3MmU0YjMwYjdhOWQzYjFiNDU5ZDg2MWFkZjlmIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FVUNJUUNUa2FGVFlGdW0rWE4wUlZ3aWwrNlFa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CQUxDxcNMjYwOTA0MTQxNzIwWjAvBgkqhkiG9w0BCQQxIgQgg0/opwKjAfUOl2e9kAymhhauZlwyMvIzg2V9/95nzN4wgY4GCyqGSIb3DQEJEAIvMX8wfTB7MHkEIIX5J7wHq2LKw7RDVsEO/IGyxog/2nq55thw2dE6zQW3MFUwPaQ7MDkxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEgMB4GA1UEAxMXc2lnc3RvcmUtdHNhLXNlbGZzaWduZWQCFDoTVC8MkGHuvMFDL8uKjosqI4sMMAoGCCqGSM49BAMCBGcwZQIxAJ1bj0YMMqMFT1/U5jUVYAjRUXQp4baUDq9of2++1A26fBqgv/JNDVVVGq/j04Ce+gIwc5sTU92/EL9WbtUnj0L70336Ta2N+ims/0JR3/ig7/4NxWT/qHV+8nbeBYhx7p+F"}]}},"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"OmjTEk4uBu1SZ3hUqKLlESShcuSzC3qdOxtFnYYa358="},"signature":"MEUCIQCTkaFTYFum+XN0RVwil+6QZ9ou7ILaSzwE3MQh+e9/ZAIgdsVReNR3Qc3QJJYIfUfTQlvg11COslbswjyEu2N0TNI="}}
build/torch212-cxx11-cu130-aarch64-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-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49e5ababd9692f41e928027eecd1897d156a16187fc778e2b10a3036468157ad
3
+ size 74934456
build/torch212-cxx11-cu130-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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": "SeWrq9lpL0HpKAJ+7NGJfRVqFhh/x3jisQowNkaBV60=",
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-aarch64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtGgAwIBAgIUGgkpT387TNaEbCPHkP6ocsdul34wCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQxNzIyWhcNMjYwOTA0MTQyNzIyWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEMAdRZcjHgOQqmTbGZ+tjINm7sA1s+DFeXMbxW82mPc4627QjXc9uQGfF+9JRYAkQc6sbA4Zje61kcwG3Pr3/3KOCBfAwggXsMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUZDx33npEdmZAaFcd5ZCidnw/EeIwHwYDVR0jBBgwFoAU39Ppz1YkEZb5qNjpKFWixi4YZD8wawYDVR0RAQH/BGEwX4ZdaHR0cHM6Ly9naXRodW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czovL2dpdGh1Yi5jb20vaHVnZ2luZ2ZhY2UwGAYKKwYBBAGDvzABEQQKDAgyNTcyMDc0MzBtBgorBgEEAYO/MAESBF8MXWh0dHBzOi8vZ2l0aHViLmNvbS9odWdnaW5nZmFjZS9rZXJuZWxzLWNvbW11bml0eS8uZ2l0aHViL3dvcmtmbG93cy9idWlsZC55YW1sQHJlZnMvaGVhZHMvbWFpbjA4BgorBgEEAYO/MAETBCoMKDA1NmUyOGI4NTIyMGMwMzJiNGRjMWJiM2RhZGViZGRkNTZkYzIyOGUwIQYKKwYBBAGDvzABFAQTDBF3b3JrZmxvd19kaXNwYXRjaDBkBgorBgEEAYO/MAEVBFYMVGh0dHBzOi8vZ2l0aHViLmNvbS9odWdnaW5nZmFjZS9rZXJuZWxzLWNvbW11bml0eS9hY3Rpb25zL3J1bnMvMzM4ODA5ODMwMzcvYXR0ZW1wdHMvMTAWBgorBgEEAYO/MAEWBAgMBnB1YmxpYzBGBgorBgEEAYO/MAEYBDgMNnJlcG86aHVnZ2luZ2ZhY2Uva2VybmVscy1jb21tdW5pdHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBigYKKwYBBAHWeQIEAgR8BHoAeAB2AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzIA/UAAAQDAEcwRQIgbr7ru/sijDi3JUZ/IIEam3imrzH+QlBTB2gPwP/Vd7ECIQCx7w28xnOMWUYqTglUdeMSZ5JxOeSdatmS87C1CrdJFjAKBggqhkjOPQQDAwNoADBlAjEAh7KL+RTp5AE7xVcWZKItFuHr9H330drX6bUC22dYWGVAOOcB13KFgVwWn2rJdbHGAjBpwB4cHrZYg9j8bITJf5SrvkUz8PpZqtKLYeoaMqZvOI9TG3Iot22s33/jMpofGes="},"tlogEntries":[{"logIndex":"2712207293","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1788531443","inclusionPromise":{"signedEntryTimestamp":"MEYCIQCvLZ9HNSrcl+79asYzS48IqyLTXO2tTg04KG8EgnKB+wIhANhz+A9zhnqNiKRwl8zEGy31IqSp2vf9++To3/t/Ibz9"},"inclusionProof":{"logIndex":"2590303031","rootHash":"WfmdI6CxfC8d543stVXCU4To3gKfMtJjE+BNFbx9qUU=","treeSize":"2590303500","hashes":["2cxFvrGkhX5zREL0kn26ODNvYj3IZZCPT9G9aD+suW0=","rGZ5EUOASjIshNK5g6sFQmwujYe9PYUNx+Cd21hkTug=","s4ewz/bVA19TPG2PTUvVv8XyyOw6vNXC+PyorYetMLg=","eYH/hy0lG0mYPgsh7OYY628MVLQpLqKczI+qui51vTo=","54dKAMqxTV45UZREE3X5VZZ5ok9xmSBwzO+bmXZLGU0=","Gfrrd3wiiL/m2p6MgXLWcGz/0aMRwannidIRFan6Zb8=","pNtypuTy5shS+Q/WhqCkH06v+2jNOm6odfO3NTTNJpc=","2EzrN0aKNSZB0v52y2meIimGsze5uJI/RSnLUqHJC3A=","7me4LqbSAx/c0mXz4Zw8nO8yEjDLlw2g5gWRc3fY3Cs=","g6+15tz0IvMIiVVN/ZXRO4KFNFolmaE27hj4XhxyJ1s=","LiITXVFFflQQ5udIm3jdVx/NCeh6sQJK9NkWd+1RTKY=","r+69k0fOjzxcXnOwIlD352Kuyjs22Maer1/AFrceTYo=","ohrY7Q07dQsFxHshSCrWurSq9MSwWE8Ea+QdavE4zrM=","8Ne5O/slxyxV3WMOHVD3Kjoe/OUxlahj83eaPxftJ6U=","wgA+dB9j8L++Xwb+XT+v0evEwWqMLyd201Sc69PSLzg=","N+foNlyVQOzU7HZsPPSKIQU/1+E+tmJj33u2r6dwmBs=","I1FtczpUgFViy1Ae7CAfwglj2nSpp5nZrcsYauARxMs=","fnPrvt7afEuTlIhaMcrGUdu9+heAmk4jOJ3+Br8/B8M=","eXSLrLqKSxRTixSP/k4YimriB2lufao6trqTrsxxlyg=","SndbMKVtcTenAkwi2JBf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":{"algorithm":"SHA2_256","digest":"fthshA+8FN7aG5rcO1bcQ/8xr6MdhaL+GtvcDBwKElI="},"signature":"MEYCIQDkPfunoLlL2dU0Y73ugXLQLysDr+MO0yl4dz/hcgCOTAIhAJ2l7fiPg/HMpNWdhXE+rslYUeb17Gn7RF1ridyj+1KE"}}
build/torch212-cxx11-cu132-aarch64-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-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:012229d08b1266fcd8a9ed38c7a50661a1ced324a906df2d7959639c54623aa1
3
+ size 75002488
build/torch212-cxx11-cu132-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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": "ASIp0IsSZvzYqe04x6UGYaHO0ySpBt8teVljnFRiOqE=",
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-aarch64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtKgAwIBAgIUE11Yy+ls4GvbxTdWZpelUx3pOsUwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQxNzI1WhcNMjYwOTA0MTQyNzI1WjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEos1zKlalJf+qWXNxwCCQ3l3hISTLzv9z2JnijhSrBDK0112VKo9LzW9zCfJ5sBRVNXAwGSyYn4IuBTXSkIPc/KOCBfEwggXtMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQU3uUqPVaWx4VhKgMmEFla7c/6Le4wHwYDVR0jBBgwFoAU39Ppz1YkEZb5qNjpKFWixi4YZD8wawYDVR0RAQH/BGEwX4ZdaHR0cHM6Ly9naXRodWIuY29tL2h1Z2dpbmdmYWNlL2tlcm5lbHMtY29tbXVuaXR5Ly5naXRodWIvd29ya2Zsb3dzL2J1aWxkLnlhbWxAcmVmcy9oZWFkcy9tYWluMDkGCisGAQQBg78wAQEEK2h0dHBzOi8vdG9rZW4uYWN0aW9ucy5naXRodWJ1c2VyY29udGVudC5jb20wHwYKKwYBBAGDvzABAgQRd29ya2Zsb3dfZGlzcGF0Y2gwNgYKKwYBBAGDvzABAwQoMDU2ZTI4Yjg1MjIwYzAzMmI0ZGMxYmIzZGFkZWJkZGQ1NmRjMjI4ZTATBgorBgEEAYO/MAEEBAVCdWlsZDArBgorBgEEAYO/MAEFBB1odWdnaW5nZmFjZS9rZXJuZWxzLWNvbW11bml0eTAdBgorBgEEAYO/MAEGBA9yZWZzL2hlYWRzL21haW4wOwYKKwYBBAGDvzABC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ODA5ODMwMzcvYXR0ZW1wdHMvMTAWBgorBgEEAYO/MAEWBAgMBnB1YmxpYzBGBgorBgEEAYO/MAEYBDgMNnJlcG86aHVnZ2luZ2ZhY2Uva2VybmVscy1jb21tdW5pdHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBiwYKKwYBBAHWeQIEAgR9BHsAeQB3AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzIDycAAAQDAEgwRgIhAP8vqZGkNaGnRIlGm001aFQakZnqCkLWvXcKa3mUvT0VAiEAzpDz+kFK/O6JbiClUdJ/7R9xZUBNSro0/S3+9i7kbJAwCgYIKoZIzj0EAwMDZwAwZAIwFg3piE1u7sseou8AYoSX0lyNwjqG2tVvZ3ORoesJiGuIphZs0HtRJH6VoHzAd3mtAjBRp8ouHhP5TJbwowE102cxAIREBcLdXm3KxSHW6qSByNUkDaJZjSF5Hzj7BSh0H5s="},"tlogEntries":[{"logIndex":"2712207943","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1788531445","inclusionPromise":{"signedEntryTimestamp":"MEUCIGjRq6DLUFLe7ri4ykDwm/iyiNKHTVkG2LWuzZ9+pfRLAiEArbtiQYSuPAxNnbcE0SJ7LUvaqQ2+dWajZhl7ZJcCbOQ="},"inclusionProof":{"logIndex":"2590303681","rootHash":"42aTA6sdGh1OHznEAybnbgyDXBJTcMqRB18u9vTyrs8=","treeSize":"2590304182","hashes":["E94iD6zRcB7SEYeWwIB7KeTmpU2PxVFRyDH1b95Eht0=","si0hTWeBvTS7sNBwBYeJaN09D50AAz2Z18GvzP0pIPE=","Jh0boxaEq8QqEw1W9BWsjgUe5ix/wLPJtD9coWAoG4g=","4Ffg7NpSwd2Xz/3X2+xifKmZYOsaObTFXuHtvmmuBdw=","q8cRbDXdKTGaMQub+k/AQ4QaNQqELpaWAlS/yX6ovqo=","3UB/k0PDCeTfEybl9iefMnlb8qiXTKYnhj7PoCyD53M=","IHmh9RWSp3jsMdeBPMl+gJnZiTFoCRxnshs6S6ZywHE=","4n0Eo6WnyJCDEqFpK46WRQE1wQKg/3AjcYsnwZQYip0=","MpPwp638fmb2Q2ZLj6zGkCJwTVI7pLz000sbmluXGg4=","T9gvtU8aznESDhqcF7J3TmgYgwpxETlztDF8ytqtcU0=","lEwXj6GVlLVdEynO9nlxd0jbX2m6mEtQjOdrv/C8Gxs=","r+69k0fOjzxcXnOwIlD352Kuyjs22Maer1/AFrceTYo=","ohrY7Q07dQsFxHshSCrWurSq9MSwWE8Ea+QdavE4zrM=","8Ne5O/slxyxV3WMOHVD3Kjoe/OUxlahj83eaPxftJ6U=","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\n2590304182\n42aTA6sdGh1OHznEAybnbgyDXBJTcMqRB18u9vTyrs8=\n\n— rekor.sigstore.dev wNI9ajBFAiEAo63FaOTQOMQ/zR2FYz32qOMiJq+S9of2/BekRwENsOUCIE/wlmEyCJIaRGBm1Z/UrFJX+FI3id/PMxC6wiSni4e+\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJmOWFiYTBlODc5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uZGV2MSAwHgYDVQQDExdzaWdzdG9yZS10c2Etc2VsZnNpZ25lZAIUOhNULwyQYe68wUMvy4qOiyojiwwwCwYJYIZIAWUDBAIBoIH8MBoGCSqGSIb3DQEJAzENBgsqhkiG9w0BCRABBDAcBgkqhkiG9w0BCQUxDxcNMjYwOTA0MTQxNzI1WjAvBgkqhkiG9w0BCQQxIgQgG5PJSk9HUtrVpi73syVGSJmMLFJiXL0LhrATICpADgswgY4GCyqGSIb3DQEJEAIvMX8wfTB7MHkEIIX5J7wHq2LKw7RDVsEO/IGyxog/2nq55thw2dE6zQW3MFUwPaQ7MDkxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEgMB4GA1UEAxMXc2lnc3RvcmUtdHNhLXNlbGZzaWduZWQCFDoTVC8MkGHuvMFDL8uKjosqI4sMMAoGCCqGSM49BAMCBGcwZQIwYsUcdGXlsofK5VZOw7Jq46InIO9qERSh5WD6pg2qQ/jrLODT67Ye74g/RRGiCiZUAjEA7gHiUtNalSQKyuOuBxUJwvh9LFxzljf5ESiI3QU6fxr50zoZcaQrwF3puHDsK1ZJ"}]}},"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"+aug6HlYyoFJ9HZEj0f01R+oeiHfb2G3cuXSdizQoZI="},"signature":"MEQCIGoq7yOsPx59NKYUu6feJDzgBpGC2A6ckr7wZ8zHWv1wAiA+v5SRYAkuC+03JPVnm1YjdaF/7wmIgJKuoJJmlnXIlg=="}}
build/torch213-cxx11-cu126-aarch64-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-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e166fbb8d695ba179fe3d197a4daf5da55e8d8ae398a28340d28cb80ddb29a2e
3
+ size 78911912
build/torch213-cxx11-cu126-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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": "4Wb7uNaVuhef49GXpNr12lXo2K45iig0DSjLgN2ymi4=",
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-aarch64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtGgAwIBAgIUYpMV7O/BP0Z4rM86oJuHThhtOPMwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQxNzI5WhcNMjYwOTA0MTQyNzI5WjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtd8DSwDgT/q1uAOyFNq6HbWgETeCAMKSgs7V5jGiTJevEV6Bxxx2wMqbTvN/K4OLQqTHUEHCApj3lToKireaPKOCBfAwggXsMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAd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KHE3PRyeI="},"tlogEntries":[{"logIndex":"2712209126","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1788531451","inclusionPromise":{"signedEntryTimestamp":"MEYCIQD5DJ5liR1Q9OmFxwOzEUFrHuIk8+eEuJb6LMKjBuOuOQIhAOfPGdxOw+gz5hDOQLGFKkVLFBIb/FX02WeQDeDIaFZV"},"inclusionProof":{"logIndex":"2590304864","rootHash":"E7HGGeT4aeWLU2Te7Fx/tfzmYi/JL8QhfUV3ApKxBok=","treeSize":"2590304907","hashes":["BwPMMPYyLAYc4+tnv+WCUxHP7hHfp36cb2UHdIlMzjA=","M/Aghb36880tBfbaisSSzrwyZMx1IzFBdZ7UvYHCH8k=","lWznuXEYmQ/+6JuR5wZRtZYsJK28bCrp8yYpFdnPohg=","HL9+kMb843VTY9B8hAb7tTUydDzY1KordoGlv4hBIcA=","LXdgt0UINWyxd0GGPNBKAsyAp+NVZzS1FREAdREMrKA=","e2hyvQrpy7PFMLCqN+D9OGTG686qdnFaCJR68lgm2Ok=","CDT0BN7tUbNcQSKcpfgpqgDNdKTyZvrsdrxg5N008Ls=","Tw7XDM9uiRXrf2kJFUdcOr1cEvTDrUL/YxEzflG6/d8=","HeOLbwKuDOT5caHN88H+iFCJfQDVT2lRnVzhrysbU9s=","Ynsf1tbb9300W+zDms6HJywTVRd4XY1FxuqzcgA2qmc=","r+69k0fOjzxcXnOwIlD352Kuyjs22Maer1/AFrceTYo=","ohrY7Q07dQsFxHshSCrWurSq9MSwWE8Ea+QdavE4zrM=","8Ne5O/slxyxV3WMOHVD3Kjoe/OUxlahj83eaPxftJ6U=","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\n2590304907\nE7HGGeT4aeWLU2Te7Fx/tfzmYi/JL8QhfUV3ApKxBok=\n\n— rekor.sigstore.dev wNI9ajBGAiEAo54YYv519wo4gdz19zduwQUpjO7FDlYrKcp+DZE7aNYCIQD6f6XGdRUx2gmSr6SKhmAV/69mMAjxMT4eH9flx8TPHA==\n"}},"canonicalizedBody":"eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaGFzaGVkcmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiI3NDJmZDBjOTUyNTFjODNmZTNkODhjMTZhOTNiZTE5YTBmMGY2YjIzOGVkNDBlNDc1ODdhNGFkZDAzM2E5ZTczIn19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FVUNJRzJpU1pPWUFZeHJhWng2SnByNXdBNU14Q2tCdzZzcm5YeC9ybUpMQ2wrMkFpRUFuUHF3YVd5RFd1NnZuSTZTZi9RaWVnY1l4eERpYlVPYmMwOFVYeWd6SmxnPSIsInB1YmxpY0tleSI6eyJjb250ZW50IjoiTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sxSlNVaFRla05EUW5SSFowRjNTVUpCWjBsVldYQk5WamRQTDBKUU1GbzBjazA0Tm05S2RVaFVhR2gwVDFCTmQwTm5XVWxMYjFwSmVtb3dSVUYzVFhjS1RucEZWazFDVFVkQk1WVkZRMmhOVFdNeWJHNWpNMUoyWTIxVmRWcEhWakpOVWpSM1NFRlpSRlpSVVVSRmVGWjZZVmRrZW1S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VvdluktsA9iyAtreVgdieMtgj9V2LMtOMe2iaApgijicJNCG9vUX3oaPWTsuMP//"}]}},"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"dC/QyVJRyD/j2IwWqTvhmg8PayOO1A5HWHpK3QM6nnM="},"signature":"MEUCIG2iSZOYAYxraZx6Jpr5wA5MxCkBw6srnXx/rmJLCl+2AiEAnPqwaWyDWu6vnI6Sf/QiegcYxxDibUObc08UXygzJlg="}}
build/torch213-cxx11-cu130-aarch64-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-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce373b8049bc86d3309df58ee8d6d23f5a79bf991a8150ff66dffa1c2b40a995
3
+ size 74934224
build/torch213-cxx11-cu130-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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-aarch64-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": "zjc7gEm8htMwnfWO6NbSP1p5v5kagVD/Zt/6HCtAqZU=",
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-aarch64-linux/metadata.json.sigstore ADDED
@@ -0,0 +1 @@
 
 
1
+ {"mediaType":"application/vnd.dev.sigstore.bundle.v0.3+json","verificationMaterial":{"certificate":{"rawBytes":"MIIHSzCCBtGgAwIBAgIUQp4elL/n1oL9cROBz/D/atQYC5gwCgYIKoZIzj0EAwMwNzEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MR4wHAYDVQQDExVzaWdzdG9yZS1pbnRlcm1lZGlhdGUwHhcNMjYwOTA0MTQxNzMyWhcNMjYwOTA0MTQyNzMyWjAAMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEIt2cmRhMqz64ycaO4h3gILa+Z+0dPT7KJ8qyT4lSOuVYBLeQBMqEBOPsgZMSmiAr6Hs3+YtfTmFNJm7pjHzA2qOCBfAwggXsMA4GA1UdDwEB/wQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAzAdBgNVHQ4EFgQUMA35A7DcJXHm6RVbr1ko7Epg6OwwHwYDVR0jBBgwFoAU39Ppz1YkEZb5qNjpKFWixi4YZD8wawYDVR0RAQH/BGEwX4ZdaHR0cHM6Ly9naXRodWIuY29tL2h1Z2dpbmdmYWNlL2tlcm5lbHMtY29tbXVuaXR5Ly5naXRodWIvd29ya2Zsb3dzL2J1aWxkLnlhbWxAcmVmcy9oZWFkcy9tYWluMDkGCisGAQQBg78wAQEEK2h0dHBzOi8vdG9rZW4uYWN0aW9ucy5naXRodWJ1c2VyY29udGVudC5jb20wHwYKKwYBBAGDvzABAgQRd29ya2Zsb3dfZGlzcGF0Y2gwNgYKKwYBBAGDvzABAwQoMDU2ZTI4Yjg1MjIwYzAzMmI0ZGMxYmIzZGFkZWJkZGQ1NmRjMjI4ZTATBgorBgEEAYO/MAEEBAVCdWlsZDArBgorBgEEAYO/MAEFBB1odWdnaW5nZ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0dHBzOi8vZ2l0aHViLmNvbS9odWdnaW5nZmFjZS9rZXJuZWxzLWNvbW11bml0eS9hY3Rpb25zL3J1bnMvMzM4ODA5ODMwMzcvYXR0ZW1wdHMvMTAWBgorBgEEAYO/MAEWBAgMBnB1YmxpYzBGBgorBgEEAYO/MAEYBDgMNnJlcG86aHVnZ2luZ2ZhY2Uva2VybmVscy1jb21tdW5pdHk6cmVmOnJlZnMvaGVhZHMvbWFpbjCBigYKKwYBBAHWeQIEAgR8BHoAeAB2AN09MGrGxxEyYxkeHJlnNwKiSl643jyt/4eKcoAvKe6OAAABoGzIK+IAAAQDAEcwRQIhAPnwZ7W6CHe9gMb7EHaEafC1MRm35jE2ebGxgeryowEdAiASdtlxKs/62fOcKh/WQHMm892vQPhFiwJu/lS8iW7pDzAKBggqhkjOPQQDAwNoADBlAjBlvRXFE3MPsi3TSbA5wB/lfOOkk8Qk2o/7EyOPNe3axj7m9NlA7W9KtN2bgvK3tUYCMQCnFrOSocucrPWmtCRT/H4xYBPY3ztTuzGaWHfL8uff8iUB1tzY5ZBQLjktRRdhWvg="},"tlogEntries":[{"logIndex":"2712210243","logId":{"keyId":"wNI9atQGlz+VWfO6LRygH4QUfY/8W4RFwiT5i5WRgB0="},"kindVersion":{"kind":"hashedrekord","version":"0.0.1"},"integratedTime":"1788531455","inclusionPromise":{"signedEntryTimestamp":"MEQCIFgfugGpPezwpsrim07ywoV77dwDmNz4fHNLCYJDpetsAiBt9aLPpLTMU1mM9fyFUs2IwtStmoDxttzOX/11NyR2BQ=="},"inclusionProof":{"logIndex":"2590305981","rootHash":"QeH0Hu+gnSc1orhRbA0NGre4Rm4M3Bf7fTkIhSl8fI0=","treeSize":"2590306306","hashes":["e5RgmPDCGyvO57/4WjmpeaIKb0pbQGesMhNpXOO86Pc=","x1O8W/5AKzBdHTOfn4YgIKmTTtPfK8B91XQqR2sMmlI=","Mpt7/AVW+v3CQrGmyiYW1TFlrDU1Z3KjQK9cAFJqXrg=","fRD5/zktUsVofDngcLl7zW3vU5bNFc+xpfOWHrAKUn8=","VBvVHSqOLtgAuNiiXMCdVRlgVXzCwSBYyyXdWWrqmRI=","V+shyTkOAnhceHAvgUbLxUBoMa+0GxC8O2bHOexuB84=","5DaZWMbs2p7ZWGB6ZwVwl3i9kOYGQKmysee/WlwPGTE=","A4F7dKS2cP53btGWtIH8Tv+xrHtsletofyEtPzcF/k8=","7DoQ3ggxKtzBEfzB/Q7Bl2k8hZGsOZkunhG1uLobSpE=","46f6poNmQe6XU7iE73fENBdfxybdQIWnxw5JZFpmHVM=","rh0X0kaj+rt1oOdlpoMW2u3Ef9e5khn4K2m4JvfYyJQ=","Ynsf1tbb9300W+zDms6HJywTVRd4XY1FxuqzcgA2qmc=","JxEJ83kMMSvspIYj2SF9rag7dIVF24Xvxk5o3+DY7GU=","r+69k0fOjzxcXnOwIlD352Kuyjs22Maer1/AFrceTYo=","ohrY7Q07dQsFxHshSCrWurSq9MSwWE8Ea+QdavE4zrM=","8Ne5O/slxyxV3WMOHVD3Kjoe/OUxlahj83eaPxftJ6U=","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\n2590306306\nQeH0Hu+gnSc1orhRbA0NGre4Rm4M3Bf7fTkIhSl8fI0=\n\n— rekor.sigstore.dev wNI9ajBGAiEAimD4WAU/GpvSAAPC9iM5XKmV9CiZS5yAfb2ZUjkbqqMCIQD0ukzvz8aTadS1Tw9zaA9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1jZo/8PeihjGd76l5J0CFFNJK+lnlqiZyqCUA/j0L2UC8XxSGA8yMDI2MDkwNDE0MTczMlowAwIBAaAypDAwLjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MRUwEwYDVQQDEwxzaWdzdG9yZS10c2GgADGCAdowggHWAgEBMFEwOTEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MSAwHgYDVQQDExdzaWdzdG9yZS10c2Etc2VsZnNpZ25lZAIUOhNULwyQYe68wUMvy4qOiyojiwwwCwYJYIZIAWUDBAIBoIH8MBoGCSqGSIb3DQEJAzENBgsqhkiG9w0BCRABBDAcBgkqhkiG9w0BCQUxDxcNMjYwOTA0MTQxNzMyWjAvBgkqhkiG9w0BCQQxIgQgTdiZ35nRdKUuhlSdVYAOgR63LDH4jJpLUJX+ise4hv4wgY4GCyqGSIb3DQEJEAIvMX8wfTB7MHkEIIX5J7wHq2LKw7RDVsEO/IGyxog/2nq55thw2dE6zQW3MFUwPaQ7MDkxFTATBgNVBAoTDHNpZ3N0b3JlLmRldjEgMB4GA1UEAxMXc2lnc3RvcmUtdHNhLXNlbGZzaWduZWQCFDoTVC8MkGHuvMFDL8uKjosqI4sMMAoGCCqGSM49BAMCBGYwZAIwBlBJKtiIuN7rOlMqRdZLJp0fM+ajElPMZEM0L4TiT15Rb+2nCe1t9AlcskI+Rn9YAjAoRWKLrISIZK58MXcqJj0TcxfSWYwz+abJmQnoeml8t+VhU6KS4WuUbl8bxFMogKI="}]}},"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"fywSaoEwNOSLOdpVxelZXjLmWpenRIT6jehMnWW+wb0="},"signature":"MEYCIQD+723PbI3A9JMLgd5yyxLRlfRUJ4p5rkEFM+HmUK9zVgIhAJp7J7nhKV7/Mx9H6NLJUzi/6zsyAS55T4O3l8n3Odgg"}}
build/torch213-cxx11-cu132-aarch64-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-aarch64-linux/_causal_conv1d_cuda_056e28b.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:79bcf114bcc754bc73b331505be2a3655b2e8348bfbef3b5883ac06719b9de83
3
+ size 75002256
build/torch213-cxx11-cu132-aarch64-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-aarch64-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-aarch64-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