Generate a batch
(data_iterator)
| 55 | |
| 56 | |
| 57 | def get_batch(data_iterator): |
| 58 | """Generate a batch""" |
| 59 | args = get_args() |
| 60 | tokenizer = get_tokenizer() |
| 61 | |
| 62 | # Items and their type. |
| 63 | keys = ['text'] |
| 64 | datatype = torch.int64 |
| 65 | |
| 66 | # Broadcast data. |
| 67 | if data_iterator is not None: |
| 68 | data = next(data_iterator) |
| 69 | else: |
| 70 | data = None |
| 71 | data_b = mpu.broadcast_data(keys, data, datatype) |
| 72 | |
| 73 | # Unpack. |
| 74 | tokens_ = data_b['text'].long() |
| 75 | labels = tokens_[:, 1:].contiguous() |
| 76 | tokens = tokens_[:, :-1].contiguous() |
| 77 | |
| 78 | # Get the masks and postition ids. |
| 79 | attention_mask, loss_mask, position_ids = get_ltor_masks_and_position_ids( |
| 80 | tokens, |
| 81 | tokenizer.eod, |
| 82 | args.reset_position_ids, |
| 83 | args.reset_attention_mask, |
| 84 | args.eod_mask_loss) |
| 85 | |
| 86 | return tokens, labels, loss_mask, attention_mask, position_ids |
| 87 | |
| 88 | |
| 89 | def forward_step(data_iterator, model): |
no test coverage detected