def backward_gpu(self, inputs, grad_outputs):
cupy = cuda.cupy
x, t = inputs
gloss = grad_outputs[0]
n_unit = t.size // len(t)
coeff = gloss * self._coeff
gx = cuda.elementwise(
'T y, S t, raw T coeff, S n_channel, S n_unit, raw T weights',
'T gx',
'''
const int c = (i / n_unit % n_channel);
gx = ((t == -1) || (c != t)) ? 0 : ((weights[t]*coeff[0]) / max(y, 1e-5));
''',
'crossent_bwd')(self.y, cupy.expand_dims(t, 1), -coeff, x.shape[1], n_unit, self.weights.reduced_view())
return gx, None
weighted_cross_entropy.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录