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

Method forward

python/singa/autograd.py:1273–1284  ·  view source on GitHub ↗
(self, pos, neg)

Source from the content-addressed store, hash-verified

1271 self.M = M
1272
1273 def forward(self, pos, neg):
1274 # L = max{0, M - fn(pos) + fn(neg)}
1275 zero = singa.Tensor(list(pos.shape()), pos.device())
1276 zero.SetFloatValue(0.0)
1277 val = singa.AddFloat(singa.__sub__(neg, pos), self.M)
1278 gt_zero = singa.__gt__(val, zero)
1279 if training:
1280 self.inputs = (gt_zero,) # (BS,)
1281 all_loss = singa.__mul__(gt_zero, val)
1282 loss = singa.SumAll(all_loss)
1283 loss /= (pos.shape()[0])
1284 return loss
1285
1286 def backward(self, dy=1.0):
1287 assert training, "enable training mode to do backward"

Callers

nothing calls this directly

Calls 6

TensorMethod · 0.80
shapeMethod · 0.80
deviceMethod · 0.80
__sub__Method · 0.45
__gt__Method · 0.45
__mul__Method · 0.45

Tested by

no test coverage detected