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

Method train_one_batch

examples/cifar_distributed_cnn/model/xceptionnet.py:274–291  ·  view source on GitHub ↗
(self, x, y, dist_option, spars)

Source from the content-addressed store, hash-verified

272 return x
273
274 def train_one_batch(self, x, y, dist_option, spars):
275 out = self.forward(x)
276 loss = self.softmax_cross_entropy(out, y)
277 if dist_option == 'plain':
278 self.optimizer(loss)
279 elif dist_option == 'half':
280 self.optimizer.backward_and_update_half(loss)
281 elif dist_option == 'partialUpdate':
282 self.optimizer.backward_and_partial_update(loss)
283 elif dist_option == 'sparseTopK':
284 self.optimizer.backward_and_sparse_update(loss,
285 topK=True,
286 spars=spars)
287 elif dist_option == 'sparseThreshold':
288 self.optimizer.backward_and_sparse_update(loss,
289 topK=False,
290 spars=spars)
291 return out, loss
292
293 def set_optimizer(self, optimizer):
294 self.optimizer = optimizer

Callers

nothing calls this directly

Calls 4

forwardMethod · 0.95

Tested by

no test coverage detected