vllm.models.hy_v4.nvidia.hc ¶
iHC (independent Hyper-Connections) layers for HY V4 (NVIDIA).
iHC replaces the single residual stream of a standard transformer with hc_mult parallel residual channels. Each decoder sub-block reduces the channels to one hidden state (HYV4HCPreLayer), runs the sub-block, then scatters the result back over the channels (HYV4HCPostLayer). The final HYV4HCHeadLayer merges the channels before the model's output norm.
NOTE: Each of the three steps has an optional single-kernel HPC replacement (HpcIHCPre / HpcIHCPost / HpcIHCHead). They are only constructed when the hpc package is installed, VLLM_ENABLE_HPC_OPS=1 and the shape / device constraints hold; otherwise the eager path below runs unchanged. TODO: port the cross-layer post+pre fusion (HpcIHCPostPre) as well; it requires restructuring the decoder-layer forward scheduling.
Classes:
-
HYV4HCHeadLayer–iHC head layer (2D-activation adaptation).
-
HYV4HCLayer–Wrapper owning one iHC boundary (pre + post) of a decoder sub-block.
-
HYV4HCPostLayer–iHC post-processing layer (2D-activation adaptation).
-
HYV4HCPreLayer–iHC pre-processing layer (2D-activation adaptation).
HYV4HCHeadLayer ¶
Bases: Module
iHC head layer (2D-activation adaptation).
Merges the iHC channels back into a single hidden state before the final layer norm, using an RMS-normed projection plus sigmoid-gated reduction.
Methods:
-
forward–Merge the iHC channels into a single hidden state.
-
reset_parameters–Initialize the head gate scale and per-channel gate bias.
Source code in vllm/models/hy_v4/nvidia/hc.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
forward(x) ¶
Merge the iHC channels into a single hidden state.
Parameters:
Returns:
-
Tensor–The merged hidden state
[num_tokens, d].
Source code in vllm/models/hy_v4/nvidia/hc.py
reset_parameters(init_std=0.006, base_noise_std=0.0) ¶
Initialize the head gate scale and per-channel gate bias.
Source code in vllm/models/hy_v4/nvidia/hc.py
HYV4HCLayer ¶
Bases: Module
Wrapper owning one iHC boundary (pre + post) of a decoder sub-block.
Methods:
-
post–Apply post-gating and add the residual.
-
pre–Reduce the iHC channels and produce the post gates.
-
prepare_input–Normalize the sub-block input to 3D when iHC is enabled.
Source code in vllm/models/hy_v4/nvidia/hc.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
_prepare_input_to_3d(hidden_states) ¶
Reshape the iHC input to [num_tokens, hc, h].
Accepted inputs are [num_tokens, hc, h] (no-op), [num_tokens, h] (broadcast over the channels) and [num_tokens, hc * h] (reshape).
Source code in vllm/models/hy_v4/nvidia/hc.py
post(output_with_bias, residual, post_gates) ¶
Apply post-gating and add the residual.
Source code in vllm/models/hy_v4/nvidia/hc.py
pre(hidden_states) ¶
Reduce the iHC channels and produce the post gates.
Returns:
-
Tensor–A tuple of the reduced hidden states
[num_tokens, d], the post -
Tensor | None–gates
[num_tokens, hc](Nonewhen iHC is disabled) and the -
Tensor–residual (the untouched input).
Source code in vllm/models/hy_v4/nvidia/hc.py
prepare_input(hidden_states) ¶
Normalize the sub-block input to 3D when iHC is enabled.
HYV4HCPostLayer ¶
Bases: Module
iHC post-processing layer (2D-activation adaptation).
Applies post-gating to the sub-block output and adds the multi-channel residual (no comb mixing)::
y[n, i, d] = post[n, i] * x[n, d] + residual[n, i, d]
Methods:
-
forward–Scatter the sub-block output back onto the iHC channels.
Source code in vllm/models/hy_v4/nvidia/hc.py
forward(x, residual, post) ¶
Scatter the sub-block output back onto the iHC channels.
Parameters:
-
(x¶Tensor) –Attention/MLP output of shape
[num_tokens, d]. -
(residual¶Tensor) –Multi-channel residual
[num_tokens, hc, d]. -
(post¶Tensor) –Post gates
[num_tokens, hc]fromHYV4HCPreLayer.
Returns:
-
Tensor–The updated residual channels
[num_tokens, hc, d].
Source code in vllm/models/hy_v4/nvidia/hc.py
HYV4HCPreLayer ¶
Bases: Module
iHC pre-processing layer (2D-activation adaptation).
Steps
- RMS-normalize the flattened
[num_tokens, hc * d]input. - Project to the pre/post gating logits.
- Turn the logits into sigmoid gates.
- Reduce over the channel dim with the pre gates.
Methods:
-
forward–Reduce the iHC channels and emit the post gates.
-
reset_parameters–Initialize the gate scale and per-channel gate bias.
Source code in vllm/models/hy_v4/nvidia/hc.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
forward(x) ¶
Reduce the iHC channels and emit the post gates.
Parameters:
Returns:
-
Tensor–A tuple of the pre-gated reduction
[num_tokens, d]and the post -
Tensor–gates
[num_tokens, hc]consumed byHYV4HCPostLayer.
Source code in vllm/models/hy_v4/nvidia/hc.py
reset_parameters(init_std, base_noise_std=0.0) ¶
Initialize the gate scale and per-channel gate bias.