Skip to content

vllm.model_executor.kernels.mhc.tilelang

Functions:

_mhc_fused_post_pre_tilelang_impl(x, residual, post_layer_mix, comb_res_mix, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, n_splits=1, tile_n=1, norm_weight=None, norm_eps=1e-06, reuse_residual=False)

Run one MHC post block followed by the next MHC pre block.

When norm_weight is provided, the layer_input_cur output is the RMSNorm'd activation (fused into the kernel); otherwise it is the raw pre-norm activation as before.

n_splits and tile_n are retained for the shared MHC operator API. The TileLang path selects both values internally from the runtime shape.

With reuse_residual, the unfused path writes residual_cur into residual's storage instead of allocating a new buffer. The post kernel reads every hc row of a hidden block before writing that block, so the in-place update is exact.

Returns:

  • residual_cur ( Tensor ) –

    post-mapped residual, shape (..., hc_mult, hidden_size)

  • post_mix_cur ( Tensor ) –

    shape (..., hc_mult, 1)

  • comb_mix_cur ( Tensor ) –

    shape (..., hc_mult, hc_mult)

  • layer_input_cur ( Tensor ) –

    shape (..., hidden_size)

hc_head_fused_kernel_tilelang(hs_flat, fn, hc_scale, hc_base, rms_eps, hc_eps)

Apply the fused hc_head kernel and return the (T, H) bf16 result.

mhc_fused_post_pre_delayed_tilelang(x, residual, post_layer_mix, comb_res_mix, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, pre_mix=None, norm_weight=None, norm_eps=1e-06, capture_aux=False)

Run one mHC post block followed by the next delayed mHC pre block.

Within the fused kernel's token range the post mapping is folded into the pre-norm GEMM, so the updated residual streams feed the projection from registers instead of a second pass over global memory. Above it this runs the same post kernel and split-k GEMM as the unfused pair.

Parameters:

  • x

    (Tensor) –

    BF16 sublayer output of shape (tokens, hidden_size).

  • residual

    (Tensor) –

    BF16 residual streams of shape (tokens, hc_mult, hidden_size).

  • post_layer_mix

    (Tensor) –

    FP32 post coefficients of shape (tokens, hc_mult, 1).

  • comb_res_mix

    (Tensor) –

    FP32 residual coefficients, (tokens, hc_mult, hc_mult).

  • fn

    (Tensor) –

    FP32 projection of shape (hc_mult * (hc_mult + 2), input_size).

  • hc_scale

    (Tensor) –

    FP32 scales of shape (3,).

  • hc_base

    (Tensor) –

    FP32 bias of shape (hc_mult * (hc_mult + 2),).

  • rms_eps

    (float) –

    RMS normalization epsilon.

  • hc_pre_eps

    (float) –

    Pre-mix epsilon.

  • hc_sinkhorn_eps

    (float) –

    Sinkhorn epsilon.

  • hc_post_mult_value

    (float) –

    Post-mix multiplier.

  • sinkhorn_repeat

    (int) –

    Number of Sinkhorn iterations.

  • pre_mix

    (Tensor | None, default: None ) –

    FP32 coefficients from the previous sublayer, or None to select residual stream zero.

  • norm_weight

    (Tensor | None, default: None ) –

    Optional BF16 RMSNorm weight for the collapsed input.

  • norm_eps

    (float, default: 1e-06 ) –

    RMSNorm epsilon for the collapsed input.

  • capture_aux

    (bool, default: False ) –

    Also return the mean over the post-mapped streams, which draft models consume as the target's hidden state. It is folded into the collapse, which already reads those streams.

Returns:

  • Tensor –

    The post-mapped residual streams, the post and residual coefficients,

  • Tensor –

    the optionally normalized BF16 layer input, the next FP32 pre-mix, and

  • Tensor –

    the BF16 stream mean (empty unless capture_aux), with shapes

  • Tensor –

    (tokens, hc_mult, hidden_size), (tokens, hc_mult, 1),

  • Tensor –

    (tokens, hc_mult, hc_mult), (tokens, hidden_size), (tokens, hc_mult),

  • Tensor –

    and (tokens, hidden_size).

mhc_fused_post_pre_tilelang(x, residual, post_layer_mix, comb_res_mix, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, n_splits=1, tile_n=1, norm_weight=None, norm_eps=1e-06)

See _mhc_fused_post_pre_tilelang_impl. Never writes to its inputs.

mhc_fused_post_pre_tilelang_reuse_residual(x, residual, post_layer_mix, comb_res_mix, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, n_splits=1, tile_n=1, norm_weight=None, norm_eps=1e-06)

Like mhc_fused_post_pre_tilelang but may overwrite residual.

Not a registered custom op. Only for eager callers that own residual and do not read it after this call.

mhc_pre_broadcast_tilelang(residual, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, n_splits=1, norm_weight=None, norm_eps=1e-06, fn_broadcast=None)

First-layer mHC pre for a residual broadcast from (T, H).

mhc_pre_delayed_tilelang(residual, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, pre_mix=None, x=None, norm_weight=None, norm_eps=1e-06)

Run mHC pre with a carried pre-mix and return the next pre-mix.

Parameters:

  • residual

    (Tensor) –

    BF16 residual streams of shape (tokens, hc_mult, hidden_size).

  • fn

    (Tensor) –

    FP32 projection of shape (hc_mult * (hc_mult + 2), input_size).

  • hc_scale

    (Tensor) –

    FP32 scales of shape (3,).

  • hc_base

    (Tensor) –

    FP32 bias of shape (hc_mult * (hc_mult + 2),).

  • rms_eps

    (float) –

    RMS normalization epsilon.

  • hc_pre_eps

    (float) –

    Pre-mix epsilon.

  • hc_sinkhorn_eps

    (float) –

    Sinkhorn epsilon.

  • hc_post_mult_value

    (float) –

    Post-mix multiplier.

  • sinkhorn_repeat

    (int) –

    Number of Sinkhorn iterations.

  • pre_mix

    (Tensor | None, default: None ) –

    FP32 coefficients from the previous sublayer, or None to select residual stream zero at model entry.

  • x

    (Tensor | None, default: None ) –

    Optional BF16 projection input of shape (tokens, input_size), for the first layer's broadcast embedding and summed projection.

  • norm_weight

    (Tensor | None, default: None ) –

    Optional BF16 RMSNorm weight for the collapsed input.

  • norm_eps

    (float, default: 1e-06 ) –

    RMSNorm epsilon for the collapsed input.

Returns:

  • Tensor –

    Post and residual coefficients, optionally normalized BF16 layer input,

  • Tensor –

    and the next FP32 pre-mix, with shapes (tokens, hc_mult, 1),

  • Tensor –

    (tokens, hc_mult, hc_mult), (tokens, hidden_size), and (tokens, hc_mult).

mhc_pre_tilelang(residual, fn, hc_scale, hc_base, rms_eps, hc_pre_eps, hc_sinkhorn_eps, hc_post_mult_value, sinkhorn_repeat, n_splits=1, norm_weight=None, norm_eps=1e-06)

Forward pass for mHC pre block.

Parameters:

  • residual

    (Tensor) –

    shape (..., hc_mult, hidden_size), dtype torch.bfloat16

  • fn

    (Tensor) –

    shape (hc_mult3, hc_mult * hidden_size), dtype torch.float32

  • hc_scale

    (Tensor) –

    shape (3,), dtype torch.float32

  • hc_base

    (Tensor) –

    shape (hc_mult3,), dtype torch.float32

  • rms_eps

    (float) –

    RMS normalization epsilon

  • hc_pre_eps

    (float) –

    pre-mix epsilon

  • hc_sinkhorn_eps

    (float) –

    sinkhorn epsilon

  • hc_post_mult_value

    (float) –

    post-mix multiplier value

  • sinkhorn_repeat

    (int) –

    number of sinkhorn iterations

  • n_splits

    (int, default: 1 ) –

    retained for the shared MHC operator API; the active GEMM backend selects its split factor internally.

  • norm_weight

    (Tensor | None, default: None ) –

    optional RMSNorm weight, shape (hidden_size,), dtype torch.bfloat16. When provided, RMSNorm is fused into the layer_input write path of the big_fuse kernel.

  • norm_eps

    (float, default: 1e-06 ) –

    epsilon for the fused RMSNorm; only consulted when norm_weight is given.

Returns:

  • post_mix ( Tensor ) –

    shape (..., hc_mult), dtype torch.float32

  • comb_mix ( Tensor ) –

    shape (..., hc_mult, hc_mult), dtype torch.float32

  • layer_input ( Tensor ) –

    shape (..., hidden_size), dtype torch.bfloat16