Read-out weights

Flatten the streams

×

Lay the 4 streams end to end: 28,672 features per position.

[B, T, 4, 7168]  →  [B, T, 28672][B,\,T,\,4,\,7168]\;\to\;[B,\,T,\,28672]
in
X61X_{61} [B batch, T positions, 4 streams, 7168 d]
out
xfx^{f} [B batch, T positions, 28672 streams × d]
Sources

In codex.flatten(2).float() · 676

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-Pro @ b5968e9190ef

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)