(model,
input_tokens, attention_mask, position_ids,
context_length: int, num_samples: int)
| 577 | |
| 578 | |
| 579 | def sample_topk_tokens(model, |
| 580 | input_tokens, attention_mask, position_ids, |
| 581 | context_length: int, num_samples: int): |
| 582 | assert context_length < input_tokens.shape[-1], "context_length must be smaller than seq_length" |
| 583 | |
| 584 | model.eval() |
| 585 | with torch.no_grad(): |
| 586 | output = forward_step( |
| 587 | model, |
| 588 | input_tokens, |
| 589 | position_ids, |
| 590 | attention_mask, |
| 591 | tokentype_ids=None, |
| 592 | forward_method_parallel_output=False, |
| 593 | ) |
| 594 | assert output is not None |
| 595 | logits = output[:, context_length - 1, :] |
| 596 | |
| 597 | return topk_sampling(logits, num_samples) |
| 598 | |
| 599 | |
| 600 | def nuclear_sample_tokens(model, |
no test coverage detected