(handles: List[Handle], temperature: float, top_p: float, top_k: int, model)
| 740 | |
| 741 | |
| 742 | def expand_handles(handles: List[Handle], temperature: float, top_p: float, top_k: int, model): |
| 743 | args = get_args() |
| 744 | tokenizer = get_tokenizer() |
| 745 | |
| 746 | context_tokens = [b.tokens.copy() for b in handles] |
| 747 | context_tokens, context_lengths = pad_batch(context_tokens, tokenizer.eod, args) |
| 748 | |
| 749 | context_lengths = set(context_lengths) |
| 750 | assert len(context_lengths) == 1, "context_lengths must be the same" |
| 751 | context_length = list(context_lengths)[0] |
| 752 | |
| 753 | context_tokens_tensor = torch.cuda.LongTensor(context_tokens) |
| 754 | tokens, attention_mask, position_ids = get_batch_(context_tokens_tensor) |
| 755 | tokens, scores = nuclear_sample_tokens(model, tokens, attention_mask, position_ids, context_length, temperature, |
| 756 | top_p, top_k) |
| 757 | tokens = tokens.detach().cpu().tolist() |
| 758 | scores = scores.detach().cpu().tolist() |
| 759 | assert len(tokens) == len(handles), "output tokens and input must have the same length" |
| 760 | |
| 761 | all_beams = [] |
| 762 | for i in range(len(handles)): |
| 763 | this_tokens = tokens[i] |
| 764 | this_scores = scores[i] |
| 765 | |
| 766 | all_beams.append(handles[i].derived(this_tokens, this_scores)) |
| 767 | |
| 768 | return all_beams |
| 769 | |
| 770 | |
| 771 | def generate_nuclear_sampling(model, context_tokens, num_samples: int, temperature: float, top_p: float, top_k: int): |
no test coverage detected