Skip to content

Commit a058294

Browse files
committed
[wwb] Add to vlm chat pipeline support of GenAI supported models
1 parent ca2104f commit a058294

3 files changed

Lines changed: 669 additions & 38 deletions

File tree

tools/who_what_benchmark/whowhatbench/chat_visualtext_evaluator.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
import json
5+
import torch
56
import numpy as np
67
import pandas as pd
78
from tqdm import tqdm
@@ -187,7 +188,14 @@ def default_gen_answer(
187188
# The output tuple has format (<list of decoded outputs without question/prompt>, <GenerateDecoderOnlyOutput>)
188189
answer_text = tokens[0][0]
189190
else:
190-
answer_tokens = tokens[:, preprocess_inputs["input_ids"].shape[-1] :]
191+
# Some models includes the input_ids in the generated tokens, some - not, so we need to check and remove them if needed
192+
inputs_num = preprocess_inputs["input_ids"].shape[-1]
193+
if tokens.shape[-1] > inputs_num and torch.equal(
194+
tokens[:, :inputs_num], preprocess_inputs["input_ids"]
195+
):
196+
answer_tokens = tokens[:, preprocess_inputs["input_ids"].shape[-1] :]
197+
else:
198+
answer_tokens = tokens
191199
answer_text = tokenizer.batch_decode(answer_tokens, skip_special_tokens=True)[0]
192200

193201
inputs_processor.update_chat_history_with_answer(answer_text)

0 commit comments

Comments
 (0)