bridge.models.ernie.modeling_ernie55.muon#

The reference implementation’s Muon recipe as parameter attributes Megatron-Core’s Muon reads.

The reference’s Muon (muon_qkv_update_mode="split_head", muon_ffn_split) orthogonalizes some weights block by block: every row block below goes through Newton-Schulz alone, with Muon’s scale of its own shape. :func:tag_ernie55_muon_params describes the blocks (:func:ernie55_muon_split_sizes) to Megatron-Core as a per-parameter :class:~megatron.core.transformer.attention.QKVLayout with one group whose per-head slices are the blocks (is_mla=False), on

  • H layers: linear_q_up_proj per head, linear_o_group_proj and the output gate per output group;

  • D layers: linear_q_up_proj per head and, inside a head, the no-RoPE and RoPE rows apart; linear_kv_down_proj as the latent and the RoPE key; k_b_proj, v_b_proj and the output gate per head; the indexer’s linear_wq_b per indexer head;

  • every gated fc1 (dense MLP, routed and shared experts) as its gate and up halves.

Megatron-Core’s emerging-optimizer setup tags every 2-D weight that carries a qkv_layout (is_qkv and its split shapes). muon_split_qkv (Megatron-Core’s default, which the ERNIE 5.5 recipe keeps) is what turns the blocks on: with it TensorParallelMuon.orthogonalize orthogonalizes each block separately. With muon_split_qkv=False Muon silently orthogonalizes these weights whole, dropping the reference’s blocks. Since the layout has a single group, muon_split_qkv_per_head does not change which rows form a block; it only picks Megatron-Core’s per-head implementation. The recipe leaves it off: for blocks of one size that implementation runs one batched Newton-Schulz and reshapes its result with view_as (TensorParallelMuon._orthogonalize_split_qkv), which fails when the blocks have more rows than columns, because Newton-Schulz then returns a transposed, non-contiguous tensor. k_b_proj and the dense fc1 halves have such blocks. Without it Megatron-Core orthogonalizes the blocks one at a time. These layouts replace Megatron-Core’s own on the H and D query up projections, which are MLA layouts (is_mla=True) that Muon splits only under muon_split_mla_qkv; the recipe leaves that off, so no other weight is split.

The compressor’s APE (muon_exclude_patterns "ape") is tagged use_muon=False, which sends it to the scalar optimizer; the router matrices ("mlp.gate") follow moe_router_skip_muon, which the ERNIE 5.5 bridge turns on.

The block sizes describe a weight’s local rows, so they are set only when no weight is sharded along dim 0 (tensor and expert tensor parallel size 1); otherwise Muon orthogonalizes whole matrices, with a warning.

Per-parameter QKV layouts exist only in Megatron-Core dev: with a Megatron-Core that has no QKVLayout, :func:tag_ernie55_muon_params still excludes the APE but leaves every weight unsplit, with one warning per process.

Module Contents#

Functions#

ernie55_muon_split_sizes

The Muon row blocks of the weights module owns directly, by name relative to module.

ernie55_muon_layout

The layout that has Megatron-Core’s split-QKV Muon orthogonalize every row block alone.

_has_glu_interleave

Whether the fc1 name keeps Megatron-Core’s block-interleaved [g, u, g, u, ...] rows.

tag_ernie55_muon_params

Set the reference’s Muon recipe on model’s parameters (see the module docstring).

Data#

API#

bridge.models.ernie.modeling_ernie55.muon.logger#

‘getLogger(…)’

bridge.models.ernie.modeling_ernie55.muon.__all__#

[‘ernie55_muon_layout’, ‘ernie55_muon_split_sizes’, ‘tag_ernie55_muon_params’]

bridge.models.ernie.modeling_ernie55.muon._GATED_FC1#

‘compile(…)’

bridge.models.ernie.modeling_ernie55.muon._warned_no_qkv_layout#

False

bridge.models.ernie.modeling_ernie55.muon.ernie55_muon_split_sizes(
module: torch.nn.Module,
) → dict[str, list[int]]#

The Muon row blocks of the weights module owns directly, by name relative to module.

bridge.models.ernie.modeling_ernie55.muon.ernie55_muon_layout(
sizes: list[int],
) → megatron.core.transformer.attention.QKVLayout#

The layout that has Megatron-Core’s split-QKV Muon orthogonalize every row block alone.

One group whose projections and per-head slices are both sizes, so Megatron-Core’s split is sizes with or without muon_split_qkv_per_head (per_head_split_shapes * num_groups or projection_split_shapes over one group); only muon_split_qkv turns it on. is_mla=False, so the split does not depend on muon_split_mla_qkv.

bridge.models.ernie.modeling_ernie55.muon._has_glu_interleave(config, name: str) → bool#

Whether the fc1 name keeps Megatron-Core’s block-interleaved [g, u, g, u, ...] rows.

bridge.models.ernie.modeling_ernie55.muon.tag_ernie55_muon_params(model: torch.nn.Module) → None#

Set the reference’s Muon recipe on model’s parameters (see the module docstring).

Shared SD-MTP parameters are the decoder’s Parameters, so they are tagged once.