Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions examples/offline_inference/bagel/end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import os

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():
Expand Down Expand Up @@ -171,15 +174,19 @@ def main():
elif args.modality == "img2text":
if args.image_path:
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": final_prompt_text,
"multi_modal_data": {"image": loaded_image},
"modalities": ["text"],
}
formatted_prompts.append(prompt_dict)
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 ""
Comment thread
hsliuustc0106 marked this conversation as resolved.
final_prompt_text = f"{think_prefix}<|im_start|>{p}<|im_end|><|im_start|>"
Comment thread
princepride marked this conversation as resolved.
Comment thread
hsliuustc0106 marked this conversation as resolved.
Comment thread
princepride marked this conversation as resolved.
prompt_dict = {"prompt": final_prompt_text, "modalities": ["text"]}
formatted_prompts.append(prompt_dict)
else:
Expand Down Expand Up @@ -217,15 +224,11 @@ def main():
img_idx = 0
for req_output in omni_outputs:
if args.think:
text_output = getattr(req_output, "text", None) or getattr(req_output, "outputs", None)
if text_output:
if isinstance(text_output, list) and text_output:
for out in text_output:
txt = getattr(out, "text", str(out))
if txt:
print(f"[Think] {txt}")
elif isinstance(text_output, str):
print(f"[Think] {text_output}")
ro = getattr(req_output, "request_output", None)
Comment thread
princepride marked this conversation as resolved.
if ro and getattr(ro, "outputs", None):
txt = "".join(getattr(o, "text", "") or "" for o in ro.outputs)
if txt:
print(txt)

images = getattr(req_output, "images", None)

Expand Down
7 changes: 7 additions & 0 deletions vllm_omni/model_executor/stage_input_processors/bagel.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def expand_cfg_prompts(
"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(
prompt: dict[str, Any] | str,
Expand Down
Loading