Read-out weights

Mix projection

×

Project the flattened streams to 4 numbers and divide by the streams’ root mean square.

m=xfWmix⊤mean⁡((xf)2)+ε{\htmlData{light=mixes project}{m}}=\frac{{\htmlData{light=flat flatten}{x^{f}}}W_{\mathrm{mix}}^{\top}}{\sqrt{\operatorname{mean}\big(({\htmlData{light=flat flatten}{x^{f}}})^{2}\big)+\varepsilon}}
in
xfx^{f} [B batch, T positions, 16384 streams × d]
out
mm [B batch, T positions, 4 mix numbers]

One statistic per position over all 16,384 features, with ε = 0.000001; computed in float32.

Parameters65,536

65,536 parameters owned by this component

ComponentCalculationParameters
weights, no bias16,384 × 465,536
Sources

In codeF.linear(x, hc_fn) * rsqrt · 732

Open pinned code ↗

Direct evidence

hc_pre: flatten the streams, project them to the mix numbers divided by their root mean square, split them by Sinkhorn, and read the streams with the reading weights; hc_post: each new stream is the writing weight times the sublayer’s output plus the streams combined by a column of the combination.

model.py 673–686 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6

Excerpt
    def hc_pre(self, x: torch.Tensor, hc_fn: torch.Tensor, hc_scale: torch.Tensor, hc_base: torch.Tensor):
        # x: [b,s,hc,d], hc_fn: [mix_hc,hc*d], hc_scale: [3], hc_base: [mix_hc], y: [b,s,hc,d]
        shape, dtype = x.size(), x.dtype
        x = x.flatten(2).float()
        rsqrt = torch.rsqrt(x.square().mean(-1, keepdim=True) + self.norm_eps)
        mixes = F.linear(x, hc_fn) * rsqrt
        pre, post, comb = hc_split_sinkhorn(mixes, hc_scale, hc_base, self.hc_mult, self.hc_sinkhorn_iters, self.hc_eps)
        y = torch.sum(pre.unsqueeze(-1) * x.view(shape), dim=2)
        return y.to(dtype), post, comb

    def hc_post(self, x: torch.Tensor, residual: torch.Tensor, post: torch.Tensor, comb: torch.Tensor):
        # x: [b,s,d], residual: [b,s,hc,d], post: [b,s,hc], comb: [b,s,hc,hc], y: [b,s,hc,d]
        y = post.unsqueeze(-1) * x.unsqueeze(-2) + torch.sum(comb.unsqueeze(-1) * residual.unsqueeze(-2), dim=2)
        return y.type_as(x)

A block owns attention, the mixture of experts, two RMSNorms, and for each sublayer a projection of the flattened four streams to 24 mix numbers, their 24 offsets and three scales.

model.py 647–671 ↗ · deepseek-ai/DeepSeek-V4-Flash @ 60d8d70770c6

Excerpt
class Block(nn.Module):
    """Transformer block with Hyper-Connections (HC) mixing.
    Instead of a simple residual, HC maintains `hc_mult` copies of the hidden state.
    hc_pre: reduces hc copies -> 1 via learned weighted sum (pre-weights from Sinkhorn).
    hc_post: expands 1 -> hc copies via learned post-weights + combination matrix."""
    def __init__(self, layer_id: int, args: ModelArgs):
        super().__init__()
        self.layer_id = layer_id
        self.norm_eps = args.norm_eps
        self.attn = Attention(layer_id, args)
        self.ffn = MoE(layer_id, args)
        self.attn_norm = RMSNorm(args.dim, self.norm_eps)
        self.ffn_norm = RMSNorm(args.dim, self.norm_eps)
        self.hc_mult = hc_mult = args.hc_mult
        self.hc_sinkhorn_iters = args.hc_sinkhorn_iters
        self.hc_eps = args.hc_eps
        mix_hc = (2 + hc_mult) * hc_mult
        hc_dim = hc_mult * args.dim
        with set_dtype(torch.float32):
            self.hc_attn_fn = nn.Parameter(torch.empty(mix_hc, hc_dim))
            self.hc_ffn_fn = nn.Parameter(torch.empty(mix_hc, hc_dim))
            self.hc_attn_base = nn.Parameter(torch.empty(mix_hc))
            self.hc_ffn_base = nn.Parameter(torch.empty(mix_hc))
            self.hc_attn_scale = nn.Parameter(torch.empty(3))
            self.hc_ffn_scale = nn.Parameter(torch.empty(3))