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

Method train_one_batch

examples/hfl/src/mlp.py:47–61  ·  view source on GitHub ↗
(self, x, y, dist_option, spars)

Source from the content-addressed store, hash-verified

45 return y
46
47 def train_one_batch(self, x, y, dist_option, spars):
48 out = self.forward(x)
49 loss = self.softmax_cross_entropy(out, y)
50
51 if dist_option == "plain":
52 self.optimizer(loss)
53 elif dist_option == "half":
54 self.optimizer.backward_and_update_half(loss)
55 elif dist_option == "partialUpdate":
56 self.optimizer.backward_and_partial_update(loss)
57 elif dist_option == "sparseTopK":
58 self.optimizer.backward_and_sparse_update(loss, topK=True, spars=spars)
59 elif dist_option == "sparseThreshold":
60 self.optimizer.backward_and_sparse_update(loss, topK=False, spars=spars)
61 return out, loss
62
63 def set_optimizer(self, optimizer):
64 self.optimizer = optimizer

Callers

nothing calls this directly

Calls 4

forwardMethod · 0.95

Tested by

no test coverage detected