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_gpu
def selective_scan_fwd_gpu[kernel_dtype: DType, DSTATE: Int, output_LT: TensorLayout, x_LT: TensorLayout, out_z_LT: TensorLayout, u_LT: TensorLayout, delta_LT: TensorLayout, A_LT: TensorLayout, B_LT: TensorLayout, C_LT: TensorLayout, D_LT: TensorLayout, z_LT: TensorLayout, delta_bias_LT: TensorLayout](total_batch_dim: Int, batch: Int, dim: Int, seqlen: Int, group_size: Int, delta_softplus: Int8, output: TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin], x: TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin], out_z: TileTensor[kernel_dtype, out_z_LT, MutUntrackedOrigin], u: TileTensor[kernel_dtype, u_LT, MutUntrackedOrigin], delta: TileTensor[kernel_dtype, delta_LT, MutUntrackedOrigin], A: TileTensor[kernel_dtype, A_LT, MutUntrackedOrigin], B: TileTensor[kernel_dtype, B_LT, MutUntrackedOrigin], C: TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin], D: TileTensor[kernel_dtype, D_LT, MutUntrackedOrigin], z: TileTensor[kernel_dtype, z_LT, MutUntrackedOrigin], delta_bias: TileTensor[kernel_dtype, delta_bias_LT, MutUntrackedOrigin], output_strides: IndexList[Int(3)], x_strides: IndexList[Int(4)], out_z_strides: IndexList[Int(3)], 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)], D_strides: IndexList[Int(1)], z_strides: IndexList[Int(3)], delta_bias_strides: IndexList[Int(1)])
GPU kernel for selective scan forward pass.
Each thread processes one (batch, dim) pair and iterates through the sequence.
Parameters:
- βkernel_dtype (
DType): Element type of the input and output tensors. - βDSTATE (
Int): Number of SSM state elements per (batch, dim) pair. - βoutput_LT (
TensorLayout): Memory layout of theoutputtensor. - βx_LT (
TensorLayout): Memory layout of thexcheckpoint tensor. - βout_z_LT (
TensorLayout): Memory layout of theout_zgated output tensor. - βu_LT (
TensorLayout): Memory layout of theuinput tensor. - βdelta_LT (
TensorLayout): Memory layout of thedeltatime-step tensor. - βA_LT (
TensorLayout): Memory layout of theArecurrence matrix. - βB_LT (
TensorLayout): Memory layout of theBinput projection tensor. - βC_LT (
TensorLayout): Memory layout of theCoutput projection tensor. - βD_LT (
TensorLayout): Memory layout of theDskip connection tensor. - βz_LT (
TensorLayout): Memory layout of thezgating tensor. - βdelta_bias_LT (
TensorLayout): Memory layout of thedelta_biastensor.
Args:
- βtotal_batch_dim (
Int): Total(batch, dim)pairs launched. - βbatch (
Int): Number of sequences. - βdim (
Int): Hidden dimension (channels per sequence position). - βseqlen (
Int): Sequence length. - βgroup_size (
Int): Dims per group sharingBandC. - βdelta_softplus (
Int8): When nonzero, applysoftplustodelta. - βoutput (
TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin]): Output tensor(batch, dim, seqlen). - βx (
TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin]): Checkpoint tensor(batch, dim, n_chunks, 2*DSTATE). - βout_z (
TileTensor[kernel_dtype, out_z_LT, MutUntrackedOrigin]): Gated output(batch, dim, seqlen)whenzis present. - βu (
TileTensor[kernel_dtype, u_LT, MutUntrackedOrigin]): Input tensor(batch, dim, seqlen). - βdelta (
TileTensor[kernel_dtype, delta_LT, MutUntrackedOrigin]): Time-step tensor(batch, dim, seqlen). - βA (
TileTensor[kernel_dtype, A_LT, MutUntrackedOrigin]): Recurrence matrix(dim, DSTATE). - βB (
TileTensor[kernel_dtype, B_LT, MutUntrackedOrigin]): Input projection(batch, n_groups, DSTATE, seqlen). - βC (
TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin]): Output projection(batch, n_groups, DSTATE, seqlen). - βD (
TileTensor[kernel_dtype, D_LT, MutUntrackedOrigin]): Skip vector(dim,). - βz (
TileTensor[kernel_dtype, z_LT, MutUntrackedOrigin]): Gating tensor(batch, dim, seqlen). - βdelta_bias (
TileTensor[kernel_dtype, delta_bias_LT, MutUntrackedOrigin]): Bias vector(dim,). - βoutput_strides (
IndexList[Int(3)]): Stride tuple foroutput. - βx_strides (
IndexList[Int(4)]): Stride tuple forx. - βout_z_strides (
IndexList[Int(3)]): Stride tuple forout_z. - βu_strides (
IndexList[Int(3)]): Stride tuple foru. - βdelta_strides (
IndexList[Int(3)]): Stride tuple fordelta. - βA_strides (
IndexList[Int(2)]): Stride tuple forA. - βB_strides (
IndexList[Int(4)]): Stride tuple forB. - βC_strides (
IndexList[Int(4)]): Stride tuple forC. - βD_strides (
IndexList[Int(1)]): Stride tuple forD. - βz_strides (
IndexList[Int(3)]): Stride tuple forz. - βdelta_bias_strides (
IndexList[Int(1)]): Stride tuple fordelta_bias.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!