MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / linear

Method linear

optimizers/kfac_utils.py:53–66  ·  view source on GitHub ↗

:param input: batch_size * input_dim :param grad_output: batch_size * output_dim :param layer: [nn.module] output_dim * input_dim :return: batch_size * output_dim * (input_dim + [1 if with bias])

(input, grad_output, layer)

Source from the content-addressed store, hash-verified

51
52 @staticmethod
53 def linear(input, grad_output, layer):
54 """
55 :param input: batch_size * input_dim
56 :param grad_output: batch_size * output_dim
57 :param layer: [nn.module] output_dim * input_dim
58 :return: batch_size * output_dim * (input_dim + [1 if with bias])
59 """
60 with torch.no_grad():
61 if layer.bias is not None:
62 input = torch.cat([input, input.new(input.size(0), 1).fill_(1)], 1)
63 input = input.unsqueeze(1)
64 grad_output = grad_output.unsqueeze(2)
65 grad = torch.bmm(grad_output, input)
66 return grad
67
68 @staticmethod
69 def conv2d(input, grad_output, layer):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected