Merge remote-tracking branch 'origin/main' into qwen-image-2.1

# Conflicts:
#	vllm_omni/diffusion/executor/multiproc_executor.py
#	vllm_omni/diffusion/offloader/sequential_backend.py
This commit is contained in:
Isotr0py committed 2026-09-21 07:32:04 +00:00
commit 9174554e40
1332 files changed
+160051 -60504

No files matched your search

@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
import argparse
import functools
@@ -24,6 +24,8 @@ from vllm_omni.model_extras import (
build_text_to_image_prompt as build_model_text_to_image_prompt,
)
from vllm_omni.model_extras import (
get_ar_input_builder,
get_ar_tokenizer_validator,
get_extra_body_params,
get_model_class_name,
should_init_extra_args_for_non_diffusion_stages,
@@ -56,6 +58,7 @@ def parse_json_object(value: str, flag_name: str = "argument") -> dict[str, Any]
parse_profiler_config = functools.partial(parse_json_object, flag_name="--profiler-config")
parse_custom_pipeline_args = functools.partial(parse_json_object, flag_name="--custom-pipeline-args")
def build_text_to_image_prompt(prompt: str, negative_prompt: str | None) -> dict[str, Any]:
@@ -378,10 +381,123 @@ def parse_args() -> argparse.Namespace:
default=None,
help="Supplementary auxiliary text encoder parameters model name or path (especially for Hidream-l1-full).",
)
parser.add_argument(
"--model-class-name",
type=str,
default=None,
help="Override the diffusion pipeline class name (e.g. AnimaPipeline).",
)
parser.add_argument(
"--custom-pipeline-args",
type=parse_custom_pipeline_args,
default=None,
help='JSON object passed to native/custom pipelines (e.g. \'{"components_path": "/path"}\').',
)
parser.add_argument(
"--trust-remote-code",
action="store_true",
help="Trust and execute custom modeling code from the model repo (required by e.g. HunyuanImage-3.0).",
)
parser.add_argument(
"--allow-tokenizer-fallback",
action="store_true",
help=(
"For models with a declared ar_input_builder (e.g. HunyuanImage-3.0): if loading "
"the AR tokenizer fails, degrade to the string-prompt form (no BPE parity) instead "
"of failing the run. Off by default -- a tokenizer load failure usually means a "
"missing --trust-remote-code or a network/cache issue that's worth surfacing, not "
"silently masking with a possibly-wrong prompt."
),
)
current_omni_platform.pre_register_and_update(parser)
return parser.parse_args()
def _apply_ar_stage_inputs(
ar_input_builder: Any,
*,
model: str,
prompt_text: str,
extra_body: dict[str, Any],
num_images: int,
height: int | None,
width: int | None,
prompt_dict: dict[str, Any],
sampling_params_list: list[Any],
text_output: bool = False,
trust_remote_code: bool = False,
validate_tokenizer: Any | None = None,
allow_tokenizer_fallback: bool = False,
) -> None:
"""Apply a model's declared AR-stage inputs to the request in place.
Loads the model tokenizer (for byte-for-byte HF-parity segment
tokenization) and asks the model's ``ar_input_builder`` for the AR
prefill + stop tokens, then writes them onto ``prompt_dict`` and the
non-diffusion (AR) stage sampling params. Kept model-agnostic: the
example only knows the declared-hook contract.
``trust_remote_code`` must be threaded in from the caller's own resolved
``--trust-remote-code`` flag -- this is a separate tokenizer load outside
the main engine, so it needs the same explicit user opt-in rather than
defaulting to trusting whatever ``--model`` was passed.
``validate_tokenizer``, when the model declares one via
``get_ar_tokenizer_validator``, is called on a successfully-loaded real
tokenizer -- outside the load's try/except, so a validation failure (a
model/tokenizer revision drifting from hardcoded special-token ids)
raises instead of being swallowed into the string-prompt fallback.
``allow_tokenizer_fallback`` (default ``False``, i.e. fail fast): a
tokenizer load failure normally raises, since silently degrading to the
string-prompt form can produce a request that completes with subtly
wrong stop tokens instead of surfacing the real problem (missing
``--trust-remote-code``, network/cache issue, etc.). Set ``True`` only
for explicit unit tests or a deliberate offline-compat run where the
caller has already decided a degraded prompt is acceptable.
"""
try:
from transformers import AutoTokenizer
ar_tokenizer: Any | None = AutoTokenizer.from_pretrained(model, trust_remote_code=trust_remote_code)
except Exception as exc: # noqa: BLE001 - re-raised unless the caller opts into the fallback
if not allow_tokenizer_fallback:
raise
logger.warning(f"AR tokenizer load failed ({exc}); falling back to string prompt (no BPE parity).")
ar_tokenizer = None
if ar_tokenizer is not None and validate_tokenizer is not None:
validate_tokenizer(ar_tokenizer)
ar_inputs = ar_input_builder(
prompt=prompt_text,
tokenizer=ar_tokenizer,
extra_body=extra_body,
num_images=num_images,
height=height,
width=width,
text_output=text_output,
)
if ar_inputs.prompt_token_ids is not None:
prompt_dict["prompt_token_ids"] = ar_inputs.prompt_token_ids
elif ar_inputs.prompt is not None:
prompt_dict["prompt"] = ar_inputs.prompt
if ar_inputs.use_system_prompt:
prompt_dict["use_system_prompt"] = ar_inputs.use_system_prompt
prompt_dict["modalities"] = ar_inputs.modalities
# Apply stop_token_ids to exactly the stage(s) the builder names -- not
# "whichever stage isn't a diffusion stage," which would misfire on any
# future topology with more than one non-diffusion stage.
for stage_index in ar_inputs.stage_indices:
if stage_index >= len(sampling_params_list):
continue
stage_params = sampling_params_list[stage_index]
if not isinstance(stage_params, OmniDiffusionSamplingParams) and hasattr(stage_params, "stop_token_ids"):
stage_params.stop_token_ids = ar_inputs.stop_token_ids
def main():
args = parse_args()
generator = torch.Generator(device=current_omni_platform.device_type).manual_seed(args.seed)
@@ -456,7 +572,6 @@ def main():
"vae_patch_parallel_size": args.vae_patch_parallel_size,
"enable_expert_parallel": args.enable_expert_parallel,
"enable_cpu_offload": args.enable_cpu_offload,
"mode": "text-to-image",
"log_stats": args.log_stats,
"enable_diffusion_pipeline_profiler": args.enable_diffusion_pipeline_profiler,
"profiler_config": args.profiler_config,
@@ -470,11 +585,17 @@ def main():
omni_kwargs["tensor_parallel_size"] = args.tensor_parallel_size
if args.enforce_eager is not None:
omni_kwargs["enforce_eager"] = args.enforce_eager
if args.trust_remote_code:
omni_kwargs["trust_remote_code"] = True
if args.deploy_config:
omni_kwargs["deploy_config"] = args.deploy_config
if use_nextstep:
if args.model_class_name:
omni_kwargs["model_class_name"] = args.model_class_name
elif use_nextstep:
# NextStep-1.1 requires explicit pipeline class
omni_kwargs["model_class_name"] = "NextStep11Pipeline"
if args.custom_pipeline_args is not None:
omni_kwargs["custom_pipeline_args"] = args.custom_pipeline_args
# Cosmos3 loads its (gated) guardrail models at build time, so the guardrails
# gate is an engine-level config (offline analog of the server's --no-guardrails).
if args.extra_body and "guardrails" in args.extra_body:
@@ -510,6 +631,10 @@ def main():
print(f" LoRA: scale={args.lora_scale}")
if args.deploy_config:
print(f" deploy-config: {args.deploy_config}")
if args.model_class_name:
print(f" Model class name: {args.model_class_name}")
if args.custom_pipeline_args is not None:
print(f" Custom pipeline args: {args.custom_pipeline_args}")
print(f"{'=' * 60}\n")
# Build LoRA request when --lora-path is set
@@ -614,6 +739,30 @@ def main():
if not diffusion_replaced and len(sampling_params_list) == 1:
sampling_params_list = [diffusion_params]
# Models with an AR text stage (e.g. HunyuanImage3) declare an
# ar_input_builder. When present, build the AR prefill token-ids and AR
# stop-token-ids declaratively from the plain prompt + extra_body, so this
# example stays model-agnostic. Models without one are untouched.
ar_input_builder = get_ar_input_builder(model_class_name)
# A model can also be deployed with only its diffusion stage. Keep those
# requests on the string-prompt path, as in the single-stage images API.
has_ar_stage = any(not isinstance(params, OmniDiffusionSamplingParams) for params in sampling_params_list)
if ar_input_builder is not None and has_ar_stage:
_apply_ar_stage_inputs(
ar_input_builder,
model=args.model,
prompt_text=args.prompt,
extra_body=user_extra,
num_images=0,
height=args.height,
width=args.width,
prompt_dict=prompt_dict,
sampling_params_list=sampling_params_list,
trust_remote_code=args.trust_remote_code,
validate_tokenizer=get_ar_tokenizer_validator(model_class_name),
allow_tokenizer_fallback=args.allow_tokenizer_fallback,
)
outputs = omni.generate(prompt_dict, sampling_params_list=sampling_params_list)
generation_end = time.perf_counter()