Fix HardShrink to accept its documented lambd argument#3786
Open
Pablosinyores wants to merge 1 commit into
Open
Fix HardShrink to accept its documented lambd argument#3786Pablosinyores wants to merge 1 commit into
Pablosinyores wants to merge 1 commit into
Conversation
HardShrink was built with @_make_activation_module, which sets __call__ to always use the default lambd and gives the class no __init__. Its docstring documents a configurable lambd, but the class could not be constructed with one: nn.HardShrink(lambd=0.3) raised TypeError. Replace the decorator with an explicit __init__/__call__ that stores and forwards lambd, mirroring the sibling Softshrink layer. Extend test_hard_shrink to exercise the class path (default and lambd=0.1), which was previously untested.
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.
What
nn.HardShrinkdocuments a configurablelambdargument (Default: 0.5), but the class cannot actually be constructed with one:The class is built with
@_make_activation_module(hard_shrink), which sets__call__to always apply the defaultlambdand leaves the class with no__init__(it inheritsModule.__init__(self)). So the documented parameter is silently unusable.Fix
Replace the decorator with an explicit
__init__/__call__that stores and forwardslambd, mirroring the siblingSoftshrinklayer (which already does this and is tested). Every other parameterized activation (Softshrink,ELU,CELU,LeakyReLU,PReLU,Step) follows this same pattern;HardShrinkwas the lone one mistakenly decorated.Tests
Extended
test_hard_shrinkto exercise the class path (nn.HardShrink()andnn.HardShrink(lambd=0.1)), which was previously untested — only the functionalnn.hard_shrinkwas covered, which is why the missing parameter went unnoticed.