MCPcopy Create free account
hub / github.com/apache/singa / backward

Method backward

python/singa/autograd.py:1286–1297  ·  view source on GitHub ↗
(self, dy=1.0)

Source from the content-addressed store, hash-verified

1284 return loss
1285
1286 def backward(self, dy=1.0):
1287 assert training, "enable training mode to do backward"
1288 # dpos = -1 if M-pos+neg > 0 else 0
1289 # dneg = 1 if M-pos+neg > 0 else 0
1290 gt_zero = self.inputs[0]
1291 dpos_factor = singa.Tensor(list(gt_zero.shape()), gt_zero.device())
1292 dpos_factor.SetFloatValue(-1.0 / gt_zero.Size())
1293 dneg_factor = singa.Tensor(list(gt_zero.shape()), gt_zero.device())
1294 dneg_factor.SetFloatValue(1.0 / gt_zero.Size())
1295 dpos = singa.__mul__(gt_zero, dpos_factor)
1296 dneg = singa.__mul__(gt_zero, dneg_factor)
1297 return dpos, dneg
1298
1299
1300def ranking_loss(pos, neg, M=0.2):

Callers

nothing calls this directly

Calls 5

TensorMethod · 0.80
shapeMethod · 0.80
deviceMethod · 0.80
SizeMethod · 0.45
__mul__Method · 0.45

Tested by

no test coverage detected