Struct MuonConfig
pub struct MuonConfig { /* private fields */ }Expand description
Muon configuration.
Muon is an optimizer specifically designed for 2D parameters of neural network hidden layers (weight matrices). Other parameters such as biases and embeddings should be optimized using a standard method such as AdamW.
§Learning Rate Adjustment
Muon adjusts the learning rate based on parameter shape to maintain consistent RMS across rectangular matrices. Two methods are available:
-
Original: Uses
sqrt(max(1, A/B))where A and B are the first two dimensions. This is Keller Jordan’s method and is the default. -
MatchRmsAdamW: Uses
0.2 * sqrt(max(A, B)). This is Moonshot’s method designed to match AdamW’s RMS, allowing direct reuse of AdamW hyperparameters.
§Example
use burn_optim::{MuonConfig, AdjustLrFn};
// Using default (Original) method
let optimizer = MuonConfig::new().init();
// Using MatchRmsAdamW for AdamW-compatible hyperparameters
let optimizer = MuonConfig::new()
.with_adjust_lr_fn(AdjustLrFn::MatchRmsAdamW)
.init();§References
Implementations§
§impl MuonConfig
impl MuonConfig
pub fn new() -> MuonConfig
pub fn new() -> MuonConfig
Create a new instance of the config.
§impl MuonConfig
impl MuonConfig
pub fn with_momentum(self, momentum: MomentumConfig) -> MuonConfig
pub fn with_momentum(self, momentum: MomentumConfig) -> MuonConfig
Momentum config.
pub fn with_ns_coefficients(
self,
ns_coefficients: (f32, f32, f32),
) -> MuonConfig
pub fn with_ns_coefficients( self, ns_coefficients: (f32, f32, f32), ) -> MuonConfig
Newton-Schulz iteration coefficients (a, b, c).
pub fn with_epsilon(self, epsilon: f32) -> MuonConfig
pub fn with_epsilon(self, epsilon: f32) -> MuonConfig
Epsilon for numerical stability.
pub fn with_ns_steps(self, ns_steps: usize) -> MuonConfig
pub fn with_ns_steps(self, ns_steps: usize) -> MuonConfig
Number of Newton-Schulz iteration steps.
pub fn with_adjust_lr_fn(self, adjust_lr_fn: AdjustLrFn) -> MuonConfig
pub fn with_adjust_lr_fn(self, adjust_lr_fn: AdjustLrFn) -> MuonConfig
Learning rate adjustment method.
pub fn with_weight_decay(
self,
weight_decay: Option<WeightDecayConfig>,
) -> MuonConfig
pub fn with_weight_decay( self, weight_decay: Option<WeightDecayConfig>, ) -> MuonConfig
Set the default value for the field.
§impl MuonConfig
impl MuonConfig
pub fn init<B, M>(
&self,
) -> OptimizerAdaptor<Muon<<B as AutodiffBackend>::InnerBackend>, M, B>where
B: AutodiffBackend,
M: AutodiffModule<B>,
pub fn init<B, M>(
&self,
) -> OptimizerAdaptor<Muon<<B as AutodiffBackend>::InnerBackend>, M, B>where
B: AutodiffBackend,
M: AutodiffModule<B>,
Initialize Muon optimizer.
§Returns
Returns an optimizer adaptor that can be used to optimize a module.
§Example
use burn_optim::{MuonConfig, AdjustLrFn, decay::WeightDecayConfig};
// Basic configuration with default (Original) LR adjustment
let optimizer = MuonConfig::new()
.with_weight_decay(Some(WeightDecayConfig::new(0.01)))
.init();
// With AdamW-compatible settings using MatchRmsAdamW
let optimizer = MuonConfig::new()
.with_adjust_lr_fn(AdjustLrFn::MatchRmsAdamW)
.with_weight_decay(Some(WeightDecayConfig::new(0.1)))
.init();
// Custom momentum and NS settings
let optimizer = MuonConfig::new()
.with_momentum(MomentumConfig {
momentum: 0.9,
dampening: 0.1,
nesterov: false,
})
.with_ns_steps(7)
.init();Trait Implementations§
§impl Clone for MuonConfig
impl Clone for MuonConfig
§fn clone(&self) -> MuonConfig
fn clone(&self) -> MuonConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Config for MuonConfig
impl Config for MuonConfig
§impl Debug for MuonConfig
impl Debug for MuonConfig
§impl<'de> Deserialize<'de> for MuonConfig
impl<'de> Deserialize<'de> for MuonConfig
§fn deserialize<D>(
deserializer: D,
) -> Result<MuonConfig, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<MuonConfig, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
§impl Display for MuonConfig
impl Display for MuonConfig
§impl Serialize for MuonConfig
impl Serialize for MuonConfig
§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Auto Trait Implementations§
impl Freeze for MuonConfig
impl RefUnwindSafe for MuonConfig
impl Send for MuonConfig
impl Sync for MuonConfig
impl Unpin for MuonConfig
impl UnwindSafe for MuonConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more