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

Function generate_nuclear_sampling

codegeex/megatron/code_generation_utils.py:771–798  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

769
770
771def 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
801def forward_step(

Callers

nothing calls this directly

Calls 5

get_argsFunction · 0.90
get_tokenizerFunction · 0.90
HandleClass · 0.85
expand_handlesFunction · 0.85
is_finishedMethod · 0.80

Tested by

no test coverage detected