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

Function forward_step

SwissArmyTransformer/examples/glm/finetune_glm_sst2.py:69–85  ·  view source on GitHub ↗

Forward step.

(data_iterator, model, args, timers)

Source from the content-addressed store, hash-verified

67
68
69def forward_step(data_iterator, model, args, timers):
70 """Forward step."""
71
72 # Get the batch.
73 timers('batch generator').start()
74 tokens, labels, attention_mask, position_ids, loss_mask = get_batch(
75 data_iterator, args, timers)
76 timers('batch generator').stop()
77
78 logits, *mems = model(tokens, position_ids, attention_mask)
79 pred = ((logits.contiguous().float().squeeze(-1)) * loss_mask).sum(dim=-1) / loss_mask.sum(dim=-1)
80 loss = torch.nn.functional.binary_cross_entropy_with_logits(
81 pred,
82 labels.float()
83 )
84 acc = ((pred > 0.).long() == labels).sum() / labels.numel()
85 return loss, {'acc': acc}
86
87def create_dataset_function(path, args):
88 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