Process batch and produce inputs for the model.
(batch)
| 56 | |
| 57 | |
| 58 | def process_batch(batch): |
| 59 | """Process batch and produce inputs for the model.""" |
| 60 | args = get_args() |
| 61 | tokenizer = get_tokenizer() |
| 62 | |
| 63 | loss_mask = batch['pad_mask'].long().cuda().contiguous().byte() |
| 64 | tokens_ = batch['text'].long().cuda().contiguous() |
| 65 | labels = tokens_[:, 1:].contiguous() |
| 66 | tokens = tokens_[:, :-1].contiguous() |
| 67 | |
| 68 | # Get the masks and postition ids. |
| 69 | attention_mask, _, position_ids = get_ltor_masks_and_position_ids( |
| 70 | tokens, |
| 71 | tokenizer.eod, |
| 72 | args.reset_position_ids, |
| 73 | args.reset_attention_mask, |
| 74 | args.eod_mask_loss) |
| 75 | |
| 76 | return tokens, labels, attention_mask, position_ids, loss_mask |
| 77 | |
| 78 | |
| 79 | def forward_step(batch, model, eval_metric): |
no test coverage detected