Skip to content

Add fan_out to Conv2dConfig::init #1138

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

Merged
merged 1 commit into from
Jan 12, 2024
Merged

Add fan_out to Conv2dConfig::init #1138

merged 1 commit into from
Jan 12, 2024

Conversation

laggui
Copy link
Member

@laggui laggui commented Jan 12, 2024

When using a custom Initializer with fan_out_only: true, the Conv2dConfig::init() panics because we only provide a value for fan_in.

let init = Initializer::KaimingUniform {
    gain: 1.0 / sqrt(3.0),
    fan_out_only: true,
};
let device = Default::default();
let config = Conv2dConfig::new([5, 1], [5, 5]).with_initializer(init.clone());
let _ = config.init::<TestBackend>(&device);

This example results in:

thread 'main' panicked at burn-core/src/nn/initializer.rs:132:23:
Can't use Kaiming initialization without specifying fan. Use init_with method.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Checklist

  • Confirmed that run-checks all script has been executed.
  • Made sure the book is up to date with changes in this PR.

Changes

  • Added fan_out calculation to Conv2dConfig::init() to handle custom Initializer w/ fan_out_only set to true

Testing

  • Added simple initializer_fan_out() test to make sure fan_out is passed to Initializer::init_with() (previously panicked)

@laggui laggui added the bug Something isn't working label Jan 12, 2024
@laggui laggui requested a review from louisfd January 12, 2024 19:37
Copy link
Member

@louisfd louisfd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the fix 😄

Copy link

codecov bot commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9bd2d7b) 85.69% compared to head (ff48f02) 85.67%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1138      +/-   ##
==========================================
- Coverage   85.69%   85.67%   -0.02%     
==========================================
  Files         513      513              
  Lines       56987    57006      +19     
==========================================
+ Hits        48837    48842       +5     
- Misses       8150     8164      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@louisfd louisfd merged commit 76c9358 into main Jan 12, 2024
@nathanielsimard nathanielsimard deleted the fix/conv2d-initializer branch January 15, 2024 14:39
@louisfd louisfd mentioned this pull request Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants