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

Function nuclear_sample_tokens

codegeex/megatron/code_generation_utils.py:600–617  ·  view source on GitHub ↗
(model,
                          input_tokens, attention_mask, position_ids,
                          context_length: int, temperature: float, top_p: float, top_k: int)

Source from the content-addressed store, hash-verified

598
599
600def 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

Callers 1

expand_handlesFunction · 0.85

Calls 3

nuclear_samplingFunction · 0.85
forward_stepFunction · 0.70
evalMethod · 0.45

Tested by

no test coverage detected