MCPcopy Create free account
hub / github.com/csuhan/OneLLM / sample_top_p

Method sample_top_p

model/meta.py:164–172  ·  view source on GitHub ↗
(self, probs, p)

Source from the content-addressed store, hash-verified

162 yield {"text": self.tokenizer.decode(tokens[start_pos:generate_until].tolist()), "end_of_content": True}
163
164 def sample_top_p(self, probs, p):
165 probs_sort, probs_idx = torch.sort(probs, dim=-1, descending=True)
166 probs_sum = torch.cumsum(probs_sort, dim=-1)
167 mask = probs_sum - probs_sort > p
168 probs_sort[mask] = 0.0
169 probs_sort.div_(probs_sort.sum(dim=-1, keepdim=True))
170 next_token = torch.multinomial(probs_sort, num_samples=1)
171 next_token = torch.gather(probs_idx, -1, next_token)
172 return next_token
173
174 def get_image_words(self):
175 return self.llma.image_words

Callers 2

generateMethod · 0.95
stream_generateMethod · 0.95

Calls 1

cumsumMethod · 0.80

Tested by

no test coverage detected