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

Function get_batch

SwissArmyTransformer/examples/bert/finetune_bert_boolq.py:11–35  ·  view source on GitHub ↗
(data_iterator, args, timers)

Source from the content-addressed store, hash-verified

9from bert_ft_model import ClassificationModel
10
11def get_batch(data_iterator, args, timers):
12 # Items and their type.
13 keys = ['input_ids', 'position_ids', 'token_type_ids', 'attention_mask', 'label']
14 datatype = torch.int64
15
16 # Broadcast data.
17 timers('data loader').start()
18 if data_iterator is not None:
19 data = next(data_iterator)
20 else:
21 data = None
22 timers('data loader').stop()
23 data_b = mpu.broadcast_data(keys, data, datatype)
24 # Unpack.
25 tokens = data_b['input_ids'].long()
26 labels = data_b['label'].long()
27 position_ids = data_b['position_ids'].long()
28 token_type_ids = data_b['token_type_ids'].long()
29 attention_mask = data_b['attention_mask'][:, None, None, :].float()
30
31 # Convert
32 if args.fp16:
33 attention_mask = attention_mask.half()
34
35 return tokens, labels, attention_mask, position_ids, token_type_ids, (tokens!=1)
36
37
38def forward_step(data_iterator, model, args, timers):

Callers 1

forward_stepFunction · 0.70

Calls 2

startMethod · 0.80
stopMethod · 0.80

Tested by

no test coverage detected