Forward step.
(data_iterator, model)
| 87 | |
| 88 | |
| 89 | def forward_step(data_iterator, model): |
| 90 | """Forward step.""" |
| 91 | args = get_args() |
| 92 | timers = get_timers() |
| 93 | |
| 94 | # Get the batch. |
| 95 | timers('batch generator').start() |
| 96 | tokens, labels, loss_mask, attention_mask, position_ids = get_batch( |
| 97 | data_iterator) |
| 98 | timers('batch generator').stop() |
| 99 | # Forward model. |
| 100 | losses = model(tokens, position_ids, attention_mask, labels=labels) |
| 101 | if args.curriculum_learning and args.curriculum_seqlen < args.seq_length: |
| 102 | loss_mask = loss_mask[:, :args.curriculum_seqlen].contiguous() |
| 103 | loss_mask = loss_mask.view(-1) |
| 104 | loss = torch.sum(losses.view(-1) * loss_mask) / loss_mask.sum() |
| 105 | |
| 106 | # Reduce loss for logging. |
| 107 | reduced_loss = reduce_losses([loss]) |
| 108 | |
| 109 | return loss, {'lm loss': reduced_loss[0]} |
| 110 | |
| 111 | |
| 112 | def train_valid_test_datasets_provider(train_val_test_num_samples): |
nothing calls this directly
no test coverage detected