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

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100

View as Markdown

Gradient finalize for the MiniMax M3 MSA SM100 backward (one launch).

  • dQ: the main kernel accumulates dQ with packed 16-bit atomics (DQ_ACCUM_DTYPE) either into a head-pair interleaved pool [T, Hq/2, D, 2] — de-interleaved here: pool row (t, hp) of 256 elements becomes rows 2hp and 2hp + 1 of the BF16 [T, Hq, D] gradient (16-byte loads, 8-byte stores) — or into a plain [T, Hq, D] pool, which is cast in place (16-byte loads and stores). One warp per 256-element pool row.
  • dK/dV: the FP32 pool is cast to BF16 (2048 elements per CTA, 16-byte loads/stores).

Grid [max(dq_blocks, kv_blocks), 2]: blockIdx.y == 0 does 8 dQ rows, 1 does one 2048-element dK/dV chunk; both roles are predicated on their own extents.

Module Contents

Classes

NameDescription
_MSAGradFinalizeSm100-

Functions

NameDescription
_compileCompile the finalize once per dQ pool dtype and layout.
run_grad_finalizeCast the accumulation pools to the BF16 gradients in one launch.

Data

DQ_ROWS_PER_CTA

KV_PER_CTA

NUM_THREADS

POOL_ROW

API

class nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100._MSAGradFinalizeSm100(
interleaved: bool
)
rows_per_cta
= NUM_THREADS // (POOL_ROW // self.vals_per_thread)
vals_per_thread
= 16 if interleaved else 8
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100._MSAGradFinalizeSm100.__call__(
mDQPool: cutlass.cute.Tensor,
mDQOut: cutlass.cute.Tensor,
mKVPool: cutlass.cute.Tensor,
mKVOut: cutlass.cute.Tensor,
num_dq_rows: cutlass.Int32,
num_kv_blocks: cutlass.Int32,
stream: cuda.bindings.driver.CUstream
)
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100._MSAGradFinalizeSm100.kernel(
mDQPool: cutlass.cute.Tensor,
mDQOut: cutlass.cute.Tensor,
mKVPool: cutlass.cute.Tensor,
mKVOut: cutlass.cute.Tensor,
num_dq_rows: cutlass.Int32,
num_kv_blocks: cutlass.Int32,
tiled_in: cutlass.cute.TiledCopy,
tiled_out: cutlass.cute.TiledCopy,
tiled_kv_in: cutlass.cute.TiledCopy,
tiled_kv_out: cutlass.cute.TiledCopy
)
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100._compile(
dq_dtype: torch.dtype,
interleaved: bool
) -> typing.Any

Compile the finalize once per dQ pool dtype and layout.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100.run_grad_finalize(
dq_pool: torch.Tensor,
dq_out: torch.Tensor,
kv_pool: torch.Tensor,
kv_out: torch.Tensor
) -> None

Cast the accumulation pools to the BF16 gradients in one launch.

Parameters:

dq_pool
torch.Tensor

Contiguous 16-bit [T, Hq/2, D, 2] head-pair pool, or a plain [T, Hq, D] pool.

dq_out
torch.Tensor

Contiguous BF16 [T, Hq, D] written in place.

kv_pool
torch.Tensor

Contiguous FP32 [N] dK/dV pool, N a multiple of 2048.

kv_out
torch.Tensor

Contiguous BF16 [N] written in place.

nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100.DQ_ROWS_PER_CTA = NUM_THREADS // 32
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100.KV_PER_CTA = NUM_THREADS * 8
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100.NUM_THREADS = 256
nemo_automodel.components.models.minimax_m3_vl.kernels.msa_backward_postprocess_sm100.POOL_ROW = 2 * HEAD_DIM