Generate batch from context tokens.
(context_tokens)
| 30 | |
| 31 | |
| 32 | def get_batch(context_tokens): |
| 33 | """Generate batch from context tokens.""" |
| 34 | args = get_args() |
| 35 | tokenizer = get_tokenizer() |
| 36 | |
| 37 | # Move to GPU. |
| 38 | tokens = context_tokens.view(args.batch_size, -1).contiguous().cuda() |
| 39 | # Get the attention mask and postition ids. |
| 40 | attention_mask, _, position_ids = get_ltor_masks_and_position_ids( |
| 41 | tokens, |
| 42 | tokenizer.eod, |
| 43 | args.reset_position_ids, |
| 44 | args.reset_attention_mask, |
| 45 | args.eod_mask_loss) |
| 46 | |
| 47 | return tokens, attention_mask, position_ids |
| 48 | |
| 49 | |
| 50 | def top_k_logits(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')): |
no test coverage detected