Gate, merge and project

Merge heads

×

Concatenate the 128 heads into 16,384 features.

[B, 128, T, 128][B,\,128,\,T,\,128]
→  [B, T, 128, 128]\to\;[B,\,T,\,128,\,128]
→  [B, T, 16384]\to\;[B,\,T,\,16384]
in
ogo^{g} [B batch, 128 heads, T positions, 128 value d_h]
out
oo [B batch, T positions, 16384 heads × d_h]
Explanation

Heads are concatenated in order: head ii fills features 128i,…,128i+127{128i},\dots,{128i+127}.

Sources

In codecore_attn_out.reshape(batch_size, seq_len, -1) · 648

Open pinned code ↗

Direct evidence

The kernel’s output passes the gated RMSNorm, gated by z, head by head, is flattened and projected to the model width.

modeling_qwen3_5_moe.py 644–651 ↗ · huggingface/transformers @ 18329f106538

Excerpt
        # reshape input data into 2D tensor
        core_attn_out = core_attn_out.reshape(-1, self.head_v_dim)
        z = z.reshape(-1, self.head_v_dim)
        core_attn_out = self.norm(core_attn_out, z)
        core_attn_out = core_attn_out.reshape(batch_size, seq_len, -1)

        output = self.out_proj(core_attn_out)
        return output