Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/optim #272

Merged
merged 13 commits into from
Apr 5, 2023
Prev Previous commit
Next Next commit
Run clippy
  • Loading branch information
nathanielsimard committed Apr 5, 2023
commit b6f6e2b95ca6fa3a6c7f5f034b5348bf6ff41438
12 changes: 3 additions & 9 deletions burn-core/src/optim/adam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ impl AdamConfig {
beta_2: self.beta_2,
epsilon: self.epsilon,
},
weight_decay: self
.weight_decay
.as_ref()
.map(|config| WeightDecay::new(config)),
weight_decay: self.weight_decay.as_ref().map(WeightDecay::new),
};
OptimizerAdaptor::from(optim)
}
Expand Down Expand Up @@ -130,7 +127,7 @@ impl AdaptiveMomentum {
.mul_scalar(self.beta_2)
.add(grad.powf(2.0).mul_scalar(factor));

state.time = state.time + 1;
state.time += 1;

state
} else {
Expand Down Expand Up @@ -288,10 +285,7 @@ mod tests {
beta_2: config.beta_2,
epsilon: config.epsilon,
},
weight_decay: config
.weight_decay
.as_ref()
.map(|config| WeightDecay::new(config)),
weight_decay: config.weight_decay.as_ref().map(WeightDecay::new),
}
.into()
}
Expand Down
7 changes: 2 additions & 5 deletions burn-core/src/optim/sgd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ impl SgdConfig {
&self,
) -> OptimizerAdaptor<Sgd<B::InnerBackend>, M, B> {
let learning_rate = self.learning_rate.elem();
let momentum = self.momentum.as_ref().map(|config| Momentum::new(config));
let weight_decay = self
.weight_decay
.as_ref()
.map(|config| WeightDecay::new(config));
let momentum = self.momentum.as_ref().map(Momentum::new);
let weight_decay = self.weight_decay.as_ref().map(WeightDecay::new);

Sgd {
learning_rate,
Expand Down
2 changes: 1 addition & 1 deletion burn-core/src/record/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<const N: usize, T: Record + core::fmt::Debug> Record for [T; N] {
.map(Record::from_item)
.collect::<Vec<_>>()
.try_into()
.expect(format!("An arrar of size {N}").as_str())
.unwrap_or_else(|_| panic!("An arrar of size {N}"))
}
}

Expand Down
3 changes: 1 addition & 2 deletions burn-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ pub fn module_derive(input: TokenStream) -> TokenStream {
#[proc_macro_derive(Record)]
pub fn record_derive(input: TokenStream) -> TokenStream {
let input = syn::parse(input).unwrap();
let gen = record_derive_impl(&input);

// panic!("{}", gen);
gen
record_derive_impl(&input)
}

#[proc_macro_derive(Config, attributes(config))]
Expand Down