(self, probs, p)
| 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 |
no test coverage detected