Skip to content

Commit

Permalink
Add dropout prob check (#2695)
Browse files Browse the repository at this point in the history
* Add dropout prob check

* Add  test
  • Loading branch information
laggui authored Jan 14, 2025
1 parent 1902c90 commit ddc4339
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/burn-core/src/nn/dropout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ pub struct Dropout {
impl DropoutConfig {
/// Initialize a new [dropout](Dropout) module.
pub fn init(&self) -> Dropout {
if self.prob < 0.0 || self.prob > 1.0 {
panic!(
"Dropout probability should be between 0 and 1, but got {}",
self.prob
);
}
Dropout { prob: self.prob }
}
}
Expand Down Expand Up @@ -108,4 +114,11 @@ mod tests {

assert_eq!(alloc::format!("{}", layer), "Dropout {prob: 0.5}");
}

#[test]
#[should_panic = "Dropout probability should be between 0 and 1,"]
fn dropout_prob_invalid() {
let config = DropoutConfig::new(-10.);
let _layer = config.init();
}
}

0 comments on commit ddc4339

Please sign in to comment.