MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / forward_step

Function forward_step

SwissArmyTransformer/examples/cogview/pretrain_gpt2.py:86–102  ·  view source on GitHub ↗

Forward step.

(data_iterator, model, args, timers)

Source from the content-addressed store, hash-verified

84
85
86def forward_step(data_iterator, model, args, timers):
87 """Forward step."""
88
89 # Get the batch.
90 timers('batch generator').start()
91 tokens, labels, loss_mask, attention_mask, position_ids = get_batch(
92 data_iterator, args, timers)
93 timers('batch generator').stop()
94 # Forward model.
95 logits, *mems = model(tokens, position_ids, attention_mask)
96 losses = mpu.vocab_parallel_cross_entropy(logits.contiguous().float(), labels)
97 # scaling loss mask
98 loss_mask = loss_mask.view(-1)
99
100 losses = losses.view(-1) * loss_mask
101 loss = torch.sum(losses) / loss_mask.sum()
102 return loss, {}
103
104def create_dataset_function(path, args):
105 tokenizer = get_tokenizer()

Callers

nothing calls this directly

Calls 3

startMethod · 0.80
stopMethod · 0.80
get_batchFunction · 0.70

Tested by

no test coverage detected