[Feature] Bagel: Support tp+cfg parallel using mooncake transfer engine connector (#2705)

Signed-off-by: natureofnature <wzliu@connect.hku.hk>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
NATUREandHongsheng Liu authored and GitHub committed 2026-04-16 16:25:13 +08:00
1 parent 24e61f4d7b
commit 4d816ff1de
12 files changed
+1846 -266

No files matched your search

+44 -9
View File
@@ -86,6 +86,7 @@ from vllm_omni.entrypoints.openai.image_api_utils import validate_layered_layers
from vllm_omni.entrypoints.openai.protocol import OmniChatCompletionStreamResponse
from vllm_omni.entrypoints.openai.protocol.audio import AudioResponse, CreateAudio
from vllm_omni.entrypoints.openai.utils import (
get_stage_type,
get_supported_speakers_from_hf_config,
parse_lora_request,
validate_requested_speaker,
@@ -294,6 +295,8 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
)
num_inference_steps = None
cfg_text_scale = None
cfg_img_scale = None
# Omni multistage image generation: Stage-0 (AR) should receive a clean
# text prompt (and optional conditioning image/size) so the model's own
# processor can construct the correct inputs.
@@ -342,6 +345,8 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
except Exception:
pass
negative_prompt = extra_body.get("negative_prompt")
cfg_text_scale = extra_body.get("cfg_text_scale")
cfg_img_scale = extra_body.get("cfg_img_scale")
engine_prompt_image: dict[str, Any] | None = None
is_img2img = False
@@ -397,14 +402,18 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
sampling_params_list = self._build_sampling_params_list_from_request(request)
# Apply user-specified overrides to diffusion stage(s) for image generation
if _image_gen_height is not None or _image_gen_width is not None or num_inference_steps is not None:
for idx, sp in enumerate(sampling_params_list):
if hasattr(sp, "height") and _image_gen_height is not None:
sp.height = _image_gen_height
if hasattr(sp, "width") and _image_gen_width is not None:
sp.width = _image_gen_width
if hasattr(sp, "num_inference_steps") and num_inference_steps is not None:
sp.num_inference_steps = num_inference_steps
for idx, sp in enumerate(sampling_params_list):
if hasattr(sp, "height") and _image_gen_height is not None:
sp.height = _image_gen_height
if hasattr(sp, "width") and _image_gen_width is not None:
sp.width = _image_gen_width
if hasattr(sp, "num_inference_steps") and num_inference_steps is not None:
sp.num_inference_steps = num_inference_steps
if hasattr(sp, "extra_args") and sp.extra_args is not None:
if cfg_text_scale is not None:
sp.extra_args["cfg_text_scale"] = cfg_text_scale
if cfg_img_scale is not None:
sp.extra_args["cfg_img_scale"] = cfg_img_scale
self._log_inputs(
request_id,
@@ -2108,6 +2117,8 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
num_inference_steps = extra_body.get("num_inference_steps")
guidance_scale = extra_body.get("guidance_scale")
true_cfg_scale = extra_body.get("true_cfg_scale") or extra_body.get("cfg_scale")
cfg_text_scale = extra_body.get("cfg_text_scale")
cfg_img_scale = extra_body.get("cfg_img_scale")
seed = extra_body.get("seed")
negative_prompt = extra_body.get("negative_prompt")
num_outputs_per_prompt = extra_body.get("num_outputs_per_prompt", 1)
@@ -2162,6 +2173,10 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
gen_params.guidance_scale = guidance_scale
if true_cfg_scale is not None:
gen_params.true_cfg_scale = true_cfg_scale
if cfg_text_scale is not None:
gen_params.extra_args["cfg_text_scale"] = cfg_text_scale
if cfg_img_scale is not None:
gen_params.extra_args["cfg_img_scale"] = cfg_img_scale
if num_frames is not None:
gen_params.num_frames = num_frames
if guidance_scale_2 is not None:
@@ -2206,10 +2221,30 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
# Generate image
diffusion_engine = cast(AsyncOmni, self._diffusion_engine)
stage_configs = list(getattr(diffusion_engine, "stage_configs", []) or [])
default_params_list = list(getattr(diffusion_engine, "default_sampling_params_list", []) or [])
sampling_params_list: list[Any] = []
for idx, stage_cfg in enumerate(stage_configs):
if get_stage_type(stage_cfg) == "diffusion":
sampling_params_list.append(gen_params)
continue
default_stage_params = default_params_list[idx] if idx < len(default_params_list) else SamplingParams()
if hasattr(default_stage_params, "clone"):
try:
default_stage_params = default_stage_params.clone()
except Exception:
pass
sampling_params_list.append(default_stage_params)
if not sampling_params_list:
sampling_params_list = [gen_params]
result = None
async for output in diffusion_engine.generate(
prompt=gen_prompt,
sampling_params_list=[gen_params], # Pass as single-stage params
sampling_params_list=sampling_params_list,
request_id=request_id,
):
result = output