def backward(self, inputs, grad_outputs):
x, V, g = inputs[:3]
if hasattr(self, "W") == False:
self.norm = _get_norm(V)
self.V_normalized = V / self.norm
self.W = g * self.V_normalized
b = inputs[3] if len(inputs) == 4 else None
if b is None:
gx, gW = super(Convolution1DFunction, self).backward((x, self.W), grad_outputs)
else:
gx, gW, gb = super(Convolution1DFunction, self).backward((x, self.W, b), grad_outputs)
xp = cuda.get_array_module(x)
gg = xp.sum(gW * self.V_normalized, axis=(1, 2), keepdims=True)
gV = g * (gW - gg * self.V_normalized) / self.norm
if b is None:
return gx, gV, gg
else:
return gx, gV, gg, gb
评论列表
文章目录