(self, message, dataset=None)
| 25 | self.processor = processor |
| 26 | |
| 27 | def generate_inner(self, message, dataset=None): |
| 28 | content, images = '', [] |
| 29 | for x in message: |
| 30 | if x['type'] == 'text': |
| 31 | content += x['value'] |
| 32 | elif x['type'] == 'image': |
| 33 | content += '<image>\n' |
| 34 | images.append(Image.open(x['value'])) |
| 35 | |
| 36 | inputs = self.processor( |
| 37 | text=[content], |
| 38 | images=images, |
| 39 | padding=True, |
| 40 | return_tensors='pt' |
| 41 | ).to(device='cuda', dtype=torch.bfloat16) |
| 42 | generate_ids = self.model.generate(**inputs, max_new_tokens=2048) |
| 43 | input_token_len = inputs.input_ids.shape[1] |
| 44 | text = self.processor.batch_decode( |
| 45 | generate_ids[:, input_token_len:], |
| 46 | skip_special_tokens=True, |
| 47 | clean_up_tokenization_spaces=False |
| 48 | )[0] |
| 49 | return text |
nothing calls this directly
no test coverage detected