Layers

Opening layers

×

Layers 1–3, dense, each run its own lightning indexer; layers 4–6, MoE, attend to the positions layer 3 selected.

xn′=xn+Δattnx'_n=x_n+\Delta_{\mathrm{attn}}
xn+1=xn′+Δffnx_{n+1}=x'_n+\Delta_{\mathrm{ffn}}
All 17 steps
Dense layer:\text{Dense layer:}
xattn=RMSNorm⁡(xn)x_{\mathrm{attn}}=\operatorname{RMSNorm}(x_n)
xn′=xn+Δattnx'_n=x_n+\Delta_{\mathrm{attn}}
xffn=RMSNorm⁡(xn′)x_{\mathrm{ffn}}=\operatorname{RMSNorm}(x'_n)
g=xffnW1g=x_{\mathrm{ffn}}W_{1}
u=xffnW3u=x_{\mathrm{ffn}}W_{3}
a=g σ(g)a=g\,\sigma(g)
h=a⊙uh=a\odot u
Δffn=hW2\Delta_{\mathrm{ffn}}=hW_{2}
xn+1=xn′+Δffnx_{n+1}=x'_n+\Delta_{\mathrm{ffn}}
Sharing MoE layer:\text{Sharing MoE layer:}
xattn=RMSNorm⁡(xn)x_{\mathrm{attn}}=\operatorname{RMSNorm}(x_n)
xn′=xn+Δattnx'_n=x_n+\Delta_{\mathrm{attn}}
xffn=RMSNorm⁡(xn′)x_{\mathrm{ffn}}=\operatorname{RMSNorm}(x'_n)
yrouted=∑i=1256Gi Eiy^{\mathrm{routed}}=\sum_{i=1}^{256}G_i\,E_i
Δffn=yrouted+yshared\Delta_{\mathrm{ffn}}=y^{\mathrm{routed}}+y^{\mathrm{shared}}
xn+1=xn′+Δffnx_{n+1}=x'_n+\Delta_{\mathrm{ffn}}
in
x0x_0 [B batch, T positions, 6144 d]RR [T positions, 32 pairs]MM [T queries, T keys]
out
x6x_{6} [B batch, T positions, 6144 d]
Parameters30,806,794,752

30,806,794,752 parameters per instance, across its learned components

ComponentCalculationParameters
Dense layer400,898,816 × 31,202,696,448
Sharing MoE layer9,868,032,768 × 329,604,098,304
Per-instance total30,806,794,752
Explanation

The configuration lists the indexer type of every layer: 21 full, 57 shared (config.json 26–105). A shared layer builds no indexer (modeling_glm_moe_dsa.py 348–349) and attends to the indices of the last full layer before it (404–417).

Sources

In codeself.layers

Open pinned code ↗

Direct evidence

A layer with its own indexer selects its top-k positions; a "shared" layer takes the top-k indices of the previous layer that ran one, and fails without them. Both build the attention mask from those indices and the causal mask, and every layer returns the indices it used, which the model hands to the next layer.

modeling_glm_moe_dsa.py 404–722 ↗ · huggingface/transformers @ c4c4605f9618

Excerpt
        # DSA: select this layer's top-k tokens, or reuse the previous full layer's on `"shared"` layers.
        if self.indexer is not None:
            topk_indices = self.indexer(
                hidden_states,
                q_resid,
                position_embeddings,
                attention_mask[:, 0, :, :],
                position_ids,  # Kept for BC
                past_key_values=past_key_values,
            )  # [B, S, topk]
        else:
            if prev_topk_indices is None:
                raise ValueError("Shared DSA layers require top-k indices from a previous full indexer layer.")
            topk_indices = prev_topk_indices

        sparse_indices = None
        if self.config._attn_implementation in ("eager", "sdpa"):
            index_mask = (
                topk_indices.new_ones((batch_size, seq_length, key_states.shape[2]), dtype=torch.bool)
                .scatter(-1, topk_indices.long(), False)
                .unsqueeze(1)
            )

            if attention_mask.dtype == torch.bool:
                attention_mask = attention_mask & ~index_mask
            else:
                attention_mask = attention_mask.masked_fill(index_mask, torch.finfo(hidden_states.dtype).min)
        else:

… lines 432–599 omitted …

        hidden_states, _, topk_indices = self.self_attn(
            hidden_states=hidden_states,
            attention_mask=attention_mask,
            position_ids=position_ids,
            past_key_values=past_key_values,
            use_cache=use_cache,
            position_embeddings=position_embeddings,
            prev_topk_indices=prev_topk_indices,  # MAIN DIFF with DSV3.2
            **kwargs,
        )
        hidden_states = residual + hidden_states

        residual = hidden_states
        hidden_states = self.post_attention_layernorm(hidden_states)
        hidden_states = self.mlp(hidden_states)
        hidden_states = residual + hidden_states
        return hidden_states, topk_indices

… lines 617–710 omitted …

        topk_indices = None  # MAIN DIFF with DSV3.2
        for i, decoder_layer in enumerate(self.layers[: self.config.num_hidden_layers]):
            hidden_states, topk_indices = decoder_layer(
                hidden_states,
                attention_mask=causal_mask_mapping["indexed_attention"],
                position_embeddings=position_embeddings,
                position_ids=position_ids,
                past_key_values=past_key_values,
                use_cache=use_cache,
                prev_topk_indices=topk_indices,  # MAIN DIFF with DSV3.2
                **kwargs,
            )

Each layer’s indexer type: layers 0, 1 and 2 and every fourth layer from 6 to 74 are "full"; the other 57 are "shared". The configuration also names the schedule that gives this list, index_topk_freq 4 with index_skip_topk_offset 3.

config.json 21–105 ↗ · zai-org/GLM-5.3 @ ba32f8c19c87

Excerpt
  "index_skip_topk_offset": 3,
  "index_topk": 2048,
  "index_topk_freq": 4,
  "index_topk_pattern": null,
  "indexer_rope_interleave": true,
  "indexer_types": [
    "full",
    "full",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared",
    "full",
    "shared",
    "shared",
    "shared"
  ],