MCPcopy Index your code
hub / github.com/zai-org/CodeGeeX / expand_handles

Function expand_handles

codegeex/megatron/code_generation_utils.py:742–768  ·  view source on GitHub ↗
(handles: List[Handle], temperature: float, top_p: float, top_k: int, model)

Source from the content-addressed store, hash-verified

740
741
742def 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
771def generate_nuclear_sampling(model, context_tokens, num_samples: int, temperature: float, top_p: float, top_k: int):

Callers 1

Calls 6

get_argsFunction · 0.90
get_tokenizerFunction · 0.90
get_batch_Function · 0.85
nuclear_sample_tokensFunction · 0.85
derivedMethod · 0.80
pad_batchFunction · 0.70

Tested by

no test coverage detected