flashinfer.mhc.mhc_pre_big_fuse_with_prenorm¶
- flashinfer.mhc.mhc_pre_big_fuse_with_prenorm(dot_mix: Tensor, residual: Tensor, mhc_scale: Tensor, mhc_base: Tensor, rms_eps: float = 1e-06, mhc_pre_eps: float = 1e-06, mhc_sinkhorn_eps: float = 1e-06, mhc_post_mult_value: float = 1.0, sinkhorn_repeat: int = 20, block_size: int = 0) tuple[Tensor, Tensor, Tensor]¶
Apply mHC pre-map big-fuse and compute RMS sqrsum from
residual.This matches the Agentic
mhc_pre_finalizeboundary when no precomputedsqrsumis supplied.dot_mixmay be shaped[..., 24]or[1, ..., 24].- Parameters:
dot_mix (torch.Tensor) – Raw projection logits, shape
[..., 24]or[1, ..., 24]. The trailing24 = 4 (pre) + 4 (post) + 16 (comb)slots are partitioned and re-shaped to per-head factors inside the kernel. See mHC paper / reference implementation for the projection derivation.residual (torch.Tensor) – Multi-head residual tensor, shape
[..., HC=4, H](bfloat16).sqrsumis computed from this tensor inside the kernel; same layout asmhc_post()’sresidual.mhc_scale (torch.Tensor) – mHC scaling tensor consumed by the Sinkhorn / mix step. Shape and dtype are implementation-defined; see mHC paper / reference implementation for the exact semantics.
mhc_base (torch.Tensor) – mHC bias / base tensor consumed by the Sinkhorn / mix step. Shape and dtype are implementation-defined; see mHC paper / reference implementation for the exact semantics.
rms_eps (float) – RMSNorm epsilon for numerical stability. Default
1e-6. Must be strictly positive.mhc_pre_eps (float) – Numerical-stability epsilon used in the mHC pre-map step. Default
1e-6. Must be strictly positive.mhc_sinkhorn_eps (float) – Numerical-stability epsilon used in the Sinkhorn iteration step. Default
1e-6. Must be strictly positive.mhc_post_mult_value (float) – Post-mix multiplicative factor applied to the mHC post outputs. Default
1.0.sinkhorn_repeat (int) – Number of Sinkhorn iterations. Default
20.block_size (int) – CUDA block-size hint forwarded to the kernel (
0selects the kernel’s default). Default0.
- Returns:
(post_mix, comb_mix, layer_input)tensors with shapes[..., HC=4, 1],[..., HC=4, HC=4]and[..., H]respectively. See mHC paper / reference implementation for how downstream layers consume them.- Return type:
Tuple[torch.Tensor, torch.Tensor, torch.Tensor]