-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Support subsampling in jac_t_mat_prod
- Loading branch information
Showing
24 changed files
with
291 additions
and
125 deletions.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
from torch import gt | ||
|
||
from backpack.core.derivatives.elementwise import ElementwiseDerivatives | ||
from backpack.core.derivatives.subsampling import subsample_input | ||
|
||
|
||
class LeakyReLUDerivatives(ElementwiseDerivatives): | ||
def hessian_is_zero(self): | ||
"""`LeakyReLU''(x) = 0`.""" | ||
return True | ||
|
||
def df(self, module, g_inp, g_out): | ||
def df(self, module, g_inp, g_out, subsampling=None): | ||
"""First LeakyReLU derivative: | ||
`LeakyReLU'(x) = negative_slope if x < 0 else 1`.""" | ||
df_leakyrelu = gt(module.input0, 0).float() | ||
input = subsample_input(module, subsampling=subsampling) | ||
|
||
df_leakyrelu = gt(input, 0).float() | ||
df_leakyrelu[df_leakyrelu == 0] = module.negative_slope | ||
|
||
return df_leakyrelu |
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
Oops, something went wrong.