Skip to content

vllm.models.mistral.mistral_large4.amd.specialized_decode.mono.layout

Compile-time storage layout and CTA schedule for the GLM-5 MonoKernel.

Functions:

  • dn_tile –

    Return rows per expert-down/FFN-reduce task for the tuned schedule.

  • down_prefetch_batch –

    How many expert-down weight tiles a wave keeps in flight.

  • index_cp_capacity –

    Maximum context shard, rounded to a complete scoring tile.

  • index_cp_world –

    Use two independent CP4 groups for TP8's single-query medium contexts.

  • index_fan –

    Lists one merge level consumes per list it emits.

  • index_fp8_data_dword –

    Dword offset of FP8 index elements k .. k + 3 of one cache row.

  • index_fp8_scale_dword –

    Dword offset of the fp32 scale of one FP8 index cache row.

  • index_levels –

    Merge levels a build needs: the depth at which one list remains.

  • index_lists –

    Lists the tree holds at level for a build of index_max_seq.

  • index_seg –

    Keys one select task stages in LDS: the leaf size, not a capacity.

  • index_select_capacity –

    Context the LOCAL (merge-tree) selector must serve in this build.

  • index_select_stage –

    Stage name of tree level; the final level keeps index_select.

  • indexer_uses_tiles –

    Use the distributed tiled radix only to shard a context ACROSS RANKS.

  • layout –

    Return byte offsets for per-rank scratch and symmetric peer buffers.

  • paged_row_contract –

    Reference the device contract for one ATOM-layout request row.

  • ptpc_stage_chunk –

    How many (sample, group) cells stage_x_pairs_ptpc stages together.

  • sparse_cache_rows –

    Resolve the cache rows consumed by one flat or paged attention row.

  • sparse_keys_per_task –

    Use narrower sparse tiles when samples or attention heads fill LDS.

  • split_acc_head –

    Map one split-PV MFMA row to its local attention head.

  • split_score_column –

    Locate this wave's head column in a 16x16 MFMA score tile.

  • stage_tasks –

    Return (stage name, task count) pairs in execution order.

  • ug_split –

    Return the balanced up/gate leftover split for batches two and four.

dn_tile(samples, expert_mxfp4=False)

Return rows per expert-down/FFN-reduce task for the tuned schedule.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def dn_tile(samples: int, expert_mxfp4: bool = False) -> int:
    """Return rows per expert-down/FFN-reduce task for the tuned schedule."""
    return 32 if samples == 1 or (samples > 4 and expert_mxfp4) else HIDDEN // BLOCKS

down_prefetch_batch(samples, native_fp4_mfma=False, atom_experts=False)

How many expert-down weight tiles a wave keeps in flight.

run_units issues round r+1's buffer loads before consuming round r's, so this sets the stage's memory-level parallelism. Changing it is bit-identical -- run_units walks the units in index order whatever the batch size, so the MFMA accumulation order does not move.

Measured on the TP4 GLM-5.2 shard, this stage is not latency-starved: sweeping 2..8 at S=6 and S=12 is monotone the wrong way (bigger is slower, presumably register pressure), and 2 is the best of the values tried at both widths.

MONO_DN_BATCH overrides it for an A/B (see tests/models/glm52/kernels/bench_glm52_atom_shape.py --ab-env).

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def down_prefetch_batch(
    samples: int, native_fp4_mfma: bool = False, atom_experts: bool = False
) -> int:
    """How many expert-down weight tiles a wave keeps in flight.

    ``run_units`` issues round r+1's buffer loads before consuming round r's,
    so this sets the stage's memory-level parallelism. Changing it is
    bit-identical -- ``run_units`` walks the units in index order whatever the
    batch size, so the MFMA accumulation order does not move.

    Measured on the TP4 GLM-5.2 shard, this stage is **not** latency-starved:
    sweeping 2..8 at S=6 and S=12 is monotone the *wrong* way (bigger is
    slower, presumably register pressure), and 2 is the best of the values
    tried at both widths.

    ``MONO_DN_BATCH`` overrides it for an A/B (see
    ``tests/models/glm52/kernels/bench_glm52_atom_shape.py --ab-env``).
    """
    override = os.environ.get("MONO_DN_BATCH", "")
    if override:
        return int(override)
    if samples <= 4:
        return 9
    if native_fp4_mfma:
        return 4 if samples <= 6 else 3
    return 8 if atom_experts else 4

index_cp_capacity(index_max_seq, npes)

Maximum context shard, rounded to a complete scoring tile.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_cp_capacity(index_max_seq: int, npes: int) -> int:
    """Maximum context shard, rounded to a complete scoring tile."""
    unit = npes * INDEX_KEYS_PER_TASK
    return (index_max_seq + unit - 1) // unit * INDEX_KEYS_PER_TASK

index_cp_world(npes, samples, index_max_seq)

Use two independent CP4 groups for TP8's single-query medium contexts.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_cp_world(npes: int, samples: int, index_max_seq: int) -> int:
    """Use two independent CP4 groups for TP8's single-query medium contexts."""
    if (
        npes == 8
        and samples == 1
        and INDEX_LOCAL_LDS_CAPACITY < index_max_seq <= 131072
    ):
        return 4
    return npes

index_fan(index_max_seq, topk)

Lists one merge level consumes per list it emits.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_fan(index_max_seq: int, topk: int) -> int:
    """Lists one merge level consumes per list it emits."""
    return index_seg(index_max_seq) // topk

index_fp8_data_dword(page, row, k, page_size)

Dword offset of FP8 index elements k .. k + 3 of one cache row.

vLLM's ROCm DSA indexer page (indexer_k_quant_and_cache_triton for page_size > 1): the page_size x INDEX_DIM E4M3 keys in 16 x 16-byte SHUFFLE tiles [row // 16, k // 16, row % 16, k % 16], then page_size fp32 row scales (INDEX_PAGE_ROW bytes per row). k % 4 == 0, so the four bytes never straddle a tile.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_fp8_data_dword(page, row, k, page_size):
    """Dword offset of FP8 index elements ``k`` .. ``k + 3`` of one cache row.

    vLLM's ROCm DSA indexer page (``indexer_k_quant_and_cache_triton`` for
    ``page_size > 1``): the ``page_size x INDEX_DIM`` E4M3 keys in 16 x 16-byte
    SHUFFLE tiles ``[row // 16, k // 16, row % 16, k % 16]``, then ``page_size``
    fp32 row scales (``INDEX_PAGE_ROW`` bytes per row). ``k % 4 == 0``, so the
    four bytes never straddle a tile.
    """
    tiled = (
        row // INDEX_TILE * (INDEX_TILE * INDEX_DIM)
        + k // INDEX_TILE * (INDEX_TILE * INDEX_TILE)
        + row % INDEX_TILE * INDEX_TILE
        + k % INDEX_TILE
    )
    return page * (page_size * INDEX_PAGE_ROW // 4) + tiled // 4

index_fp8_scale_dword(page, row, page_size)

Dword offset of the fp32 scale of one FP8 index cache row.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_fp8_scale_dword(page, row, page_size):
    """Dword offset of the fp32 scale of one FP8 index cache row."""
    return page * (page_size * INDEX_PAGE_ROW // 4) + page_size * (INDEX_DIM // 4) + row

index_levels(index_max_seq, topk)

Merge levels a build needs: the depth at which one list remains.

index_max_seq <= INDEX_SEG gives 0, i.e. today's single flat select.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_levels(index_max_seq: int, topk: int) -> int:
    """Merge levels a build needs: the depth at which one list remains.

    ``index_max_seq <= INDEX_SEG`` gives 0, i.e. today's single flat select.
    """
    level = 0
    while index_lists(index_max_seq, level, topk) > 1:
        level += 1
    return level

index_lists(index_max_seq, level, topk)

Lists the tree holds at level for a build of index_max_seq.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_lists(index_max_seq: int, level: int, topk: int) -> int:
    """Lists the tree holds at ``level`` for a build of ``index_max_seq``."""
    seg = index_seg(index_max_seq)
    fan = index_fan(index_max_seq, topk)
    n = (index_max_seq + seg - 1) // seg
    for _ in range(level):
        n = (n + fan - 1) // fan
    return n

index_seg(index_max_seq)

Keys one select task stages in LDS: the leaf size, not a capacity.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_seg(index_max_seq: int) -> int:
    """Keys one select task stages in LDS: the leaf size, not a capacity."""
    return min(index_max_seq, INDEX_SEG)

index_select_capacity(index_max_seq, indexer_cp)

Context the LOCAL (merge-tree) selector must serve in this build.

A tiled build keeps the local selector as its short-query fallback, bounded by use_short_index; it reads the peer-exchanged score plane, which is one leaf wide, so its tree is always a bare leaf. Every other build sends the whole context through the tree.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_select_capacity(index_max_seq: int, indexer_cp: bool) -> int:
    """Context the LOCAL (merge-tree) selector must serve in this build.

    A tiled build keeps the local selector as its short-query fallback, bounded
    by ``use_short_index``; it reads the peer-exchanged score plane, which is
    one leaf wide, so its tree is always a bare leaf.  Every other build sends
    the whole context through the tree.
    """
    return (
        index_seg(index_max_seq)
        if indexer_uses_tiles(index_max_seq, indexer_cp)
        else index_max_seq
    )

index_select_stage(level, depth)

Stage name of tree level; the final level keeps index_select.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def index_select_stage(level: int, depth: int) -> str:
    """Stage name of tree ``level``; the final level keeps ``index_select``."""
    return "index_select" if level == depth else f"index_sel{level}"

indexer_uses_tiles(index_max_seq, indexer_cp)

Use the distributed tiled radix only to shard a context ACROSS RANKS.

It used to answer "is this context past what one selector CTA can stage in LDS", because the local selector staged every key of the context. It no longer does -- the selector is a merge tree over fixed INDEX_SEG leaves (index_levels), so one CTA serves any context. Tiles are therefore purely the context-parallel feature now: shard the scorer and the selection over index_cp_world ranks, which only a CP build can do.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def indexer_uses_tiles(index_max_seq: int, indexer_cp: bool) -> bool:
    """Use the distributed tiled radix only to shard a context ACROSS RANKS.

    It used to answer "is this context past what one selector CTA can stage in
    LDS", because the local selector staged every key of the context.  It no
    longer does -- the selector is a merge tree over fixed ``INDEX_SEG`` leaves
    (``index_levels``), so one CTA serves any context.  Tiles are therefore
    purely the context-parallel feature now: shard the scorer and the selection
    over ``index_cp_world`` ranks, which only a CP build can do.
    """
    return indexer_cp and index_max_seq > INDEX_LOCAL_LDS_CAPACITY

layout(samples, heads, npes, sparse_attention_topk, with_indexer=False, index_max_seq=4096, indexer_cp=False, inter=INTER, output_heads=None, dcp_size=1, native_fp4_mfma=False)

Return byte offsets for per-rank scratch and symmetric peer buffers.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def layout(
    samples: int,
    heads: int,
    npes: int,
    sparse_attention_topk: int,
    with_indexer: bool = False,
    index_max_seq: int = 4096,
    indexer_cp: bool = False,
    inter: int = INTER,
    output_heads: int | None = None,
    dcp_size: int = 1,
    native_fp4_mfma: bool = False,
):
    """Return byte offsets for per-rank scratch and symmetric peer buffers."""
    split_count = sparse_attention_topk // sparse_keys_per_task(samples, heads)
    output_heads = heads if output_heads is None else output_heads
    tiled_indexer = with_indexer and indexer_uses_tiles(index_max_seq, indexer_cp)
    index_ranks = index_cp_world(npes, samples, index_max_seq) if indexer_cp else 1
    pair_bytes = 8
    items = [
        ("q_a", samples * Q_LORA * pair_bytes),
        ("q_an", samples * HIDDEN // 2 * pair_bytes),
        ("iq_an", samples * HIDDEN // 2 * pair_bytes),
        ("kv_a", samples * (KV_LORA + PE_DIM) * pair_bytes),
        ("kvnew", samples * KV_LORA * pair_bytes),
        ("penew", samples * PE_DIM * pair_bytes),
        ("q_nope", samples * heads * NOPE_DIM * pair_bytes),
        ("q_pe", samples * heads * PE_DIM * pair_bytes),
        ("q_lat", samples * heads * KV_LORA * pair_bytes),
        ("sp_acc", samples * split_count * heads * KV_LORA * pair_bytes),
        ("sp_m", samples * split_count * heads * pair_bytes),
        ("sp_l", samples * split_count * heads * pair_bytes),
        ("o", samples * output_heads * V_DIM * pair_bytes),
        ("a", samples * HIDDEN * pair_bytes),
        ("scores", samples * N_EXPERTS * pair_bytes),
        ("xq", samples * HIDDEN // 4 * pair_bytes),
        ("xqs", samples * (XQ_GROUPS if native_fp4_mfma else XQ_BLOCKS) * pair_bytes),
        ("sel", samples * MOE_SLOTS * pair_bytes),
        ("prob", samples * MOE_SLOTS * pair_bytes),
        ("mid", samples * MOE_SLOTS * inter * pair_bytes),
        ("ugp", BLOCKS * samples * 2 * UG_TILE * pair_bytes),
        ("xqd", samples * HIDDEN * 4),
    ]
    if with_indexer:
        items += [
            ("index_k", samples * INDEX_DIM * pair_bytes),
            ("index_k_new", samples * INDEX_DIM // 2 * pair_bytes),
            ("index_ready", samples * pair_bytes),
            ("index_w", samples * INDEX_HEADS * pair_bytes),
            ("index_q", samples * INDEX_Q_ROWS // 2 * pair_bytes),
            (
                "index_scores",
                samples
                * (
                    index_cp_capacity(index_max_seq, index_ranks)
                    if indexer_cp
                    else index_max_seq
                )
                * pair_bytes,
            ),
            ("indices", samples * sparse_attention_topk * 4),
            ("indices_ready", samples * pair_bytes),
        ]
        # One region a NON-final selection-tree level: its lists' (score, key
        # index) entries, two tagged pairs each, so one 16-byte store publishes
        # both and one 16-byte poll validates both.  The final level writes
        # ``indices`` instead, so a build of ``index_levels`` = 0 (every context
        # one leaf can serve, and every tiled build) adds nothing at all.
        select_capacity = index_select_capacity(index_max_seq, indexer_cp)
        for level in range(index_levels(select_capacity, sparse_attention_topk)):
            items += [
                (
                    f"isel{level}",
                    samples
                    * index_lists(select_capacity, level, sparse_attention_topk)
                    * sparse_attention_topk
                    * 2
                    * pair_bytes,
                )
            ]
        if tiled_indexer:
            parts = index_cp_partitions(index_max_seq, index_ranks)
            items += [
                (
                    "index_cp_hist",
                    INDEX_RADIX_DIGITS
                    * samples
                    * parts
                    * INDEX_RADIX_BINS
                    * pair_bytes,
                ),
                ("index_cp_counts", samples * parts * 2 * pair_bytes),
                ("index_cp_offsets", samples * parts * 2 * pair_bytes),
            ]

    offset, scratch = 0, {}
    for name, size in items:
        scratch[name] = offset
        offset += _align(size)
    scratch["_bytes"] = offset

    part = npes * samples * HIDDEN * pair_bytes
    region = 2 * part
    dcp_part = (
        dcp_size * samples * (heads * V_DIM // UV_TILE) * DCP_SUMMARY_PAIRS * pair_bytes
        if dcp_size > 1
        else 0
    )
    symmetric = {
        "attn": 0,
        "ffn": region,
        "dcp": 2 * region,
        "_part_stride": part,
        "_dcp_part_stride": dcp_part,
        "_bytes": 2 * region + 2 * dcp_part,
    }
    if tiled_indexer or (with_indexer and indexer_cp):
        # Two launch slots, like the attention/FFN peer buffers. Distinct radix
        # rounds must not overwrite a histogram or threshold still being read.
        offset = symmetric["_bytes"]
        cp_items = (
            [
                (
                    "index_cp_hist",
                    index_ranks
                    * INDEX_RADIX_DIGITS
                    * samples
                    * INDEX_RADIX_BINS
                    * pair_bytes,
                ),
                ("index_cp_threshold", INDEX_RADIX_DIGITS * samples * 2 * pair_bytes),
                ("index_cp_counts", index_ranks * samples * 2 * pair_bytes),
                ("index_cp_offsets", samples * 2 * pair_bytes),
                ("index_cp_indices", samples * sparse_attention_topk * pair_bytes),
            ]
            if tiled_indexer
            else []
        )
        if indexer_cp:
            cp_items += [
                (
                    "index_cp_scores",
                    samples * min(index_max_seq, INDEX_LOCAL_LDS_CAPACITY) * pair_bytes,
                )
            ]
        if indexer_cp and not tiled_indexer and npes > 1:
            cp_items += [("index_cp_q", samples * INDEX_Q_ROWS // 2 * pair_bytes)]
        for name, size in cp_items:
            symmetric[name] = offset
            symmetric[name + "_stride"] = _align(size)
            offset += 2 * _align(size)
        symmetric["_bytes"] = offset
    return scratch, symmetric

paged_row_contract(sparse_kv_indices, sparse_kv_indptr, sample, slot_mapping=None)

Reference the device contract for one ATOM-layout request row.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def paged_row_contract(
    sparse_kv_indices, sparse_kv_indptr, sample: int, slot_mapping=None
):
    """Reference the device contract for one ATOM-layout request row."""
    start, end = sparse_kv_indptr[sample : sample + 2]
    active = end > start
    rows = sparse_kv_indices[start:end] if active else ()
    slot_owned = slot_mapping is None or slot_mapping[sample] >= 0
    return {
        "active": active,
        "context": end - start,
        "index_base": start if active else 0,
        "safe_row": rows[0] if active else 0,
        "write_cache": active if slot_mapping is None else slot_owned,
    }

ptpc_stage_chunk(samples)

How many (sample, group) cells stage_x_pairs_ptpc stages together.

The helper's two per-cell costs are per-call costs: poll resolves a whole batch in one round trip and block_maxs reduces a whole list in two barriers. Batching cells is bit-identical and removes a clean O(S) term from q_b, uk and o -- stages whose task count and weight bytes do not depend on S at all.

Measured on the TP4 GLM-5.2 shard (bench_glm52_atom_shape --ab-env MONO_PTPC_CHUNK=..., 7 trials, interleaved, spread <= 0.27%):

========== =============== ================ chunk S=6 us/launch S=12 us/launch ========== =============== ================ 1 (old) 113.785 201.790 2 112.507 196.527 4 113.238 194.113 6 116.048 194.134 all cells 116.012 214.911 ========== =============== ================

So the optimum moves with the width, and batching every cell is much worse than batching four -- it holds every cell's values live across one reduction and spills. MONO_PTPC_CHUNK overrides this for an A/B; 1 restores the per-cell walk exactly.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def ptpc_stage_chunk(samples: int) -> int:
    """How many (sample, group) cells ``stage_x_pairs_ptpc`` stages together.

    The helper's two per-cell costs are per-*call* costs: ``poll`` resolves a
    whole batch in one round trip and ``block_maxs`` reduces a whole list in
    two barriers.  Batching cells is bit-identical and removes a clean O(S)
    term from ``q_b``, ``uk`` and ``o`` -- stages whose task count and weight
    bytes do not depend on ``S`` at all.

    Measured on the TP4 GLM-5.2 shard (``bench_glm52_atom_shape --ab-env
    MONO_PTPC_CHUNK=...``, 7 trials, interleaved, spread <= 0.27%):

    ==========  ===============  ================
    chunk       S=6 us/launch    S=12 us/launch
    ==========  ===============  ================
    1 (old)     113.785          201.790
    **2**       **112.507**      196.527
    **4**       113.238          **194.113**
    6           116.048          194.134
    all cells   116.012          214.911
    ==========  ===============  ================

    So the optimum moves with the width, and batching *every* cell is much
    worse than batching four -- it holds every cell's values live across one
    reduction and spills.  ``MONO_PTPC_CHUNK`` overrides this for an A/B;
    ``1`` restores the per-cell walk exactly.
    """
    override = os.environ.get("MONO_PTPC_CHUNK", "")
    if override:
        return int(override)
    return 2 if samples <= 6 else 4

sparse_cache_rows(sparse_kv_indices, *, sample, topk, cur_pos=0, sparse_kv_indptr=None)

Resolve the cache rows consumed by one flat or paged attention row.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def sparse_cache_rows(
    sparse_kv_indices,
    *,
    sample: int,
    topk: int,
    cur_pos: int = 0,
    sparse_kv_indptr=None,
):
    """Resolve the cache rows consumed by one flat or paged attention row."""
    if sparse_kv_indptr is not None:
        start, end = sparse_kv_indptr[sample : sample + 2]
        return sparse_kv_indices[start:end]
    context = cur_pos + sample + 1
    count = min(context, topk)
    if context <= topk:
        return range(count)
    start = sample * topk
    return sparse_kv_indices[start : start + count]

sparse_keys_per_task(samples, heads=WAVES)

Use narrower sparse tiles when samples or attention heads fill LDS.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def sparse_keys_per_task(samples: int, heads: int = WAVES) -> int:
    """Use narrower sparse tiles when samples or attention heads fill LDS."""
    return 32 if heads > 2 * WAVES or (heads == WAVES and samples > 4) else 64

split_acc_head(head_group, lane_group, element)

Map one split-PV MFMA row to its local attention head.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def split_acc_head(head_group, lane_group: int, element: int):
    """Map one split-PV MFMA row to its local attention head."""
    return head_group * WAVES + lane_group * 4 + element

split_score_column(wave, lane)

Locate this wave's head column in a 16x16 MFMA score tile.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def split_score_column(wave: int, lane: int):
    """Locate this wave's head column in a 16x16 MFMA score tile."""
    return wave + 16 * ((lane % 16) // 4)

stage_tasks(samples, heads, sparse_attention_topk, with_indexer=False, index_max_seq=4096, expert_mxfp4=False, inter=INTER, indexer_cp=False, npes=1, split_head_merge=False)

Return (stage name, task count) pairs in execution order.

split_head_merge folds the two head groups of an (sample, key-chunk) cell into one task, halving split. It must be given the same value the kernel was built with: these counts set the CTA placement rotation and the timeline's per-stage offsets, so a disagreement silently mis-seats both.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def stage_tasks(
    samples: int,
    heads: int,
    sparse_attention_topk: int,
    with_indexer: bool = False,
    index_max_seq: int = 4096,
    expert_mxfp4: bool = False,
    inter: int = INTER,
    indexer_cp: bool = False,
    npes: int = 1,
    split_head_merge: bool = False,
):
    """Return ``(stage name, task count)`` pairs in execution order.

    ``split_head_merge`` folds the two head groups of an (sample, key-chunk)
    cell into one task, halving ``split``. It must be given the same value the
    kernel was built with: these counts set the CTA placement rotation and the
    timeline's per-stage offsets, so a disagreement silently mis-seats both.
    """
    index_ranks = index_cp_world(npes, samples, index_max_seq) if indexer_cp else 1
    tasks = [
        ("qkv_a", N_QKV_A),
        ("q_norm", samples),
        ("cache", 1),
        ("q_b", heads * (NOPE_DIM + Q_PE_DIM) // Q_B_TILE),
    ]
    if with_indexer:
        shard_q = indexer_cp and not indexer_uses_tiles(index_max_seq, indexer_cp)
        tasks += [
            ("index_q", INDEX_Q_ROWS // INDEX_TILE // (index_ranks if shard_q else 1))
        ]
    tasks += [("uk", heads * KV_LORA // UK_TILE)]
    if with_indexer:
        capacity = (
            index_cp_capacity(index_max_seq, index_ranks)
            if indexer_cp
            else index_max_seq
        )
        tasks += [
            (
                "index_score",
                samples * ((capacity + INDEX_KEYS_PER_TASK - 1) // INDEX_KEYS_PER_TASK),
            )
        ]
        if indexer_uses_tiles(index_max_seq, indexer_cp):
            parts = index_cp_partitions(index_max_seq, index_ranks)
            for digit in range(INDEX_RADIX_DIGITS):
                tasks += [
                    (f"index_hist_{digit}", samples * parts),
                    (f"index_prefix_{digit}", samples),
                ]
            tasks += [
                ("index_count", samples * parts),
                ("index_offsets", samples),
                ("index_emit", samples * parts),
            ]
        # One stage a selection-tree level; the last is named ``index_select``
        # so the timeline, the CTA rotation base and every reader of this table
        # keep the name they had when the tree was a single flat select.  A
        # tiled build is depth 0, so its table is unchanged.
        select_capacity = index_select_capacity(index_max_seq, indexer_cp)
        depth = index_levels(select_capacity, sparse_attention_topk)
        tasks += [
            (
                index_select_stage(level, depth),
                samples * index_lists(select_capacity, level, sparse_attention_topk),
            )
            for level in range(depth + 1)
        ]
    tasks += [
        (
            "split",
            samples
            * (1 if split_head_merge else heads // WAVES)
            * (sparse_attention_topk // sparse_keys_per_task(samples, heads)),
        ),
        ("uv", samples * (heads * V_DIM // UV_TILE)),
        ("o", N_ROW_TILES),
        ("router", samples * N_ROUTER),
        # one 8-row column tile of one routed slot per task (the per-sample loop
        # is inside the task); == inter for GLM's top-8
        ("ug", TOP_K * (inter // 8)),
        ("down", HIDDEN // dn_tile(samples, expert_mxfp4)),
    ]
    return tasks

ug_split(samples, inter=INTER)

Return the balanced up/gate leftover split for batches two and four.

Source code in vllm/models/mistral/mistral_large4/amd/specialized_decode/mono/layout.py
def ug_split(samples: int, inter: int = INTER):
    """Return the balanced up/gate leftover split for batches two and four."""
    full_tiles, remainder = divmod((samples * TOP_K + 1) * (inter // UG_TILE), BLOCKS)
    if samples not in (2, 4) or remainder == 0 or BLOCKS % remainder:
        return None
    segments = BLOCKS // remainder
    if (HIDDEN // 128) % segments or (HIDDEN // 128) // segments > WAVES // 2:
        return None
    return full_tiles, segments