detrium.optim.muon

MuAdamW: Hybrid Matrix-Orthogonalized (Muon) + Adaptive (AdamW) Optimizer for DEIM / D-FINE / RT-DETRv2 / RT-DETRv4. Adapts YOLO26 MuSGD & Moonshot Kimi-Muon principles to heterogeneous CNN/DETR architectures: - 5-step quintic Newton-Schulz orthogonalization in bfloat16 Tensor Cores (batched by matrix shape). - RMS-aligned rectangular scaling (ns_scale * sqrt(max(m, n)), default ns_scale=0.2) so Muon updates match AdamW element-wise RMS step size (~0.2 * lr), allowing direct reuse of DEIM lr & weight_decay. - Deterministic structural filtering protecting 1D norms/biases/affine scales, depthwise & grouped convolutions (groups > 1), input stems, discrete embeddings, channel gates (EseModule / EffectiveSELayer / Gateway), deformable attention offsets/weights, distillation projectors, and detection output heads. - Supports both pure Muon on eligible matrices (Phase 1, muon_ratio=1.0, 50% state memory reduction) and MuSGD-inspired dual-cue convex blending (Phase 2, 0 < muon_ratio < 1.0).

导出符号 · MuAdamW、zeropower_via_newtonschulz5_batched、is_muon_eligible

class MuAdamW(optim.Optimizer)

Hybrid Muon + AdamW optimizer with RMS step-size alignment and MuSGD-style update blending.

名称类型默认值
paramsIterable—
lrfloat0.0005
betasTuple[float, float](0.9, 0.999)
epsfloat1e-08
weight_decayfloat0.000125
momentumfloat0.95
nesterovboolTrue
ns_stepsint5
ns_scalefloat0.2
muon_ratiofloat1.0
include_backboneboolFalse
min_dimint16
exclude_patternsOptional[Sequence[str]]None
is_muon_eligible(name: str, param: torch.Tensor, include_backbone: bool=False, min_dim: int=16, exclude_patterns: Sequence[str]=DEFAULT_EXCLUDE_PATTERNS, conv_groups: int=1, is_channel_gate: bool=False) -> Tuple[bool, str]

Deterministically classify whether a parameter tensor should receive Muon orthogonalized updates.

名称类型默认值
namestr—
paramtorch.Tensor—
include_backboneboolFalse
min_dimint16
exclude_patternsSequence[str]DEFAULT_EXCLUDE_PATTERNS
conv_groupsint1
is_channel_gateboolFalse
zeropower_via_newtonschulz5_batched(G: torch.Tensor, steps: int=5, eps: float=1e-12) -> torch.Tensor

Batched 5-step quintic Newton-Schulz iteration approximating the semi-orthogonal polar factor of a batch of 2D matrices G with shape (B, m, n).

名称类型默认值
Gtorch.Tensor—
stepsint5
epsfloat1e-12