Beam search. Note that this function does not support model parallel!
(model, context_tokens, num_samples: int, temperature: float, top_p: float, top_k: int)
| 769 | |
| 770 | |
| 771 | def generate_nuclear_sampling(model, context_tokens, num_samples: int, temperature: float, top_p: float, top_k: int): |
| 772 | """Beam search. |
| 773 | |
| 774 | Note that this function does not support model parallel! |
| 775 | """ |
| 776 | args = get_args() |
| 777 | tokenizer = get_tokenizer() |
| 778 | |
| 779 | assert not isinstance(context_tokens[0], list), "batched beam search not supported" |
| 780 | |
| 781 | handles = [Handle(tokens=context_tokens, score=0) for _ in range(num_samples)] |
| 782 | context_len = len(context_tokens) |
| 783 | finished_handles = [] |
| 784 | |
| 785 | while len(handles) > 0 and context_len < args.seq_length: |
| 786 | expanded_handles = expand_handles(handles, temperature, top_p, top_k, model) |
| 787 | |
| 788 | new_handles = [] |
| 789 | for h in expanded_handles: |
| 790 | if h.is_finished(): |
| 791 | finished_handles.append(h) |
| 792 | else: |
| 793 | new_handles.append(h) |
| 794 | |
| 795 | context_len += 1 |
| 796 | handles = new_handles |
| 797 | |
| 798 | return handles + finished_handles |
| 799 | |
| 800 | |
| 801 | def forward_step( |
nothing calls this directly
no test coverage detected