-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ConvTranspose2d with bias_jac_t_mat_prod
- Loading branch information
F. Dangel
committed
Apr 26, 2020
1 parent
75e861f
commit e6d1382
Showing
2 changed files
with
27 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Partial derivatives for `torch.nn.ConvTranspose2d`.""" | ||
|
||
from torch.nn import ConvTranspose2d | ||
|
||
from backpack.core.derivatives.basederivatives import BaseParameterDerivatives | ||
|
||
|
||
class ConvTranspose2DDerivatives(BaseParameterDerivatives): | ||
def get_module(self): | ||
return ConvTranspose2d | ||
|
||
def hessian_is_zero(self): | ||
return True | ||
|
||
def _bias_jac_t_mat_prod(self, module, g_inp, g_out, mat, sum_batch=True): | ||
N_axis, H_axis, W_axis = 1, 3, 4 | ||
axes = [H_axis, W_axis] | ||
if sum_batch: | ||
axes = [N_axis] + axes | ||
|
||
return mat.sum(axes) | ||
|
||
def _weight_jac_t_mat_prod(self, module, g_inp, g_out, mat, sum_batch=True): | ||
raise NotImplementedError |