vllm.model_executor.layers.hpc.hpc_ihc
¶
HPC fused iHC (independent Hyper-Connections) kernels for HY V4.
Replaces the eager HYV4HCPreLayer / HYV4HCPostLayer / HYV4HCHeadLayer bodies with single-kernel HPC implementations:
pre : rms square sum + w projection + sigmoid gates + hc-dim weighted sum post : y[n, i, :] = H_post[n, i] * x[n, :] + residual[n, i, :] head : same as pre but hc_mult projection rows and no H_post output
The eager path issues 20 / 5 / 15 kernels for pre / post / head; each HPC op is a single kernel.
Constraints
- Requires VLLM_ENABLE_HPC_OPS=1
- Requires the hpc package (.so) built for the current arch
- Only sm100 / sm103 (compute capability 100, 103)
- Only hc_mult == 4 and hidden_size in {4096, 6144}
- x / residual must be bfloat16; hc_fn weights stay float32 (the checkpoint keeps them out of fp8 quantization via modules_to_not_convert)
The fused modules own no parameters: their forwards read the weights of the eager layer they replace directly via the captured owner reference.
NOTE: The reference implementation also offers a cross-layer post+pre fusion
(HpcIHCPostPre) that folds one segment's post into the next segment's pre.
It requires reworking the decoder-layer forward scheduling and is not ported
here. TODO: add it once the decoder dataflow is restructured for it.
Classes:
-
HpcIHCHead–Fused iHC head block: merge the hc channels back into one hidden state.
-
HpcIHCPost–Fused iHC post block: H_post gating plus multi-channel residual add.
-
HpcIHCPre–Fused iHC pre block.
HpcIHCHead
¶
Bases: HpcModule
Fused iHC head block: merge the hc channels back into one hidden state.
Same structure as HpcIHCPre but the projection emits only hc_mult gate logits and there is no H_post output. Called once per forward, after the last decoder layer.
HpcIHCPost
¶
Bases: HpcModule
Fused iHC post block: H_post gating plus multi-channel residual add.
Unlike mHC there is no comb matrix, so each output channel only needs its own residual channel and the whole thing is one fused multiply-add per element.
HpcIHCPre
¶
Bases: HpcModule
Fused iHC pre block.
Computes, in one kernel: x_flat = x.flatten(1) r = rsqrt(x_flat.square().mean(-1) + rms_norm_eps) mixes = (x_flat @ w.T) * r H_pre = sigmoid(mixes[:, :hc] * hc_scale[0] + hc_base[:hc]) + hc_eps H_post = magnitude * sigmoid( mixes[:, hc:] * hc_scale[1] + hc_base[hc:]) + hc_eps y = sum_i H_pre[:, i] * x[:, i, :]
Parameters:
-
(hc_mult¶int) –HC expand ratio.
-
(hidden_size¶int) –Model hidden dimension.
-
(magnitude¶float) –H_post multiplier (config.hc_magnitude).
-
(hc_eps¶float) –Epsilon added to both gates (config.hc_eps).
-
(norm_eps¶float) –Epsilon inside the rsqrt (config.rms_norm_eps).
-
(fallback_op¶Module) –The eager HYV4HCPreLayer to source weights from.
-
(norm_owner¶Module | None, default:None) –Optional RMSNorm that immediately follows this pre block. When given, its weight/eps are folded into the kernel so a single launch covers pre + RMSNorm (the caller then skips the separate layernorm). None keeps the original pre-only behaviour.
_ihc_supported(hc_mult, hidden_size)
¶
Shared gate for all three iHC ops.