[Lance] Add Gradio demo and align inference with upstream

- Add ``examples/offline_inference/lance/gradio_demo.py`` — a unified 7-task UI
  (t2i / t2v / i2v / image_edit / video_edit / x2t_image / x2t_video) that
  loads ``Lance_3B`` and ``Lance_3B_Video`` on two GPUs so image and video
  tasks run concurrently.  Surfaces official Lance examples per task; aspect
  ratio is auto-snapped to one of upstream's 6 buckets from the input
  image/video.
- Fix x2t_image / x2t_video output format: route x2t_image through a new
  ``_forward_x2t_image`` handler (was falling through to the img2img path
  and emitting garbage), build the chat prefill in three segments
  (prefix → ViT → suffix) so the ``<|im_end|>`` markers line up with
  upstream's template, and start generation from a newline token instead of
  ``<|im_start|>`` so the assistant turn doesn't close itself with an
  immediate EOS.  Add a ``system_prompt`` override to ``render_lance_prompt``
  so per-example QA instructions surface ("Look at the image carefully and
  answer the question.") instead of the caption-style default.
- ``_forward_image_edit``: also stash the PIL image into ``custom_output``
  so callers reading ``outputs[0].output`` *or* ``custom_output["image"]``
  both work — the orchestrator IPC strips the bare ``output`` field across
  process boundaries.
- ``pipeline_registry.py``, ``model_executor/models/lance/*``, registry
  cleanup: remove the dead Lance-specific autoregressive shim
  (``lance.py``) and its stage-input processor; the diffusion pipeline owns
  the full flow now.
- Aspect-ratio buckets aligned with upstream's ``BucketResize`` (6 ratios:
  21:9 / 16:9 / 4:3 / 1:1 / 3:4 / 9:16, sized for ``resolution_vae`` ∈
  {480, 640, 768}).  3:2 / 2:3 dropped — upstream snaps those to 4:3 / 3:4.
- Gradio defaults match upstream's official scripts (cfg_text_scale=4.0,
  validation_num_timesteps=30, validation_timestep_shift=3.5, seed=42); only
  the demo *duration* is intentionally shorter than upstream's 121-frame
  default to keep the UI snappy (user can extend to 10s via slider for
  byte-identical reproduction).

Signed-off-by: lishunyang12 <lishunyang12@163.com>

Signed-off-by: WeiQing Chen <david6666666@users.noreply.github.com>
This commit is contained in:
lishunyang12 authored and WeiQing Chen committed 2026-05-31 11:40:40 +00:00
1 parent 74050cdacd
commit 7c934b6188
12 files changed
+2059 -208

No files matched your search

@@ -2,20 +2,8 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Lance (ByteDance) — vLLM-Omni model_executor package.
The runnable, registered path is the **single-stage** topology: a
self-contained diffusion stage (``LancePipeline``) that owns the Qwen2-MoT
LLM, the Qwen2.5-VL ViT, the Wan2.2 VAE and the tokenizer — directly analogous
to ``bagel_single_stage``.
The two-stage (separate AR "thinker" + DiT) topology additionally needs a
``LanceConfig`` / ``LanceProcessor`` registered in the ``vllm`` package
(mirroring ``vllm.transformers_utils.configs.bagel`` /
``vllm.model_executor.models.bagel``); that is an explicit follow-up and is
intentionally not wired here to avoid shipping a half-working AR stage.
Single-stage topology: a self-contained diffusion stage (``LancePipeline``
defined in ``vllm_omni.diffusion.models.lance``) that owns the Qwen2-MoT LLM,
the Qwen2.5-VL ViT, the Wan2.2 VAE and the tokenizer — directly analogous to
``bagel_single_stage``. The ``PipelineConfig`` lives in :mod:`.pipeline`.
"""
from vllm_omni.model_executor.models.lance.lance import (
OmniLanceForConditionalGeneration,
)
__all__ = ["OmniLanceForConditionalGeneration"]
@@ -1,33 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Lance AR-stage model wrapper (two-stage topology).
Lance is BAGEL-lineage, so the AR/thinker stage is the same Qwen2-MoT model
BAGEL uses. This subclass exists so the two-stage pipeline has a distinct
arch name to register against; behaviour is inherited unchanged from
:class:`OmniBagelForConditionalGeneration`.
IMPORTANT: the two-stage Lance topology is a follow-up. It additionally
requires a ``LanceConfig`` + ``LanceProcessor`` registered in the ``vllm``
package (the base ``BagelForConditionalGeneration`` resolves its HF config /
processor by ``model_type == "bagel"``; Lance ships ``model_type ==
"qwen2_5_vl"`` in ``llm_config.json`` and no BAGEL-style top-level config).
Until that lands, use the **single-stage** topology (``model_type: lance`` ->
``LANCE_SINGLE_STAGE_PIPELINE`` -> ``LancePipeline``), which is fully wired and
needs no ``vllm``-submodule changes.
"""
from __future__ import annotations
from vllm_omni.model_executor.models.bagel.bagel import (
OmniBagelForConditionalGeneration,
)
class OmniLanceForConditionalGeneration(OmniBagelForConditionalGeneration):
"""Lance AR-stage model. Identical to BAGEL's (same Qwen2-MoT weights);
distinct class only so the two-stage pipeline can register a ``lance``
arch separately. See module docstring for the two-stage follow-up."""
# Same packed→sublayer LoRA / MoT mapping as BAGEL (weight names match).
packed_modules_mapping = OmniBagelForConditionalGeneration.packed_modules_mapping
@@ -1,17 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Lance pipeline topologies.
"""Lance pipeline topology.
Single-stage (runnable / registered):
Stage 0: DiT — self-contained diffusion stage that handles all modalities
(text2img, image_edit, x2t_image) internally via its own
Qwen2-MoT LLM, Qwen2.5-VL ViT, Wan2.2 VAE, and tokenizer.
Mirrors ``bagel_single_stage``.
Two-stage (follow-up — see vllm_omni/model_executor/models/lance/lance.py):
Stage 0: Thinker (AR) -> Stage 1: DiT. Needs a LanceConfig/LanceProcessor
in the ``vllm`` package; defined here for completeness but gated behind the
follow-up so it is not selected by default.
Single-stage DiT — self-contained diffusion stage that handles all modalities
(text2img, image_edit, x2t_image, video) internally via its own Qwen2-MoT
LLM, Qwen2.5-VL ViT, Wan2.2 VAE, and tokenizer. Mirrors ``bagel_single_stage``.
"""
from vllm_omni.config.stage_config import (
@@ -20,10 +13,7 @@ from vllm_omni.config.stage_config import (
StagePipelineConfig,
)
_PROC = "vllm_omni.model_executor.stage_input_processors.lance"
# --- Single-stage (default, fully wired) -------------------------------- #
LANCE_SINGLE_STAGE_PIPELINE = PipelineConfig(
LANCE_PIPELINE = PipelineConfig(
model_type="lance",
model_arch="LancePipeline",
hf_architectures=(),
@@ -38,40 +28,3 @@ LANCE_SINGLE_STAGE_PIPELINE = PipelineConfig(
),
),
)
# --- Two-stage (follow-up; not registered as default) ------------------- #
LANCE_PIPELINE = PipelineConfig(
model_type="lance_two_stage",
model_arch="OmniLanceForConditionalGeneration",
hf_architectures=(),
stages=(
StagePipelineConfig(
stage_id=0,
model_stage="thinker",
execution_type=StageExecutionType.LLM_AR,
input_sources=(),
final_output=True,
final_output_type="text",
owns_tokenizer=True,
requires_multimodal_data=True,
model_arch="OmniLanceForConditionalGeneration",
engine_output_type="text",
prompt_expand_func=f"{_PROC}.expand_cfg_prompts",
omni_kv_config={
"need_send_cache": True,
"kv_transfer_criteria": {"type": "prefill_finished"},
},
sampling_constraints={"detokenize": True},
),
StagePipelineConfig(
stage_id=1,
model_stage="dit",
execution_type=StageExecutionType.DIFFUSION,
input_sources=(0,),
final_output=True,
final_output_type="image",
cfg_kv_collect_func=f"{_PROC}.collect_cfg_kv_caches",
omni_kv_config={"need_recv_cache": True},
),
),
)
@@ -134,12 +134,6 @@ _OMNI_MODELS = {
"bagel",
"OmniBagelForConditionalGeneration",
),
## lance (ByteDance) — BAGEL-lineage; two-stage AR arch (follow-up)
"OmniLanceForConditionalGeneration": (
"lance",
"lance",
"OmniLanceForConditionalGeneration",
),
"HunyuanImage3ForCausalMM": (
"hunyuan_image3",
"hunyuan_image3",