For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
selective_scan_fwd_cpu_minimal
def selective_scan_fwd_cpu_minimal[kernel_dtype: DType, DSTATE: Int](batch: Int, dim: Int, seqlen: Int, group_size: Int, delta_softplus: Int8, output: TileTensor[kernel_dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type], x: TileTensor[kernel_dtype, Storage=x.Storage, address_space=x.address_space, linear_idx_type=x.linear_idx_type], u: TileTensor[kernel_dtype, Storage=u.Storage, address_space=u.address_space, linear_idx_type=u.linear_idx_type], delta: TileTensor[kernel_dtype, Storage=delta.Storage, address_space=delta.address_space, linear_idx_type=delta.linear_idx_type], A: TileTensor[kernel_dtype, Storage=A.Storage, address_space=A.address_space, linear_idx_type=A.linear_idx_type], B: TileTensor[kernel_dtype, Storage=B.Storage, address_space=B.address_space, linear_idx_type=B.linear_idx_type], C: TileTensor[kernel_dtype, Storage=C.Storage, address_space=C.address_space, linear_idx_type=C.linear_idx_type], output_strides: IndexList[Int(3)], x_strides: IndexList[Int(4)], u_strides: IndexList[Int(3)], delta_strides: IndexList[Int(3)], A_strides: IndexList[Int(2)], B_strides: IndexList[Int(4)], C_strides: IndexList[Int(4)], ctx: Optional[DeviceContext] = None)
Minimal CPU kernel for selective scan forward - no D, z, or delta_bias.
Parameters:
- βkernel_dtype (
DType): Element type of the input and output tensors. - βDSTATE (
Int): Number of SSM state elements per (batch, dim) pair.
Args:
- βbatch (
Int): Number of sequences processed in parallel. - βdim (
Int): Hidden dimension, equal to the number of channels per sequence position. - βseqlen (
Int): Number of timesteps in each sequence. - βgroup_size (
Int): Number of dims per group; dims in the same group shareBandCinputs. - βdelta_softplus (
Int8): Nonzero appliessoftplustodeltabefore the scan recurrence. - βoutput (
TileTensor[kernel_dtype, Storage=output.Storage, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): Output tensor of shape(batch, dim, seqlen), written. - βx (
TileTensor[kernel_dtype, Storage=x.Storage, address_space=x.address_space, linear_idx_type=x.linear_idx_type]): Checkpoint tensor of shape(batch, dim, n_chunks,2*DSTATE)storing per-chunk cumulativeAandBvalues, written. - βu (
TileTensor[kernel_dtype, Storage=u.Storage, address_space=u.address_space, linear_idx_type=u.linear_idx_type]): Selective scan input tensor of shape(batch, dim, seqlen), read. - βdelta (
TileTensor[kernel_dtype, Storage=delta.Storage, address_space=delta.address_space, linear_idx_type=delta.linear_idx_type]): Time-step tensor of shape(batch, dim, seqlen), read. - βA (
TileTensor[kernel_dtype, Storage=A.Storage, address_space=A.address_space, linear_idx_type=A.linear_idx_type]): SSM recurrence matrix of shape(dim, DSTATE), read. - βB (
TileTensor[kernel_dtype, Storage=B.Storage, address_space=B.address_space, linear_idx_type=B.linear_idx_type]): SSM input projection of shape(batch, n_groups, DSTATE, seqlen), read. - βC (
TileTensor[kernel_dtype, Storage=C.Storage, address_space=C.address_space, linear_idx_type=C.linear_idx_type]): SSM output projection of shape(batch, n_groups, DSTATE, seqlen), read. - βoutput_strides (
IndexList[Int(3)]): 3D strides(batch, dim, seqlen)for indexingoutput. - βx_strides (
IndexList[Int(4)]): 4D strides(batch, dim, n_chunks, 2*DSTATE)for indexingx. - βu_strides (
IndexList[Int(3)]): 3D strides(batch, dim, seqlen)for indexingu. - βdelta_strides (
IndexList[Int(3)]): 3D strides(batch, dim, seqlen)for indexingdelta. - βA_strides (
IndexList[Int(2)]): 2D strides(dim, DSTATE)for indexingA. - βB_strides (
IndexList[Int(4)]): 4D strides(batch, n_groups, DSTATE, seqlen)for indexingB. - βC_strides (
IndexList[Int(4)]): 4D strides(batch, n_groups, DSTATE, seqlen)for indexingC. - βctx (
Optional[DeviceContext]): Device context for parallel execution (defaults toNone).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!