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_projper head,linear_o_group_projand the output gate per output group;D layers:
linear_q_up_projper head and, inside a head, the no-RoPE and RoPE rows apart;linear_kv_down_projas the latent and the RoPE key;k_b_proj,v_b_projand the output gate per head; the indexer’slinear_wq_bper 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#
The Muon row blocks of the weights |
|
The layout that has Megatron-Core’s split-QKV Muon orthogonalize every row block alone. |
|
Whether the fc1 |
|
Set the reference’s Muon recipe on |
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,
The Muon row blocks of the weights
moduleowns directly, by name relative tomodule.
- bridge.models.ernie.modeling_ernie55.muon.ernie55_muon_layout(
- sizes: list[int],
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 issizeswith or withoutmuon_split_qkv_per_head(per_head_split_shapes * num_groupsorprojection_split_shapesover one group); onlymuon_split_qkvturns it on.is_mla=False, so the split does not depend onmuon_split_mla_qkv.
- bridge.models.ernie.modeling_ernie55.muon._has_glu_interleave(config, name: str) bool#
Whether the fc1
namekeeps 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.