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

Function forward_step

DeepSpeedExample/pretrain_gpt2.py:89–109  ·  view source on GitHub ↗

Forward step.

(data_iterator, model)

Source from the content-addressed store, hash-verified

87
88
89def 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
112def train_valid_test_datasets_provider(train_val_test_num_samples):

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected