CausalConvWithState#
Domain:
ai.onnxSince version: 29
Stateful causal one-dimensional depthwise convolution.
input has shape (B, C, L), weight has shape (C, 1, K), and optional
bias has shape (C): B is batch size, C is channel count, L is input
length, and K is kernel size. Let d = dilation (default 1) and
H = (K - 1) * d. Both K and d must be at least 1, and the effective
kernel size H + 1 must fit in a signed 64-bit integer.
Both state tensors have shape (B, C, H) and store consecutive raw samples
in chronological order. Form P by concatenating past_state and input
along axis 2; use a zero tensor of shape (B, C, H) when past_state is absent.
For each batch b, channel c, and position 0 <= t < L, compute
z[b,c,t] = sum_{j=0}^{K-1} weight[c,0,j] * P[b,c,t+j*d] + bias[c],
with omitted bias treated as zero. The output has shape (B, C, L) and equals
z for activation ‘none’ (the default), or z / (1 + exp(-z)) elementwise
for ‘silu’ and its alias ‘swish’.
The next state is present_state = P[:, :, L:L+H], independent of activation.
When L < H, it retains the required past samples or initial zeros.
Passing this state to the next call preserves convolution across chunk boundaries.
For K = 1, state has shape (B, C, 0). For L = 0, output has shape
(B, C, 0) and state is unchanged (all zeros if past_state is absent).
Inputs
input (T): Input tensor with shape (batch_size, channels, length). Channels-first layout.
weight (T): Depthwise convolution kernel with shape (channels, 1, k), where k must be >= 1. Each channel is convolved independently with its corresponding kernel.
bias (T): Optional per-channel bias with shape (channels).
past_state (T): Raw chronological history with shape (batch_size, channels, (k - 1) * dilation). If not provided, history is zero.
Outputs
output (T): Convolution output with same shape as input.
present_state (T): The last (k - 1) * dilation raw samples of the concatenated history and input, with shape (batch_size, channels, (k - 1) * dilation).
Attributes
activation (string): Fused activation function. One of: ‘silu’, ‘swish’, ‘none’. Default is ‘none’.
dilation (int): Spacing between kernel samples. Must be >= 1.
Type Constraints
T: Constrain input and output types to float tensors. Allowed types: tensor(bfloat16), tensor(float), tensor(float16).
Examples#
test_cc_causal_conv_with_state_dilated_d2_l0_k3_no_past_none
Node:
CausalConvWithState(input, weight, bias) -> (output, present_state)
Attributes:
dilation = 2
Inputs:
input: shape=(1, 2, 0), dtype=float32
[]
weight: shape=(2, 1, 3), dtype=float32
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
Outputs:
output: shape=(1, 2, 0), dtype=float32
[]
present_state: shape=(1, 2, 4), dtype=float32
[[[0., 0., 0., 0.],
[0., 0., 0., 0.]]]
test_cc_causal_conv_with_state_dilated_d2_l0_k3_past_none
Node:
CausalConvWithState(input, weight, bias, past_state) -> (output, present_state)
Attributes:
dilation = 2
Inputs:
input: shape=(1, 2, 0), dtype=float32
[]
weight: shape=(2, 1, 3), dtype=float32
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
past_state: shape=(1, 2, 4), dtype=float32
[[[0., 1., 2., 3.],
[4., 5., 6., 7.]]]
Outputs:
output: shape=(1, 2, 0), dtype=float32
[]
present_state: shape=(1, 2, 4), dtype=float32
[[[0., 1., 2., 3.],
[4., 5., 6., 7.]]]
test_cc_causal_conv_with_state_dilated_d2_l1_k3_no_past_none
Node:
CausalConvWithState(input, weight, bias) -> (output, present_state)
Attributes:
dilation = 2
Inputs:
input: shape=(1, 2, 1), dtype=float32
[[[0.],
[1.]]]
weight: shape=(2, 1, 3), dtype=float32
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
Outputs:
output: shape=(1, 2, 1), dtype=float32
[[[0.25],
[0. ]]]
present_state: shape=(1, 2, 4), dtype=float32
[[[0., 0., 0., 0.],
[0., 0., 0., 1.]]]
test_cc_causal_conv_with_state_dilated_d2_l3_k3_no_past_silu_fp16
Node:
CausalConvWithState(input, weight, bias) -> (output, present_state)
Attributes:
activation = "silu"
dilation = 2
Inputs:
input: shape=(1, 2, 3), dtype=float16
[[[0., 1., 2.],
[3., 4., 5.]]]
weight: shape=(2, 1, 3), dtype=float16
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float16
[ 0.25, -0.5 ]
Outputs:
output: shape=(1, 2, 3), dtype=float16
[[[0.1405, 0.2747, 0.427 ],
[0.731 , 1.227 , 3.074 ]]]
present_state: shape=(1, 2, 4), dtype=float16
[[[0., 0., 1., 2.],
[0., 3., 4., 5.]]]
test_cc_causal_conv_with_state_dilated_d2_l3_k3_past_none_fp16
Node:
CausalConvWithState(input, weight, bias, past_state) -> (output, present_state)
Attributes:
dilation = 2
Inputs:
input: shape=(1, 2, 3), dtype=float16
[[[0., 1., 2.],
[3., 4., 5.]]]
weight: shape=(2, 1, 3), dtype=float16
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float16
[ 0.25, -0.5 ]
past_state: shape=(1, 2, 4), dtype=float16
[[[0., 1., 2., 3.],
[4., 5., 6., 7.]]]
Outputs:
output: shape=(1, 2, 3), dtype=float16
[[[0.45, 0.75, 0.65],
[4.6 , 5.8 , 5. ]]]
present_state: shape=(1, 2, 4), dtype=float16
[[[3., 0., 1., 2.],
[7., 3., 4., 5.]]]
test_cc_causal_conv_with_state_dilated_d2_l7_k3_no_past_none
Node:
CausalConvWithState(input, weight, bias) -> (output, present_state)
Attributes:
dilation = 2
Inputs:
input: shape=(1, 2, 7), dtype=float32
[[[ 0., 1., 2., 3., 4., 5., 6.],
[ 7., 8., 9., 10., 11., 12., 13.]]]
weight: shape=(2, 1, 3), dtype=float32
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
Outputs:
output: shape=(1, 2, 7), dtype=float32
[[[ 0.25 , 0.45 , 0.65 , 0.95000005, 1.25 ,
1.55 , 1.85 ],
[ 3. , 3.5 , 6.8 , 7.7 , 10.700001 ,
11.9 , 13.1 ]]]
present_state: shape=(1, 2, 4), dtype=float32
[[[ 3., 4., 5., 6.],
[10., 11., 12., 13.]]]
test_cc_causal_conv_with_state_dilated_d2_l7_k3_past_none
Node:
CausalConvWithState(input, weight, bias, past_state) -> (output, present_state)
Attributes:
dilation = 2
Inputs:
input: shape=(1, 2, 7), dtype=float32
[[[ 0., 1., 2., 3., 4., 5., 6.],
[ 7., 8., 9., 10., 11., 12., 13.]]]
weight: shape=(2, 1, 3), dtype=float32
[[[0. , 0.1, 0.2]],
[[0.3, 0.4, 0.5]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
past_state: shape=(1, 2, 4), dtype=float32
[[[0., 1., 2., 3.],
[4., 5., 6., 7.]]]
Outputs:
output: shape=(1, 2, 7), dtype=float32
[[[ 0.45 , 0.75 , 0.65 , 0.95000005, 1.25 ,
1.55 , 1.85 ],
[ 6.6000004 , 7.8 , 8.6 , 9.8 , 10.700001 ,
11.9 , 13.1 ]]]
present_state: shape=(1, 2, 4), dtype=float32
[[[ 3., 4., 5., 6.],
[10., 11., 12., 13.]]]
test_cc_causal_conv_with_state_dilated_d3_l1_k4_past_silu
Node:
CausalConvWithState(input, weight, bias, past_state) -> (output, present_state)
Attributes:
activation = "silu"
dilation = 3
Inputs:
input: shape=(1, 2, 1), dtype=float32
[[[0.],
[1.]]]
weight: shape=(2, 1, 4), dtype=float32
[[[0. , 0.1, 0.2, 0.3]],
[[0.4, 0.5, 0.6, 0.7]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
past_state: shape=(1, 2, 9), dtype=float32
[[[ 0., 1., 2., 3., 4., 5., 6., 7., 8.],
[ 9., 10., 11., 12., 13., 14., 15., 16., 17.]]]
Outputs:
output: shape=(1, 2, 1), dtype=float32
[[[ 1.4909173],
[18.800001 ]]]
present_state: shape=(1, 2, 9), dtype=float32
[[[ 1., 2., 3., 4., 5., 6., 7., 8., 0.],
[10., 11., 12., 13., 14., 15., 16., 17., 1.]]]
test_cc_causal_conv_with_state_dilated_d3_l2_k1_no_past_swish
Node:
CausalConvWithState(input, weight, bias) -> (output, present_state)
Attributes:
activation = "swish"
dilation = 3
Inputs:
input: shape=(1, 2, 2), dtype=float32
[[[0., 1.],
[2., 3.]]]
weight: shape=(2, 1, 1), dtype=float32
[[[0. ]],
[[0.1]]]
bias: shape=(2,), dtype=float32
[ 0.25, -0.5 ]
Outputs:
output: shape=(1, 2, 2), dtype=float32
[[[ 0.14054413, 0.14054413],
[-0.12766725, -0.0900332 ]]]
present_state: shape=(1, 2, 0), dtype=float32
[]
Differences with previous version (27)#
SchemaDiff: CausalConvWithState (domain 'ai.onnx')
old version: 27
new version: 29
breaking: no
Attributes:
added ‘dilation’: type=INT; required=False; default=1
Documentation:
line similarity: 0.11 (+19/-48 lines)
--- CausalConvWithState v27
+++ CausalConvWithState v29
@@ -1,52 +1,23 @@
+Stateful causal one-dimensional depthwise convolution.
-Stateful causal 1D depthwise convolution.
+`input` has shape `(B, C, L)`, `weight` has shape `(C, 1, K)`, and optional
+`bias` has shape `(C)`: `B` is batch size, `C` is channel count, `L` is input
+length, and `K` is kernel size. Let `d = dilation` (default 1) and
+`H = (K - 1) * d`. Both `K` and `d` must be at least 1, and the effective
+kernel size `H + 1` must fit in a signed 64-bit integer.
-Used by Gated DeltaNet (Qwen3.5) and Mamba (Jamba, FalconMamba) as a preprocessing step.
-Replaces the 3-op pattern (Concat + Conv + Slice) with a single fused operation.
+Both state tensors have shape `(B, C, H)` and store consecutive raw samples
+in chronological order. Form `P` by concatenating `past_state` and `input`
+along axis 2; use a zero tensor of shape `(B, C, H)` when `past_state` is absent.
+For each batch `b`, channel `c`, and position `0 <= t < L`, compute
+`z[b,c,t] = sum_{j=0}^{K-1} weight[c,0,j] * P[b,c,t+j*d] + bias[c]`,
+with omitted bias treated as zero. The output has shape `(B, C, L)` and equals
+`z` for activation 'none' (the default), or `z / (1 + exp(-z))` elementwise
+for 'silu' and its alias 'swish'.
-The convolution is causal (looks only at current and past positions) and depthwise
-(each channel is convolved independently with its own kernel).
-
-The input, weight, past_state, output, and present_state tensors are rank-3 with
-shape (batch_size, channels, length). The optional bias input is rank-1 with
-shape (channels). For higher-dimensional data, use Reshape nodes before and
-after this operator to pack extra dimensions into the batch or channel axis.
-
-Weight layout: (channels, 1, k) for depthwise convolution.
-The carry state stores the last (k-1) positions for incremental decode.
-
-The optional activation attribute supports fused SiLU/Swish activation.
-
-Mathematical definition
-~~~~~~~~~~~~~~~~~~~~~~~
-
-Let ``X`` be the input of shape ``(B, C, L)``, ``W`` the weight of shape
-``(C, 1, k)``, ``b`` the optional bias of shape ``(C)``, and ``S_past`` the
-optional carry state of shape ``(B, C, k - 1)``. Define the padded sequence
-``Xpad`` of shape ``(B, C, L + k - 1)`` as the concatenation along the last
-axis of the carry state (or zero-padding when ``past_state`` is absent) and
-the input::
-
- Xpad[b, c, t] = S_past[b, c, t] if 0 <= t < k - 1 and past_state is present
- Xpad[b, c, t] = 0 if 0 <= t < k - 1 and past_state is absent
- Xpad[b, c, t] = X[b, c, t - (k - 1)] if k - 1 <= t < L + k - 1
-
-The convolution output is then::
-
- Y[b, c, l] = sum_{j=0}^{k-1} W[c, 0, j] * Xpad[b, c, l + j] for 0 <= l < L
-
-with the per-channel bias added when provided::
-
- Y[b, c, l] += b[c]
-
-When ``activation`` is ``"silu"`` or ``"swish"`` the fused activation is
-applied element-wise::
-
- Y[b, c, l] = Y[b, c, l] * sigmoid(Y[b, c, l]) where sigmoid(x) = 1 / (1 + exp(-x))
-
-The updated carry state collects the last ``k - 1`` positions of the padded
-sequence so it can be fed back as ``past_state`` on the next call::
-
- present_state[b, c, j] = Xpad[b, c, L + j] for 0 <= j < k - 1
-
+The next state is `present_state = P[:, :, L:L+H]`, independent of activation.
+When `L < H`, it retains the required past samples or initial zeros.
+Passing this state to the next call preserves convolution across chunk boundaries.
+For `K = 1`, state has shape `(B, C, 0)`. For `L = 0`, output has shape
+`(B, C, 0)` and state is unchanged (all zeros if `past_state` is absent).