For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Mojo struct
CausalConv1DVarlenFwd
struct CausalConv1DVarlenFwd[activation: StringSlice[ImmStaticOrigin], channels_last: Bool = False]
Varlen causal 1D convolution forward pass.
Performs causal 1D convolution on variable-length sequences that are concatenated together. Uses cumulative sequence lengths to identify sequence boundaries.
The registration lives here in the built-in kernel library (mirroring the
gated_delta_conv1d_fwd precedent) so the graph compiler / serve path can
resolve the op with no out-of-tree custom_extensions. The kernel math
lives in state_space.varlen_causal_conv1d.
The underlying kernels index x/output purely through runtime
dim/seqlen strides, so the token-axis memory layout is a free parameter.
With channels_last=True the op consumes and produces tokens-major
(total_seqlen, dim) tensors β the layout the surrounding graph
naturally carries β eliminating the materialized (dim, total_seqlen)
transposes on both sides of the op. Only the stride/extent bookkeeping
below changes; the per-element compute is identical in both layouts.
Tensor Shapes:
- output: (dim, total_seqlen) - Output tensor
((total_seqlen, dim) when channels_last)
- x: (dim, total_seqlen) - Input tensor (concatenated sequences)
((total_seqlen, dim) when channels_last)
- weight: (dim, width) - Convolution weights per channel
- bias: (dim,) - Per-channel bias
- query_start_loc: (batch + 1,) - Cumulative sequence lengths
- cache_indices: (batch,) - Indices into conv_states (optional)
- has_initial_state: (batch,) - Whether to use initial state (optional)
- conv_states: (batch, dim, width - 1) - Conv states (optional, in/out)
Parametersβ
- βactivation (
StringSlice[ImmStaticOrigin]): Activation function - "none" or "silu". - βchannels_last (
Bool): If True,xandoutputare tokens-major (total_seqlen, dim) instead of (dim, total_seqlen).
Implemented traitsβ
Methodsβ
executeβ
static def execute[dtype: DType, target: StringSlice[ImmStaticOrigin]](output: ManagedTensorSlice[IOSpec[_, _].Output, static_spec=output.static_spec], x: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=x.static_spec], weight: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=weight.static_spec], bias: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=bias.static_spec], conv_states: ManagedTensorSlice[IOSpec[_, _].MutableInput, static_spec=conv_states.static_spec], query_start_loc: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=query_start_loc.static_spec], cache_indices: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=cache_indices.static_spec], has_initial_state: ManagedTensorSlice[IOSpec[_, _].Input, static_spec=has_initial_state.static_spec], ctx: DeviceContext)