flashinfer.mhc.mhc_post¶
- flashinfer.mhc.mhc_post(x: Tensor, residual: Tensor, post_layer_mix: Tensor, comb_res_mix: Tensor) Tensor¶
Apply mHC post mapping for HC=4.
out[..., new_hc, h] = x[..., h] * post_layer_mix[..., new_hc] + sum_old residual[..., old_hc, h] * comb_res_mix[..., old_hc, new_hc]- Parameters:
x (torch.Tensor) – Layer output tensor, shape
[..., H](matchesresidual’s outer dimensions andH = residual.shape[-1]).residual (torch.Tensor) – Multi-head residual tensor, shape
[..., HC=4, H]. TheHC=4axis must equal 4 (mHC is currently hard-wired to 4 sub-heads).post_layer_mix (torch.Tensor) – Layer-output mixing weights, shape
[..., HC=4]or[..., HC=4, 1](both accepted). Provides the per-new-head coefficient applied tox(thepost_layer_mixfactor in the formula above). See mHC paper / reference implementation for the exact training-time derivation.comb_res_mix (torch.Tensor) – Residual combination matrix, shape
[..., HC=4, HC=4]. Each[old_hc, new_hc]entry is the coefficient mixingresidual[..., old_hc, :]into the new headnew_hc(thecomb_res_mixfactor above). See mHC paper / reference implementation for the training-time derivation.
- Returns:
Output tensor with the same shape as
residual([..., HC=4, H]).- Return type:
torch.Tensor