core.ssm.ops.batch_invariant_decode#
Batch-invariant Mamba decode using buffered chunk replay.
Module Contents#
Classes#
Per-slot persistent state for the buffered decode scan. |
|
Adapter between a MambaMixer and the buffered decode. |
Functions#
Copy contiguous rows, skipping entries whose destination index is -1. |
|
Copy rows into persistent BIK buffers without touching inactive graph lanes. |
|
Run the training scan pipeline over buffered decode chunks. |
|
Run one decode token with full chunk-scan arithmetic. |
API#
- core.ssm.ops.batch_invariant_decode._masked_update_rows_kernel(
- states_ptr,
- indices_ptr,
- values_ptr,
- state_row_stride,
- value_row_stride,
- ROW_SIZE: triton.language.constexpr,
- BLOCK_SIZE: triton.language.constexpr,
Copy contiguous rows, skipping entries whose destination index is -1.
- core.ssm.ops.batch_invariant_decode._masked_update_rows(
- states: torch.Tensor,
- indices: torch.Tensor,
- values: torch.Tensor,
Copy rows into persistent BIK buffers without touching inactive graph lanes.
- core.ssm.ops.batch_invariant_decode._mamba_chunk_scan_decode_rows(
- x,
- z,
- dt,
- A,
- B,
- C,
- chunk_size,
- chunk_starts,
- slots,
- target_rows,
- chunk_flags,
- initial_states,
- out,
- D=None,
- dt_bias=None,
- dt_softplus=False,
- dt_limit=(0.0, float('inf')),
Run the training scan pipeline over buffered decode chunks.
Each kernel computes only the row or boundary consumed by this decode step, while preserving the training kernel’s arithmetic for that result.
- class core.ssm.ops.batch_invariant_decode.BatchInvariantDecodeBuffers#
Per-slot persistent state for the buffered decode scan.
- x: torch.Tensor#
None
- z: torch.Tensor#
None
- dt: torch.Tensor#
None
- B: torch.Tensor#
None
- C: torch.Tensor#
None
- num_buffered: torch.Tensor#
None
- out: torch.Tensor#
None
- target_rows: torch.Tensor#
None
- chunk_flags: torch.Tensor#
None
- classmethod allocate(
- max_requests: int,
- chunk_size: int,
- nheads: int,
- headdim: int,
- ngroups: int,
- dstate: int,
- device: torch.device,
- dtype: torch.dtype,
Allocate the per-slot decode buffers.
- seed(
- x: torch.Tensor,
- z: torch.Tensor,
- dt: torch.Tensor,
- B: torch.Tensor,
- C: torch.Tensor,
- cu_seqlens: torch.Tensor,
- batch_indices: torch.Tensor,
Store each prefill’s unfinished chunk for decode replay.
- core.ssm.ops.batch_invariant_decode.batch_invariant_decode_buffered_scan(
- buffers: core.ssm.ops.batch_invariant_decode.BatchInvariantDecodeBuffers,
- x: torch.Tensor,
- z: torch.Tensor,
- dt: torch.Tensor,
- B: torch.Tensor,
- C: torch.Tensor,
- A: torch.Tensor,
- D: torch.Tensor,
- dt_bias: torch.Tensor,
- batch_indices: torch.Tensor,
- ssm_state: torch.Tensor,
Run one decode token with full chunk-scan arithmetic.
Mutates the replay buffers and commits
ssm_statewhen a chunk fills.
- class core.ssm.ops.batch_invariant_decode.MambaBatchInvariantDecode(mixer)#
Adapter between a MambaMixer and the buffered decode.
Initialization
- _get_buffers(
- max_requests,
- x,
- B,
- seed(x, z, dt, B, C, cu_seqlens, batch_indices, max_requests) None#
Seed replay buffers from the prefill tail.
- step(x, z, dt, B, C, batch_indices, ssm_state) torch.Tensor#
Run one decode step using the mixer’s flattened layouts.