MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / sample_topk_tokens

Function sample_topk_tokens

codegeex/megatron/code_generation_utils.py:579–597  ·  view source on GitHub ↗
(model,
                       input_tokens, attention_mask, position_ids,
                       context_length: int, num_samples: int)

Source from the content-addressed store, hash-verified

577
578
579def sample_topk_tokens(model,
580 input_tokens, attention_mask, position_ids,
581 context_length: int, num_samples: int):
582 assert context_length < input_tokens.shape[-1], "context_length must be smaller than seq_length"
583
584 model.eval()
585 with torch.no_grad():
586 output = forward_step(
587 model,
588 input_tokens,
589 position_ids,
590 attention_mask,
591 tokentype_ids=None,
592 forward_method_parallel_output=False,
593 )
594 assert output is not None
595 logits = output[:, context_length - 1, :]
596
597 return topk_sampling(logits, num_samples)
598
599
600def nuclear_sample_tokens(model,

Callers 1

expand_beamsFunction · 0.85

Calls 3

topk_samplingFunction · 0.85
forward_stepFunction · 0.70
evalMethod · 0.45

Tested by

no test coverage detected