Skip to navigation
ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsModelsMinimax M3 VlKernelsnemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100

View as MarkdownOpen in Claude

Build locality-ordered backward task tables and their CTA walk on the device.

One JIT issues four launches: work scan, segment keys, bin scan, table scatter. Forward buckets have ascending queries and contiguous (head, query window, key block) segments, so offsets[segment] + task - first_tasks[segment] reproduces the Torch reference order kept in tests/functional_tests/models/minimax_m3_vl/test_msa_task_build_sm100.py. Noncontiguous segments keep source order (descriptor flag 2). Capacity overflow disables the CTA walk (flag 1). Exact task counts and the walk stay on the device; the host launches a grid bound and surplus CTAs take empty intervals.

Module Contents

Classes

NameDescription
_MSABackwardTaskTablesTask tables in the locality order plus the CTA-walk descriptor the main kernel reads.
_MSATaskBuildSm100One JIT owns the four build stages and the interpretation of segment scratch.

Functions

NameDescription
_compileCompile the four-launch build once per process with dynamic work, row, edge, document and bin counts.
_cta_exclusive_scanExclusive prefix across SCAN_THREADS; all threads must participate.
_decode_taskForward-order task task -> (index_head, document, local kblock, valid, first edge).
_task_build_sizes(capacity, bins, scratch_words, table_words) of the build for this schedule (host shape math only).
_task_capacityUpper bound of the task count from the schedule shapes (disjoint work items).
_warp_inclusive_scanInclusive prefix sum across the 32 lanes of a warp (shfl.up; clamp 0 = plain up-shuffle).
build_backward_tasksEnqueue the four build launches without a host sync; return the tables and the CTA walk.
task_build_storageRequired scratch/table int32 words; the caller owns and may reuse both buffers.

Data

BIN_COUNTS

BIN_FIRST_TASKS

BIN_LAST_TASKS

BIN_OFFSETS

DEC_WORDS

DESC_FLAGS

DESC_GRID_CTAS

DESC_NUM_FULL_CTAS

DESC_NUM_TASKS

DESC_NUM_TASK_ROWS

DESC_NUM_WORK

DESC_ROWS_PER_CTA

DESC_TAIL_ROWS

DESC_WORDS

FLAG_CAPACITY_OVERFLOW

FLAG_NONCONTIGUOUS_SEGMENTS

MAX_BINS

SCAN_PER

SCAN_THREADS

SCAN_TILE

THREADS

_INT32_MAX

_LOCALITY_WINDOW

API

class nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSABackwardTaskTables(
task_meta: torch.Tensor,
task_qrows: torch.Tensor,
task_qpos: torch.Tensor,
desc: torch.Tensor,
grid_launch: int
)
Dataclass

Task tables in the locality order plus the CTA-walk descriptor the main kernel reads.

The tables hold capacity rows; rows past the task count are never written nor read (the descriptor’s exact count bounds every CTA interval). grid_launch >= desc[DESC_GRID_CTAS].

desc
Tensor
grid_launch
int
task_meta
Tensor
task_qpos
Tensor
task_qrows
Tensor
class nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSATaskBuildSm100()

One JIT owns the four build stages and the interpretation of segment scratch.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSATaskBuildSm100.__call__(
mWorkMeta: cutlass.cute.Tensor,
mWorkCount: cutlass.cute.Tensor,
mTaskEnds: cutlass.cute.Tensor,
mRowPtr: cutlass.cute.Tensor,
mQIdx: cutlass.cute.Tensor,
mCuSeqlens: cutlass.cute.Tensor,
mDocStarts: cutlass.cute.Tensor,
mTaskSegments: cutlass.cute.Tensor,
mBins: cutlass.cute.Tensor,
mTaskDecode: cutlass.cute.Tensor,
mTaskMeta: cutlass.cute.Tensor,
mQRows: cutlass.cute.Tensor,
mQPos: cutlass.cute.Tensor,
mDesc: cutlass.cute.Tensor,
num_windows: cutlass.Int32,
num_kblocks: cutlass.Int32,
locality_window: cutlass.Int32,
num_sms: cutlass.Int32,
stream: cuda.bindings.driver.CUstream
)
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSATaskBuildSm100.assign_segments_kernel(
mWorkMeta: cutlass.cute.Tensor,
mTaskEnds: cutlass.cute.Tensor,
mRowPtr: cutlass.cute.Tensor,
mQIdx: cutlass.cute.Tensor,
mCuSeqlens: cutlass.cute.Tensor,
mDocStarts: cutlass.cute.Tensor,
mTaskSegments: cutlass.cute.Tensor,
mBins: cutlass.cute.Tensor,
mTaskDecode: cutlass.cute.Tensor,
mDesc: cutlass.cute.Tensor,
num_windows: cutlass.Int32,
num_kblocks: cutlass.Int32,
locality_window: cutlass.Int32
)
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSATaskBuildSm100.scan_bins_kernel(
mBins: cutlass.cute.Tensor,
mDesc: cutlass.cute.Tensor
)

Exclusive bin offsets; flag segments that are not contiguous source runs.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSATaskBuildSm100.scan_work_kernel(
mWorkMeta: cutlass.cute.Tensor,
mWorkCount: cutlass.cute.Tensor,
mTaskEnds: cutlass.cute.Tensor,
mBins: cutlass.cute.Tensor,
mDesc: cutlass.cute.Tensor
)

Inclusive task offsets, exact counts and cleared segment bins.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._MSATaskBuildSm100.scatter_tables_kernel(
mQIdx: cutlass.cute.Tensor,
mCuSeqlens: cutlass.cute.Tensor,
mDocStarts: cutlass.cute.Tensor,
mTaskSegments: cutlass.cute.Tensor,
mBins: cutlass.cute.Tensor,
mTaskDecode: cutlass.cute.Tensor,
mTaskMeta: cutlass.cute.Tensor,
mQRows: cutlass.cute.Tensor,
mQPos: cutlass.cute.Tensor,
mDesc: cutlass.cute.Tensor,
num_windows: cutlass.Int32,
num_kblocks: cutlass.Int32,
num_sms: cutlass.Int32
)
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._compile() -> typing.Any

Compile the four-launch build once per process with dynamic work, row, edge, document and bin counts.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._cta_exclusive_scan(
value: cutlass.Int32,
tidx: cutlass.Int32,
with_total: cutlass.Constexpr = False
)

Exclusive prefix across SCAN_THREADS; all threads must participate.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._decode_task(
mWorkMeta: cutlass.cute.Tensor,
mTaskEnds: cutlass.cute.Tensor,
mRowPtr: cutlass.cute.Tensor,
num_work: cutlass.Int32,
task: cutlass.Int32
)

Forward-order task task -> (index_head, document, local kblock, valid, first edge).

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._task_build_sizes(
num_tokens: int,
workspace_rows: int
) -> tuple[int, int, int, int]

(capacity, bins, scratch_words, table_words) of the build for this schedule (host shape math only).

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._task_capacity(
) -> int

Upper bound of the task count from the schedule shapes (disjoint work items).

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._warp_inclusive_scan(
value: cutlass.Int32,
lane: cutlass.Int32
) -> cutlass.Int32

Inclusive prefix sum across the 32 lanes of a warp (shfl.up; clamp 0 = plain up-shuffle).

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.build_backward_tasks(
num_tokens: int,
workspace_rows: int,
num_sms: int,
scratch: torch.Tensor,
tables: torch.Tensor

Enqueue the four build launches without a host sync; return the tables and the CTA walk.

Parameters:

schedule
MSABackwardSchedule

Forward-derived int32 schedule (see MSABackwardSchedule), all on one CUDA device.

num_tokens
int

Compact token count T of the backward call.

workspace_rows
int

Aligned K/V workspace length W, a multiple of 128.

num_sms
int

Streaming multiprocessors of the device; sizes the CTA walk.

scratch
torch.Tensor

Int32 buffer of task_build_storage(...)[0] words on the schedule device, carved as descriptor | task ends | task segments | bins. The descriptor stays at offset zero to keep its 16-byte alignment.

tables
torch.Tensor

Int32 buffer of task_build_storage(...)[1] words on the schedule device, carved as task_meta [capacity, 4] | task_qrows [capacity, 8] | task_qpos [capacity, 8].

Returns: _MSABackwardTaskTables

The three task tables (views into tables), the device descriptor (a view into

Raises:

  • ValueError: If the locality bins exceed MAX_BINS, which happens past roughly 250k tokens.
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.task_build_storage(
num_tokens: int,
workspace_rows: int
) -> tuple[int, int]

Required scratch/table int32 words; the caller owns and may reuse both buffers.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.BIN_COUNTS = 0
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.BIN_FIRST_TASKS = 1
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.BIN_LAST_TASKS = 2
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.BIN_OFFSETS = 3
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DEC_WORDS = 3
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_FLAGS = 7
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_GRID_CTAS = 4
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_NUM_FULL_CTAS = 2
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_NUM_TASKS = 6
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_NUM_TASK_ROWS = 0
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_NUM_WORK = 5
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_ROWS_PER_CTA = 1
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_TAIL_ROWS = 3
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.DESC_WORDS = 8
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.FLAG_CAPACITY_OVERFLOW = 1
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.FLAG_NONCONTIGUOUS_SEGMENTS = 2
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.MAX_BINS = 1 << 22
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.SCAN_PER = SCAN_TILE // SCAN_THREADS
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.SCAN_THREADS = 1024
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.SCAN_TILE = 8192
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100.THREADS = 256
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._INT32_MAX = 2 ** 31 - 1
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_task_build_sm100._LOCALITY_WINDOW = 512