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:
commit
9174554e40
1332 files changed
+160051
-60504
No files matched your search
@@ -19,23 +19,23 @@ This folder provides several entrypoints for experimenting with text-to-image di
|
||||
|
||||
### Supported Models
|
||||
|
||||
| Model | Image Shape | Peak VRAM (GiB) * | Model Weights (GiB) |
|
||||
| Model | Image Shape | Peak VRAM (GiB) * | Model Weights (GiB) |
|
||||
| ----- | ----------- | ----------- | ----------------- |
|
||||
| `Qwen/Qwen-Image` | 1024 x 1024 | 60.0 | 53.7 |
|
||||
| `Qwen/Qwen-Image-2512` |1024 x 1024 | 60.0 | 53.7 |
|
||||
| `Qwen/Qwen-Image-2512` | 1024 x 1024 | 60.0 | 53.7 |
|
||||
| `Tongyi-MAI/Z-Image-Turbo` | 1024 x 1024 | 24.8 | 19.2 |
|
||||
| `stepfun-ai/NextStep-1.1` | 512 x 512 | 71.8 | 28.1 |
|
||||
| `meituan-longcat/LongCat-Image` | 1024 x 1024 | 71.2 | 27.3 |
|
||||
| `AIDC-AI/Ovis-Image-7B` | 1024 x 1024 | 71.8 | 17.1 |
|
||||
| `OmniGen2/OmniGen2` | 1024 x 1024 | 20.1 | 14.7 |
|
||||
| `OmniGen2/OmniGen2` | 1024 x 1024 | 20.1 | 14.7 |
|
||||
| `stabilityai/stable-diffusion-3.5-medium` | 1024 x 1024 | 20.1 | 15.6 |
|
||||
| `black-forest-labs/FLUX.1-dev` | 1024 x 1024 | 33.9 | 31.4 |
|
||||
| `black-forest-labs/FLUX.1-schnell` | 1024 x 1024 | 33.9 | 31.4 |
|
||||
| `black-forest-labs/FLUX.2-klein-4B` | 1024 x 1024 | 72.7 | 14.9 |
|
||||
| `black-forest-labs/FLUX.2-klein-9B` | 1024 x 1024 | 37.1 | 32.3 |
|
||||
| `black-forest-labs/FLUX.2-dev` | 1024 x 1024 | 65.7 | >80 (CPU offload required) |
|
||||
| `HunyuanImage-3.0` | 1024 x 1024 | 80.0 (TP≥3) | 160 |
|
||||
| `HiDream-I1-Full` | 1024 x 1024 | 63.7 | 57.7 |
|
||||
| `HunyuanImage-3.0` | 1024 x 1024 | 80.0 (TP≥3) | 160 |
|
||||
| `HiDream-I1-Full` | 1024 x 1024 | 63.7 | 57.7 |
|
||||
| `krea/Krea-2-Raw`, `krea/Krea-2-Turbo` | 1024 (Raw) / 2048 (Turbo) | — | ~30 |
|
||||
|
||||
!!! info
|
||||
@@ -112,9 +112,9 @@ python text_to_image.py \
|
||||
| `--enable-cpu-offload` | flag | off | Enable CPU offloading for diffusion models |
|
||||
| `--lora-path` | str | — | Path to PEFT LoRA adapter folder or checkpoint file |
|
||||
| `--lora-scale` | float | `1.0` | Scale factor for LoRA weights |
|
||||
| `--lora-backend` | str |`"peft"`| LoRA backend for loading LoRA adapters. Default: peft. Available options: peft, distill |
|
||||
| `--use-system-prompt` | str | `None` | System prompt preset: `en_unified`, `en_vanilla`, `en_recaption`, `en_think_recaption`, `dynamic`, `None`, or custom text. Recommended: `en_unified`. Only for HunyuanImage-3.0.|
|
||||
| `--system-prompt` | str | `None` | Custom system prompt text. Only used when `--use-system-prompt` is set to `custom`. Only for HunyuanImage-3.0.|
|
||||
| `--lora-backend` | str | `"peft"` | LoRA backend for loading LoRA adapters. Default: peft. Available options: peft, distill |
|
||||
| `--use-system-prompt` | str | `None` | System prompt preset: `en_unified`, `en_vanilla`, `en_recaption`, `en_think_recaption`, `dynamic`, `None`, or custom text. Recommended: `en_unified`. Only for HunyuanImage-3.0. |
|
||||
| `--system-prompt` | str | `None` | Custom system prompt text. Only used when `--use-system-prompt` is set to `custom`. Only for HunyuanImage-3.0. |
|
||||
| `--auxiliary-text-encoder` | str | `None` | Supplementary auxiliary text encoder parameters model name or path (especially for Hidream-l1-full). |
|
||||
|
||||
**NextStep-1.1 specific arguments:**
|
||||
@@ -127,7 +127,7 @@ python text_to_image.py \
|
||||
| `--use-norm` | flag | off | Apply layer normalization to sampled tokens |
|
||||
|
||||
> If you encounter OOM errors, try using `--vae-use-slicing` and `--vae-use-tiling` to reduce memory usage.
|
||||
|
||||
>
|
||||
> Qwen-Image currently publishes best-effort presets at `1328x1328`, `1664x928`, `928x1664`, `1472x1140`, `1140x1472`, `1584x1056`, and `1056x1584`. Adjust `--height/--width` accordingly for the most reliable outcomes.
|
||||
|
||||
## More CLI Examples
|
||||
@@ -216,6 +216,26 @@ python examples/offline_inference/text_to_image/text_to_image.py \
|
||||
--output /output.png
|
||||
```
|
||||
|
||||
### Anima Single-File Checkpoints
|
||||
|
||||
Anima uses the official model dimensions by default. A checkpoint may provide a JSON file with the same stem (for example, `anima.json` beside `anima.safetensors`) containing `transformer` and `text_conditioner` configuration objects. These override the default dimensions and must match the checkpoint weights. The shared tiny-model tests use this to load small random-weight models. Components in `text_encoder/`, `vae/`, `tokenizer/`, `t5_tokenizer/`, and `scheduler/` beside the checkpoint are discovered automatically.
|
||||
|
||||
To load Anima, point `--model` to the single-file checkpoint path, pass the native pipeline class name using `--model-class-name`, and supply the converted components directory using `--custom-pipeline-args`:
|
||||
|
||||
```bash
|
||||
python examples/offline_inference/text_to_image/text_to_image.py \
|
||||
--model /path/to/models/anima-official/split_files/diffusion_models/anima-base-v1.0.safetensors \
|
||||
--model-class-name AnimaPipeline \
|
||||
--custom-pipeline-args '{"components_path": "/path/to/models/anima-components"}' \
|
||||
--prompt "A cinematic close-up of a glass teapot on a wooden table." \
|
||||
--seed 42 \
|
||||
--guidance-scale 4.0 \
|
||||
--num-inference-steps 50 \
|
||||
--height 1024 \
|
||||
--width 1024 \
|
||||
--output anima_output.png
|
||||
```
|
||||
|
||||
### Krea 2
|
||||
|
||||
Krea 2 is published as diffusers-format checkpoints: `krea/Krea-2-Turbo` (few-step distilled) and `krea/Krea-2-Raw`.
|
||||
@@ -336,7 +356,7 @@ python text_to_image.py \
|
||||
|
||||
LoRA adapters must be in PEFT format. A typical adapter directory structure:
|
||||
|
||||
```
|
||||
```text
|
||||
lora_adapter/
|
||||
├── adapter_config.json
|
||||
└── adapter_model.safetensors
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user