com.microsoft.VarlenCausalConvWithState
com.microsoft · ONNX Runtime contrib operator · contrib since_version 1
Description
Stateful causal depthwise convolution over packed token-major variable-length sequences, without reads across sequence boundaries. initial_state carries preceding raw samples and final_state is fully written. At positive state_update_capacity, capture_count selects a clamped prefix of raw input tokens for compact state_update; inactive slots are zero. SiLU and Swish are aliases. This implementation supports float16 and float32 with float32 accumulation; bfloat16 is not implemented.
See the ONNX Runtime VarlenCausalConvWithState contrib-operator spec for the reference semantics.
Inputs
| Name | Upstream name | Logical dtype | WebGPU storage | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|---|
inputT |
input |
T |
same as logical dtype | 2 |
— | Token-major packed input with shape (total_tokens, channels). |
required |
weightT |
weight |
T |
same as logical dtype | 3 |
— | Depthwise kernel with shape (channels, 1, kernel_size). |
required |
cumulativeSequenceLengthT |
cumulative_sequence_length |
M |
int32 |
1 |
— | Exclusive prefix sums with shape (batch_size + 1), starting at 0, ending at total_tokens, and strictly increasing so every sequence is non-empty. Sequence i owns tokens [cum[i], cum[i + 1]). Outputs are unspecified for a malformed schedule. |
required |
biasT |
bias |
T |
same as logical dtype | 1 |
— | Optional per-channel bias with shape (channels,). In an ONNX graph an omitted bias must still occupy input index 3 as an empty name so initial_state stays at index 4. |
optional |
initialStateT |
initial_state |
T |
same as logical dtype | 3 |
— | Required committed carry state with shape (batch_size, channels, (kernel_size - 1) * dilation), holding the raw samples immediately preceding this call. |
required |
captureCountT |
capture_count |
M |
int32 |
1 |
— | Optional int32 vector with shape (batch_size). Required exactly when state_update_capacity is positive; each value is clamped to [0, min(state_update_capacity, sequence_length)]. |
optional |
Outputs
| Name | Upstream name | Logical dtype | Rank | Shape | Description | Presence |
|---|---|---|---|---|---|---|
outputT |
output |
T |
same as inputT |
same as inputT |
Convolution output with the same shape as input. |
required |
finalStateT |
final_state |
T |
3 |
derived | State after each sequence's final token, shape (batch_size, channels, (kernel_size - 1) * dilation). Always fully written. |
required |
stateUpdateT |
state_update |
T |
3 |
derived | Optional compact transition values with shape (batch_size, state_update_capacity, channels). Active slots contain the original local input tokens and all other slots are zero. |
optional |
Attributes
Default values (overridable per request):
| Attribute | Default | Description |
|---|---|---|
activation |
"none" |
Fused activation applied after convolution and bias. One of none, silu, or swish; the standard default is none. |
dilation |
1 |
Positive integer spacing between taps; the initial and final states hold (kernel_size - 1) * dilation raw samples. |
state_update_capacity |
0 |
Static number of compact per-request prefix transition values to expose, in [0, 8]. The standard default is 0. |
Type constraints
| Variable | Allowed dtypes |
|---|---|
T |
float32, float16 |
M |
int32 |
Implementation variants
One implementation is selected per call from the device capabilities, the request shapes and the dtypes; these notes say what each one covers.
unit— Direct single-token sequence convolution with contiguous vector state traffic and fused capture writes. Strictly increasing schedules withtotal_tokens == batch_sizeimply one token per sequence. Channel divisibility selects the vector width; the workgroup respects device limits. Dilated and f16 requests use other variants.capture_copy_stream— Writes thestate_updateslots in a separate pass over contiguous 2- or 4-channel vectors, zero-filling inactive slots, then convolves with the streaming pass: one invocation walks a block of consecutive tokens of one channel. Requires float32, an even channel count, dilation 1 and kernel size 2 to 8.capture_copy— Writes thestate_updateslots in a separate pass over contiguous 2- or 4-channel vectors, zero-filling inactive slots, then convolves with one invocation per output element. Requires float32 and an even channel count.
Files
metadata.json— kernel metadata (id, file digests, manifest spec, provenance)manifest.json— the op contract (source of truth)test.json— correctness casesbench.json— benchmark casesvarlen-causal-conv-stream.wgsl.jinjavarlen-causal-conv.wgsl.jinjavarlen-state-update.wgsl.jinjavarlen-unit-sequence.wgsl.jinja
Use with @huggingface/kernels
npm install --save-exact @huggingface/kernels@0.0.1-preview.4
Paste the example into a browser app that resolves npm imports. Serve the app over HTTPS or localhost with WebGPU available.
Required output shapes and logical data types are inferred from the supplied inputs and attributes; result tensors are allocated automatically.
The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.
It follows the v1 branch as fixes land. To pin exact artifact bytes, pass a 40-character commit revision instead of version.
import { getKernel } from "@huggingface/kernels";
const kernel = await getKernel("webgpu-kernels/com.microsoft.VarlenCausalConvWithState", { version: 1 });
const inputTData = Float32Array.of(-1.125, -1.0625, -1, -0.9375);
const weightTData = Float32Array.of(
-0.28125, -0.25, -0.21875, -0.1875, -0.15625, -0.125, -0.09375, -0.0625, -0.03125, 0,
0.03125, 0.0625, 0.09375, 0.125, 0.15625, 0.1875,
);
const cumulativeSequenceLengthTData = Int32Array.of(0, 1);
const initialStateTData = Float32Array.of(
-1.375, -1.25, -1.125, -1, -0.875, -0.75, -0.625, -0.5, -0.375, -0.25, -0.125, 0,
);
const { outputT, finalStateT } = await kernel({
inputT: { data: inputTData, shape: [1, 4] },
weightT: { data: weightTData, shape: [4, 1, 4] },
cumulativeSequenceLengthT: { data: cumulativeSequenceLengthTData, shape: [2] },
initialStateT: { data: initialStateTData, shape: [1, 4, 3] },
});
console.log({ outputT, finalStateT });
- Downloads last month
- -
Requires WebGPU support. See the compatibility table.