MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / forward_step

Function forward_step

DeepSpeedExample/pretrain_bert.py:69–96  ·  view source on GitHub ↗

Forward step.

(data_iterator, model)

Source from the content-addressed store, hash-verified

67
68
69def forward_step(data_iterator, model):
70 """Forward step."""
71 args = get_args()
72 timers = get_timers()
73
74 # Get the batch.
75 timers('batch generator').start()
76 tokens, types, sentence_order, loss_mask, lm_labels, padding_mask \
77 = get_batch(data_iterator)
78 timers('batch generator').stop()
79
80 # Forward model. lm_labels
81 lm_loss_, sop_logits = model(tokens, padding_mask,
82 tokentype_ids=types,
83 lm_labels=lm_labels)
84
85 sop_loss = F.cross_entropy(sop_logits.view(-1, 2).float(),
86 sentence_order.view(-1),
87 ignore_index=-1)
88
89 lm_loss = torch.sum(
90 lm_loss_.view(-1) * loss_mask.reshape(-1)) / loss_mask.sum()
91
92 loss = lm_loss + sop_loss
93
94 reduced_losses = reduce_losses([lm_loss, sop_loss])
95
96 return loss, {'lm loss': reduced_losses[0], 'sop loss': reduced_losses[1]}
97
98
99def train_valid_test_datasets_provider(train_val_test_num_samples):

Callers

nothing calls this directly

Calls 7

get_argsFunction · 0.90
get_timersFunction · 0.90
reduce_lossesFunction · 0.90
get_batchFunction · 0.70
startMethod · 0.45
stopMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected