ai.onnx.CausalConvWithState

ai.onnx · standard ONNX operator · ONNX opset ≥ 27

Description

Stateful causal 1-D depthwise convolution. It left-pads each channel with past_state (or zeros), applies a (channels, 1, kernel_size) depthwise convolution and optional SiLU/Swish activation, and returns both the output and the last kernel_size - 1 values as present_state. This package supports float16 and float32 tensors; bfloat16 is unsupported.

See the ONNX CausalConvWithState spec for the reference semantics.

Inputs

Name Logical dtype Rank Shape Description Presence
input T 3 — Input tensor with shape (batch_size, channels, length) in channels-first layout. required
weight T 3 — Depthwise convolution kernel with shape (channels, 1, kernel_size), matching the ONNX Conv weight layout for group = channels. required
bias T 1 — Optional per-channel bias with shape (channels). optional
past_state T 3 — Carry state from the previous step with shape (batch_size, channels, kernel_size - 1). If omitted, the left padding is zero. optional

Outputs

Name Logical dtype Rank Shape Description Presence
output T 3 same as input Convolution output with the same shape as input. required
present_state T 3 derived Updated carry state with shape (batch_size, channels, kernel_size - 1), including prior state or zero-padding when the current input is shorter than the state. required

Attributes

Default values (overridable per request):

Attribute Default Description
activation "none" Optional fused activation. silu and swish are aliases; none leaves the convolution result unchanged.

Type constraints

Variable Allowed dtypes
T float32, float16

Files

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/ai.onnx.CausalConvWithState", { version: 1 });

const inputData = Float32Array.of(2, 3);
const weightData = new Float32Array(5).fill(1);

const { output, present_state } = await kernel({
  input: { data: inputData, shape: [1, 1, 2] },
  weight: { data: weightData, shape: [1, 1, 5] },
});
console.log({ output, present_state });
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.