(data_iterator, args, timers)
| 9 | from bert_ft_model import ClassificationModel |
| 10 | |
| 11 | def 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 | |
| 38 | def forward_step(data_iterator, model, args, timers): |
no test coverage detected