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

Function nuclear_sampling

codegeex/megatron/code_generation_utils.py:566–576  ·  view source on GitHub ↗
(logits: torch.FloatTensor, temperature: float, top_p: float = None, top_k: int = None)

Source from the content-addressed store, hash-verified

564
565
566def nuclear_sampling(logits: torch.FloatTensor, temperature: float, top_p: float = None, top_k: int = None):
567 orig_log_probs = F.log_softmax(logits, dim=-1)
568 logits /= temperature
569 logits = top_k_logits(logits, top_k, top_p)
570 log_probs = F.softmax(logits, dim=-1)
571 tokens = torch.multinomial(log_probs, num_samples=1).view(-1)
572
573 indices = tokens.view(-1, 1)
574 new_scores = orig_log_probs.gather(1, indices).view(-1)
575
576 return tokens, new_scores
577
578
579def sample_topk_tokens(model,

Callers 1

nuclear_sample_tokensFunction · 0.85

Calls 1

top_k_logitsFunction · 0.70

Tested by

no test coverage detected