-
Notifications
You must be signed in to change notification settings - Fork 958
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1225 from nicholas-leonard/ZeroGrad
nn.ZeroGrad
- Loading branch information
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
local ZeroGrad, parent = torch.class('nn.ZeroGrad', 'nn.Module') | ||
|
||
function ZeroGrad:updateOutput(input) | ||
self.output:set(input) | ||
return self.output | ||
end | ||
|
||
-- the gradient is simply zeroed. | ||
-- useful when you don't want to backpropgate through certain paths. | ||
function ZeroGrad:updateGradInput(input, gradOutput) | ||
self.gradInput = nn.utils.recursiveResizeAs(self.gradInput, input) | ||
self.gradInput = nn.utils.recursiveFill(self.gradInput, 0) | ||
return self.gradInput | ||
end |
This file contains 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
This file contains 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
This file contains 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