(model,
input_tokens, attention_mask, position_ids,
context_length: int, temperature: float, top_p: float, top_k: int)
| 598 | |
| 599 | |
| 600 | def nuclear_sample_tokens(model, |
| 601 | input_tokens, attention_mask, position_ids, |
| 602 | context_length: int, temperature: float, top_p: float, top_k: int): |
| 603 | assert context_length < input_tokens.shape[-1], "context_length must be smaller than seq_length" |
| 604 | |
| 605 | model.eval() |
| 606 | with torch.no_grad(): |
| 607 | output = forward_step( |
| 608 | model, |
| 609 | input_tokens, |
| 610 | position_ids, |
| 611 | attention_mask, |
| 612 | tokentype_ids=None, |
| 613 | forward_method_parallel_output=False, |
| 614 | ) |
| 615 | assert output is not None |
| 616 | logits = output[:, context_length - 1, :] |
| 617 | return nuclear_sampling(logits, temperature, top_p, top_k) |
| 618 | |
| 619 | |
| 620 | @dataclass |
no test coverage detected