Fix multimodal synthetic benchmark prompt generation to exclude special tokens (#26864)

Co-authored-by: Xinyuan Tong <115166877+JustinTong0323@users.noreply.github.com>
This commit is contained in:
Bowen Wang
2026-06-04 22:27:43 +00:00
committed by GitHub
co-authored by Xinyuan Tong
parent 0e4aa081ba
commit 07f326c184
2 changed files with 47 additions and 4 deletions
+14 -3
View File
@@ -81,10 +81,21 @@ def gen_prompt(tokenizer, token_num):
return tokenizer.decode(selected_tokens)
@lru_cache(maxsize=1)
def get_available_multimodal_text_tokens(tokenizer, image_pad_id):
"""Get valid token ids for synthetic multimodal text prompts."""
excluded_token_ids = set(getattr(tokenizer, "all_special_ids", []) or [])
if image_pad_id is not None:
excluded_token_ids.add(image_pad_id)
return [
token_id
for token_id in get_available_tokens(tokenizer)
if token_id not in excluded_token_ids
]
def gen_mm_prompt(tokenizer, image_pad_id, token_num):
"""Generate a random prompt of specified token length using tokenizer vocabulary."""
all_available_tokens = list(tokenizer.get_vocab().values())
if image_pad_id:
all_available_tokens.remove(image_pad_id)
all_available_tokens = get_available_multimodal_text_tokens(tokenizer, image_pad_id)
selected_tokens = random.choices(all_available_tokens, k=token_num)
return tokenizer.decode(selected_tokens)