MCPcopy Create free account
hub / github.com/FunAudioLLM/FunMusic / topk_sampling

Function topk_sampling

inspiremusic/utils/common.py:147–151  ·  view source on GitHub ↗
(weighted_scores, decoded_tokens, top_k=25)

Source from the content-addressed store, hash-verified

145 # Sample top-p tokens from the distribution
146 return random_sampling(selected_weighted_scores, decoded_tokens)
147def topk_sampling(weighted_scores, decoded_tokens, top_k=25):
148 zeros = weighted_scores.new_ones(weighted_scores.shape) * float('-inf')
149 values,indices = torch.topk(weighted_scores,top_k)
150 zeros.scatter_(-1, indices, values)
151 return random_sampling(zeros,decoded_tokens)
152
153# Repetition Aware Sampling in VALL-E 2
154

Callers

nothing calls this directly

Calls 1

random_samplingFunction · 0.85

Tested by

no test coverage detected