MCPcopy Index your code
hub / github.com/MoonInTheRiver/DiffSinger / training_forward

Method training_forward

utils/pl_utils.py:1564–1601  ·  view source on GitHub ↗

Handle forward for each training case (distributed, single gpu, etc...) :param batch: :param batch_idx: :return:

(self, batch, batch_idx, opt_idx, hiddens)

Source from the content-addressed store, hash-verified

1562 return 0, grad_norm_dic, all_log_metrics
1563
1564 def training_forward(self, batch, batch_idx, opt_idx, hiddens):
1565 """
1566 Handle forward for each training case (distributed, single gpu, etc...)
1567 :param batch:
1568 :param batch_idx:
1569 :return:
1570 """
1571 # ---------------
1572 # FORWARD
1573 # ---------------
1574 # enable not needing to add opt_idx to training_step
1575 args = [batch, batch_idx, opt_idx]
1576
1577 # distributed forward
1578 if self.use_ddp or self.use_dp:
1579 output = self.model(*args)
1580 # single GPU forward
1581 elif self.single_gpu:
1582 gpu_id = 0
1583 if isinstance(self.data_parallel_device_ids, list):
1584 gpu_id = self.data_parallel_device_ids[0]
1585 batch = self.transfer_batch_to_gpu(copy.copy(batch), gpu_id)
1586 args[0] = batch
1587 output = self.model.training_step(*args)
1588 # CPU forward
1589 else:
1590 output = self.model.training_step(*args)
1591
1592 # allow any mode to define training_end
1593 model_ref = self.get_model()
1594 output_ = model_ref.training_end(output)
1595 if output_ is not None:
1596 output = output_
1597
1598 # format and reduce outputs accordingly
1599 output = self.process_output(output, train=True)
1600
1601 return output
1602
1603 # ---------------
1604 # Utils

Callers 1

optimizer_closureMethod · 0.95

Calls 5

transfer_batch_to_gpuMethod · 0.95
get_modelMethod · 0.95
process_outputMethod · 0.95
training_stepMethod · 0.80
training_endMethod · 0.80

Tested by

no test coverage detected