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_update_gpu
def selective_scan_update_gpu[kernel_dtype: DType, DSTATE: Int, state_out_LT: TensorLayout, output_LT: TensorLayout, state_in_LT: TensorLayout, x_LT: TensorLayout, dt_LT: TensorLayout, A_LT: TensorLayout, B_LT: TensorLayout, C_LT: TensorLayout, D_LT: TensorLayout, z_LT: TensorLayout, dt_bias_LT: TensorLayout](total_batch_dim: Int, batch: Int, dim: Int, group_size: Int, delta_softplus: Int8, state_out: TileTensor[kernel_dtype, state_out_LT, MutUntrackedOrigin], output: TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin], state_in: TileTensor[kernel_dtype, state_in_LT, MutUntrackedOrigin], x: TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin], dt: TileTensor[kernel_dtype, dt_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], dt_bias: TileTensor[kernel_dtype, dt_bias_LT, MutUntrackedOrigin], state_out_strides: IndexList[Int(3)], output_strides: IndexList[Int(2)], state_in_strides: IndexList[Int(3)], x_strides: IndexList[Int(2)], dt_strides: IndexList[Int(2)], A_strides: IndexList[Int(2)], B_strides: IndexList[Int(3)], C_strides: IndexList[Int(3)], D_strides: IndexList[Int(1)], z_strides: IndexList[Int(2)], dt_bias_strides: IndexList[Int(1)])
GPU kernel for selective scan update (single step).
Each thread processes one (batch, dim) pair. Reads initial state from state_in, writes updated state to state_out.
Parameters:
- βkernel_dtype (
DType): Element type of the input and output tensors. - βDSTATE (
Int): Number of SSM state elements per (batch, dim) pair. - βstate_out_LT (
TensorLayout): Memory layout of thestate_outtensor. - βoutput_LT (
TensorLayout): Memory layout of theoutputtensor. - βstate_in_LT (
TensorLayout): Memory layout of thestate_intensor. - βx_LT (
TensorLayout): Memory layout of thexinput tensor. - βdt_LT (
TensorLayout): Memory layout of thedttime-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. - βdt_bias_LT (
TensorLayout): Memory layout of thedt_biastensor.
Args:
- βtotal_batch_dim (
Int): Total number of (batch, dim) pairs launched, equal tobatch * dim, used for thread bounds checking. - βbatch (
Int): Number of sequences processed in parallel. - βdim (
Int): Hidden dimension, equal to the number of channels per sequence position. - βgroup_size (
Int): Number of dims per group; dims in the same group shareBandCinputs. - βdelta_softplus (
Int8): Nonzero appliessoftplustodtbefore the scan recurrence. - βstate_out (
TileTensor[kernel_dtype, state_out_LT, MutUntrackedOrigin]): Updated SSM state tensor of shape(batch, dim, DSTATE), written. - βoutput (
TileTensor[kernel_dtype, output_LT, MutUntrackedOrigin]): Step output tensor of shape(batch, dim), written. - βstate_in (
TileTensor[kernel_dtype, state_in_LT, MutUntrackedOrigin]): Previous SSM state tensor of shape(batch, dim, DSTATE), read. - βx (
TileTensor[kernel_dtype, x_LT, MutUntrackedOrigin]): Input value tensor of shape(batch, dim)for the current timestep, read. - βdt (
TileTensor[kernel_dtype, dt_LT, MutUntrackedOrigin]): Time-step tensor of shape(batch, dim), read. - βA (
TileTensor[kernel_dtype, A_LT, MutUntrackedOrigin]): SSM recurrence matrix of shape(dim, DSTATE), read. - βB (
TileTensor[kernel_dtype, B_LT, MutUntrackedOrigin]): SSM input projection of shape(batch, n_groups, DSTATE), read. - βC (
TileTensor[kernel_dtype, C_LT, MutUntrackedOrigin]): SSM output projection of shape(batch, n_groups, DSTATE), read. - βD (
TileTensor[kernel_dtype, D_LT, MutUntrackedOrigin]): Skip connection vector of shape(dim,), read; added asD * xto the output when present. - βz (
TileTensor[kernel_dtype, z_LT, MutUntrackedOrigin]): Gating tensor of shape(batch, dim), read; gates the output viaz * sigmoid(z)when present. - βdt_bias (
TileTensor[kernel_dtype, dt_bias_LT, MutUntrackedOrigin]): Bias vector of shape(dim,), read; added todtbeforesoftpluswhen present. - βstate_out_strides (
IndexList[Int(3)]): 3D strides(batch, dim, DSTATE)for indexingstate_out. - βoutput_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingoutput. - βstate_in_strides (
IndexList[Int(3)]): 3D strides(batch, dim, DSTATE)for indexingstate_in. - βx_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingx. - βdt_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingdt. - βA_strides (
IndexList[Int(2)]): 2D strides(dim, DSTATE)for indexingA. - βB_strides (
IndexList[Int(3)]): 3D strides(batch, n_groups, DSTATE)for indexingB. - βC_strides (
IndexList[Int(3)]): 3D strides(batch, n_groups, DSTATE)for indexingC. - βD_strides (
IndexList[Int(1)]): 1D strides(dim,)for indexingD. - βz_strides (
IndexList[Int(2)]): 2D strides(batch, dim)for indexingz. - βdt_bias_strides (
IndexList[Int(1)]): 1D strides(dim,)for indexingdt_bias.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!