Fixes grouped Conv1d/Conv2d init to use in_channels // groups - #4544
Open
CodeWithMoin wants to merge 1 commit into
Open
CodeWithMoin wants to merge 1 commit into
CodeWithMoin wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Conv1dandConv2dcomputed the init bound using the fullin_channels, while the weight's last dimension isin_channels // groups. Forgroups > 1, this made uniform init range too narrow (i.e 0.71x at 2 groups, 0.5x at 4, and 0.35x at 8). This PR fixes #4536 by usingfan_in = (in_channels // groups) * kernel_size, that matches PyTorch's grouped-conv default. For theConv3dand transposed convs, we don't havegroupsoption, so they are unaffected. I've created a new test that checks init bound for groups 1, 2 and 4 on both layers. This test fails before the fix, and passes after the PR fix, In fact the fulltest_nn.pypasses.This changes only the initial random weights, so loaded checkpoints are unaffected.
Before (64 in/out channels, kernel 3, seed 0):
After: ratio 1.000 for every group count, both layers.
Tests:
test_nn74 OK ·test_conv20 OK ·test_conv_transpose10 OK ·test_init11 OK