[BugFix] Add bagel text2text/img2text think mode support (#2503)
Signed-off-by: princepride <wangzhipeng628@gmail.com>
This commit is contained in:
2 files changed
+22
-12
No files matched your search
@@ -2,7 +2,10 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from vllm_omni.inputs.data import OmniPromptType
|
from vllm_omni.inputs.data import OmniPromptType
|
||||||
from vllm_omni.model_executor.stage_input_processors.bagel import GEN_THINK_SYSTEM_PROMPT
|
from vllm_omni.model_executor.stage_input_processors.bagel import (
|
||||||
|
GEN_THINK_SYSTEM_PROMPT,
|
||||||
|
VLM_THINK_SYSTEM_PROMPT,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
@@ -171,7 +174,10 @@ def main():
|
|||||||
elif args.modality == "img2text":
|
elif args.modality == "img2text":
|
||||||
if args.image_path:
|
if args.image_path:
|
||||||
loaded_image = Image.open(args.image_path).convert("RGB")
|
loaded_image = Image.open(args.image_path).convert("RGB")
|
||||||
final_prompt_text = f"<|im_start|>user\n<|image_pad|>\n{p}<|im_end|>\n<|im_start|>assistant\n"
|
think_prefix = f"<|im_start|>system\n{VLM_THINK_SYSTEM_PROMPT}<|im_end|>\n" if args.think else ""
|
||||||
|
final_prompt_text = (
|
||||||
|
f"{think_prefix}<|im_start|>user\n<|image_pad|>\n{p}<|im_end|>\n<|im_start|>assistant\n"
|
||||||
|
)
|
||||||
prompt_dict = {
|
prompt_dict = {
|
||||||
"prompt": final_prompt_text,
|
"prompt": final_prompt_text,
|
||||||
"multi_modal_data": {"image": loaded_image},
|
"multi_modal_data": {"image": loaded_image},
|
||||||
@@ -179,7 +185,8 @@ def main():
|
|||||||
}
|
}
|
||||||
formatted_prompts.append(prompt_dict)
|
formatted_prompts.append(prompt_dict)
|
||||||
elif args.modality == "text2text":
|
elif args.modality == "text2text":
|
||||||
final_prompt_text = f"<|im_start|>user\n{p}<|im_end|>\n<|im_start|>assistant\n"
|
think_prefix = f"<|im_start|>{VLM_THINK_SYSTEM_PROMPT}<|im_end|>" if args.think else ""
|
||||||
|
final_prompt_text = f"{think_prefix}<|im_start|>{p}<|im_end|><|im_start|>"
|
||||||
prompt_dict = {"prompt": final_prompt_text, "modalities": ["text"]}
|
prompt_dict = {"prompt": final_prompt_text, "modalities": ["text"]}
|
||||||
formatted_prompts.append(prompt_dict)
|
formatted_prompts.append(prompt_dict)
|
||||||
else:
|
else:
|
||||||
@@ -217,15 +224,11 @@ def main():
|
|||||||
img_idx = 0
|
img_idx = 0
|
||||||
for req_output in omni_outputs:
|
for req_output in omni_outputs:
|
||||||
if args.think:
|
if args.think:
|
||||||
text_output = getattr(req_output, "text", None) or getattr(req_output, "outputs", None)
|
ro = getattr(req_output, "request_output", None)
|
||||||
if text_output:
|
if ro and getattr(ro, "outputs", None):
|
||||||
if isinstance(text_output, list) and text_output:
|
txt = "".join(getattr(o, "text", "") or "" for o in ro.outputs)
|
||||||
for out in text_output:
|
if txt:
|
||||||
txt = getattr(out, "text", str(out))
|
print(txt)
|
||||||
if txt:
|
|
||||||
print(f"[Think] {txt}")
|
|
||||||
elif isinstance(text_output, str):
|
|
||||||
print(f"[Think] {text_output}")
|
|
||||||
|
|
||||||
images = getattr(req_output, "images", None)
|
images = getattr(req_output, "images", None)
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,13 @@ GEN_THINK_SYSTEM_PROMPT = (
|
|||||||
"i.e. <think> planning process here </think> image here"
|
"i.e. <think> planning process here </think> image here"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
VLM_THINK_SYSTEM_PROMPT = (
|
||||||
|
"You should first think about the reasoning process in the mind "
|
||||||
|
"and then provide the user with the answer. \n"
|
||||||
|
"The reasoning process is enclosed within <think> </think> tags, "
|
||||||
|
"i.e. <think> reasoning process here </think> answer here"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def expand_cfg_prompts_think(
|
def expand_cfg_prompts_think(
|
||||||
prompt: dict[str, Any] | str,
|
prompt: dict[str, Any] | str,
|
||||||
|
|||||||
Reference in new issue
Block a user