Skip to content

Commit

Permalink
Add ConvTranspose2d with bias_jac_t_mat_prod
Browse files Browse the repository at this point in the history
  • Loading branch information
F. Dangel committed Apr 26, 2020
1 parent 75e861f commit e6d1382
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backpack/core/derivatives/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from torch.nn import (
AvgPool2d,
Conv2d,
ConvTranspose2d,
Dropout,
Linear,
MaxPool2d,
Expand All @@ -12,6 +13,7 @@

from .avgpool2d import AvgPool2DDerivatives
from .conv2d import Conv2DDerivatives
from .conv_transpose2d import ConvTranspose2DDerivatives
from .dropout import DropoutDerivatives
from .linear import LinearDerivatives
from .maxpool2d import MaxPool2DDerivatives
Expand All @@ -30,4 +32,5 @@
ReLU: ReLUDerivatives,
Tanh: TanhDerivatives,
Sigmoid: SigmoidDerivatives,
ConvTranspose2d: ConvTranspose2DDerivatives,
}
24 changes: 24 additions & 0 deletions backpack/core/derivatives/conv_transpose2d.py
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

0 comments on commit e6d1382

Please sign in to comment.