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

Function forward_step

SwissArmyTransformer/examples/glm/finetune_glm_boolq.py:68–85  ·  view source on GitHub ↗

Forward step.

(data_iterator, model, args, timers)

Source from the content-addressed store, hash-verified

66
67
68def forward_step(data_iterator, model, args, timers):
69 """Forward step."""
70
71 # Get the batch.
72 timers('batch generator').start()
73 tokens, labels, attention_mask, position_ids, loss_mask = get_batch(
74 data_iterator, args, timers)
75 timers('batch generator').stop()
76
77 logits, *mems = model(tokens, position_ids, attention_mask)
78 # pred = ((logits.contiguous().float().squeeze(-1)) * loss_mask).sum(dim=-1) / loss_mask.sum(dim=-1)
79 pred = logits.contiguous().float().squeeze(-1)[..., 0]
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
87
88from sat.data_utils import load_hf_dataset

Callers

nothing calls this directly

Calls 3

startMethod · 0.80
stopMethod · 0.80
get_batchFunction · 0.70

Tested by

no test coverage detected