vllm.models.qwen4_exp.common.hyperconnection ¶
HyperConnection (Gated Residual) utilities.
Implements the HyperConnection residual scheme proposed in "HyperConnections" (https://arxiv.org/abs/2409.19606).
The two concrete variants are
HyperConnectionBase- simple average pooling across hc_count parallel streams (equivalent to hyperconnection_average).GatedResidual- learnable low-rank gated mixing and injection (gated_residual).
Hidden states between layers have shape [..., HC*HS] with HS inner (HC outer, HS inner — checkpoint-native layout). The local torch implementation consumes the hyper input viewed as [..., HC, HS].
Typical usage inside a transformer decoder layer::
self.attn_hc = GatedResidual(hc_config, role="attn")
self.mlp_hc = GatedResidual(hc_config, role="mlp")
hidden_states, residual = self.attn_hc.mix(hidden_states)
hidden_states = attention(hidden_states)
hidden_states = self.attn_hc.combine(hidden_states, residual)
hidden_states, residual = self.mlp_hc.mix(hidden_states)
hidden_states = mlp(hidden_states)
hidden_states = self.mlp_hc.combine(hidden_states, residual)
Classes:
-
GatedResidual–Gated HyperConnection with learnable low-rank mixing and injection.
-
HyperConnectionBase–Average-pooling HyperConnection (
hyperconnection_average). -
HyperConnectionConfig–Configuration shared by all HyperConnection variants.
GatedResidual ¶
Bases: HyperConnectionBase
Gated HyperConnection with learnable low-rank mixing and injection.
mix() applies GemmaRMSNorm per HC stream and projects through a low-rank sigmoid gate to produce a single block input. combine() injects the block output back into each stream through a learned per-stream injection weight.
This implementation uses only PyTorch operators. Tensor-parallel collectives are supplied by its caller.
Methods:
-
mix–Mix: RMSNorm -> low-rank gate -> gated mean.
Source code in vllm/models/qwen4_exp/common/hyperconnection.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 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 | |
mix(hyper_input) ¶
Mix: RMSNorm -> low-rank gate -> gated mean.
Source code in vllm/models/qwen4_exp/common/hyperconnection.py
HyperConnectionBase ¶
Bases: Module
Average-pooling HyperConnection (hyperconnection_average).
Splits the incoming [..., HC*HS] tensor (HC outer, HS inner) into HC parallel streams, averages them for the block input, and broadcasts the block output back to every stream.
Methods:
-
combine–Broadcast the block output back to every stream.
-
mix–Average the HC streams into a single block input.
Source code in vllm/models/qwen4_exp/common/hyperconnection.py
combine(block_output, residual) ¶
Broadcast the block output back to every stream.
Source code in vllm/models/qwen4_exp/common/hyperconnection.py
mix(hyper_input) ¶
Average the HC streams into a single block input.
Source code in vllm/models/qwen4_exp/common/hyperconnection.py
HyperConnectionConfig dataclass ¶
Configuration shared by all HyperConnection variants.