filter kwargs before creating norm layer #2642
Closed
+14
−4
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.
Unlike other create_* functions, create_norm_layer can create normalization layers that have different parameters (such as BatchNorm2d and GroupNorm), which may trigger errors for missing required arguments or passes redundant arguments. So it's reasoning that delete them before create.
In short, I want the following code works correctly whether it's batch normalization or group normalization.
Please notice that this is a breaking change that compromises backward compatibility (the removing of num_features). If it's necessary, I can add it back. Furthermore, it doesn't robustly handle unusual scenarios, though it suffices for all normalization layers in Pytorch and timm.