MCPcopy
hub / github.com/open-compass/VLMEvalKit / generate_inner

Method generate_inner

vlmeval/vlm/chameleon.py:27–49  ·  view source on GitHub ↗
(self, message, dataset=None)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

batch_decodeMethod · 0.80
generateMethod · 0.45

Tested by

no test coverage detected