[Feature][LingBot World]stepwise execution (#6844)

Signed-off-by: BruceLoveDecimal <liuqihao970610@gmail.com>
Signed-off-by: liuqihao <liuqihao970610@gmail.com>
This commit is contained in:
BruceLoveDecimal authored and GitHub committed 2026-09-07 13:38:23 +08:00
1 parent 7f32c326c6
commit 5cd925631c
24 files changed
+2087 -217

No files matched your search

@@ -62,7 +62,6 @@ def test_lingbot_world_v2_tp1_one_block(omni_runner_handler: OmniRunnerHandler)
height=480,
width=832,
num_frames=9,
num_inference_steps=4,
max_sequence_length=512,
seed=42,
fps=16,
@@ -0,0 +1,149 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""End-to-end stepwise smoke test for LingBot-World v2.
One ``AsyncOmni.generate()`` must stream one latent chunk per AR block while
keeping a single request identity, which is what separates this path from the
tick control plane exercised by ``test_lingbot_world_v2.py``.
"""
from __future__ import annotations
import asyncio
import os
from pathlib import Path
from typing import TYPE_CHECKING, Any
import pytest
import torch
from vllm.assets.image import ImageAsset
from tests.helpers.mark import hardware_test
if TYPE_CHECKING:
from vllm_omni.outputs import OmniRequestOutput
MODEL = os.environ.get(
"VLLM_OMNI_LINGBOT_WORLD_V2_CHECKPOINT_PATH",
"robbyant/lingbot-world-v2-14b-causal-fast-diffusers",
)
# The pipeline resizes the first frame to the requested geometry, so any real
# photograph conditions the rollout; the shared vLLM asset keeps the test
# runnable with no environment setup and adds no binary to this repository.
_IMAGE_ASSET = "2560px-Gfp-wisconsin-madison-the-nature-boardwalk"
_IMAGE_PATH_OVERRIDE = os.environ.get("VLLM_OMNI_LINGBOT_WORLD_V2_IMAGE_PATH")
_HEIGHT = 480
_WIDTH = 832
_FRAMES_PER_BLOCK = 3
_TEMPORAL_COMPRESSION = 4
_REQUEST_ID = "lingbot-world-v2-stepwise-e2e"
# One three-frame action list per generated chunk.
_CAMERA_ACTION_SCRIPT = [
[["w"], ["w"], ["w"]],
[["a"], [], []],
[[], [], []],
]
_NUM_CHUNKS = len(_CAMERA_ACTION_SCRIPT)
_NUM_FRAMES = (_NUM_CHUNKS * _FRAMES_PER_BLOCK - 1) * _TEMPORAL_COMPRESSION + 1
pytestmark = [
pytest.mark.slow,
pytest.mark.diffusion,
]
def _first_frame() -> Path:
if _IMAGE_PATH_OVERRIDE:
return Path(_IMAGE_PATH_OVERRIDE).expanduser().resolve()
return Path(ImageAsset(_IMAGE_ASSET).get_path("jpg"))
def _chunk_metadata(output: OmniRequestOutput) -> dict[str, Any]:
multimodal = getattr(output, "multimodal_output", None) or {}
metadata = multimodal.get("metadata") if isinstance(multimodal, dict) else None
assert isinstance(metadata, dict), "streamed chunk is missing its metadata envelope"
ar_diffusion = metadata.get("ar_diffusion")
assert isinstance(ar_diffusion, dict), "streamed chunk is missing ar_diffusion metadata"
return dict(ar_diffusion)
async def _stream_chunks(image: Path) -> list[tuple[torch.Tensor, dict[str, Any], bool]]:
from vllm_omni.entrypoints.async_omni import AsyncOmni
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
engine = AsyncOmni(
model=MODEL,
engine_backend="vllm_omni.experimental.ar_diffusion.engine.ARDiffusionEngine",
enforce_eager=True,
tensor_parallel_size=1,
max_num_seqs=1,
step_execution=True,
diffusion_streaming_output=True,
model_config={
"ar_diffusion_height": _HEIGHT,
"ar_diffusion_width": _WIDTH,
"ar_diffusion_kv_config": {"gpu_memory_fraction": 0.6, "warmup_cudagraph": True},
},
)
sampling = OmniDiffusionSamplingParams(
height=_HEIGHT,
width=_WIDTH,
num_frames=_NUM_FRAMES,
num_inference_steps=4,
max_sequence_length=512,
seed=42,
output_type="latent",
extra_args={"flow_shift": 5.0, "camera_action_script": _CAMERA_ACTION_SCRIPT},
)
prompt = {
"prompt": "The camera moves slowly forward through the scene.",
"multi_modal_data": {"image": str(image)},
}
chunks: list[tuple[torch.Tensor, dict[str, Any], bool]] = []
try:
async for output in engine.generate(prompt, sampling, request_id=_REQUEST_ID):
images = getattr(output, "images", None)
if not images:
continue
assert len(images) == 1, "each AR block yields exactly one latent tensor"
latent = images[0].detach().float().cpu()
chunks.append((latent, _chunk_metadata(output), bool(getattr(output, "finished", False))))
finally:
engine.shutdown()
return chunks
@hardware_test(res={"cuda": "H100"}, num_cards=1)
def test_lingbot_world_v2_stepwise_streams_one_chunk_per_block() -> None:
"""Load the real checkpoint and stream N chunks from a single request."""
chunks = asyncio.run(_stream_chunks(_first_frame()))
assert len(chunks) == _NUM_CHUNKS
expected_shape = (
1,
16,
_FRAMES_PER_BLOCK,
_HEIGHT // 8,
_WIDTH // 8,
)
for chunk_index, (latent, metadata, finished) in enumerate(chunks):
assert tuple(latent.shape) == expected_shape
assert torch.isfinite(latent).all()
# The request is the session, so both ids must agree on every chunk,
# and chunk indices must be contiguous from zero.
assert metadata["chunk_index"] == chunk_index
assert metadata["session_id"] == metadata["request_id"]
assert metadata["applied_event_ids"] == []
assert finished is (chunk_index == _NUM_CHUNKS - 1)
# The engine suffixes the caller's id to keep it unique; what this path
# guarantees is that one rollout keeps one identity from start to finish.
request_ids = {metadata["request_id"] for _, metadata, _ in chunks}
assert len(request_ids) == 1
assert request_ids.pop().startswith(_REQUEST_ID)
concatenated = torch.cat([latent for latent, _, _ in chunks], dim=2)
assert concatenated.shape[2] == _NUM_CHUNKS * _FRAMES_PER_BLOCK
@@ -0,0 +1,144 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""End-to-end streaming serving smoke test for LingBot-World v2.
One ``WS /v1/realtime/video`` session must drive the whole rollout and return
one video chunk per AR block. This is the entry point the recipe documents;
``tests/e2e/offline_inference/test_lingbot_world_v2_stepwise.py`` covers the
same step-execution contract at the latent level, below the transport.
"""
from __future__ import annotations
import os
os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn"
import asyncio
import base64
import json
import mimetypes
from pathlib import Path
from typing import Any
import pytest
from vllm.assets.image import ImageAsset
from tests.helpers.mark import hardware_test
from tests.helpers.runtime import OmniServerParams
from tests.helpers.stage_config import get_deploy_config_path
MODEL = os.environ.get(
"VLLM_OMNI_LINGBOT_WORLD_V2_CHECKPOINT_PATH",
"robbyant/lingbot-world-v2-14b-causal-fast-diffusers",
)
# The pipeline resizes the first frame to the requested geometry, so any real
# photograph conditions the rollout; the shared vLLM asset keeps the test
# runnable with no environment setup and adds no binary to this repository.
_IMAGE_ASSET = "2560px-Gfp-wisconsin-madison-the-nature-boardwalk"
_IMAGE_PATH_OVERRIDE = os.environ.get("VLLM_OMNI_LINGBOT_WORLD_V2_IMAGE_PATH")
# The AR cache geometry is fixed at load time, so a request must ask for
# exactly the resolution the deploy config declares.
_HEIGHT = 480
_WIDTH = 832
_FRAMES_PER_BLOCK = 3
_TEMPORAL_COMPRESSION = 4
# One three-frame action list per generated chunk.
_CAMERA_ACTION_SCRIPT = [
[["w"], ["w"], ["w"]],
[["a"], [], []],
[[], [], []],
]
_NUM_CHUNKS = len(_CAMERA_ACTION_SCRIPT)
_NUM_FRAMES = (_NUM_CHUNKS * _FRAMES_PER_BLOCK - 1) * _TEMPORAL_COMPRESSION + 1
_PROMPT = "The camera moves slowly forward through the scene."
pytestmark = [
pytest.mark.slow,
pytest.mark.diffusion,
]
def _first_frame() -> Path:
if _IMAGE_PATH_OVERRIDE:
return Path(_IMAGE_PATH_OVERRIDE).expanduser().resolve()
return Path(ImageAsset(_IMAGE_ASSET).get_path("jpg"))
lingbot_world_v2_stepwise_server_params = [
pytest.param(
OmniServerParams(
model=MODEL,
stage_config_path=get_deploy_config_path("lingbot_world_v2_stepwise.yaml"),
),
id="lingbot_world_v2_stepwise",
)
]
def _session_start(model: str, image: Path) -> dict[str, Any]:
media_type = mimetypes.guess_type(image.name)[0] or "image/png"
encoded = base64.b64encode(image.read_bytes()).decode()
return {
"type": "session.start",
"model": model,
"prompt": _PROMPT,
# LingBot is image-conditioned: without a first frame the request is
# rejected during pre-processing.
"image_reference": {"image_url": f"data:{media_type};base64,{encoded}"},
"width": _WIDTH,
"height": _HEIGHT,
"num_frames": _NUM_FRAMES,
"fps": 16,
"seed": 42,
"extra_params": {"flow_shift": 5.0, "camera_action_script": _CAMERA_ACTION_SCRIPT},
}
async def _stream_session(url: str, model: str, image: Path) -> tuple[list[dict[str, Any]], bytes, dict[str, Any]]:
import websockets
events: list[dict[str, Any]] = []
media = bytearray()
done: dict[str, Any] = {}
async with websockets.connect(url, max_size=None, ping_interval=None) as websocket:
await websocket.send(json.dumps(_session_start(model, image)))
while True:
message = await asyncio.wait_for(websocket.recv(), timeout=900)
if isinstance(message, bytes):
media.extend(message)
continue
event = json.loads(message)
events.append(event)
if event["type"] == "error":
pytest.fail(f"server returned an error event: {event}")
if event["type"] == "session.done":
done = event
break
return events, bytes(media), done
@hardware_test(res={"cuda": "H100"}, num_cards=1)
@pytest.mark.parametrize("omni_server", lingbot_world_v2_stepwise_server_params, indirect=True)
def test_lingbot_world_v2_stepwise_streams_one_chunk_per_block(omni_server) -> None:
"""Serve the real checkpoint and stream N chunks from a single WS session."""
url = f"ws://{omni_server.host}:{omni_server.port}/v1/realtime/video"
events, media, done = asyncio.run(_stream_session(url, omni_server.model, _first_frame()))
started = [event for event in events if event["type"] == "video.start"]
assert len(started) == 1, "one session.start must open exactly one rollout"
# A trailer chunk may follow the media chunks; only media chunks carry a
# generation index, and there is exactly one per AR block.
media_chunks = [event for event in events if event["type"] == "video.chunk_metadata" and event["kind"] == "media"]
assert [event["generation_chunk_index"] for event in media_chunks] == list(range(_NUM_CHUNKS))
for event in media_chunks:
assert event["request_id"] == started[0]["request_id"]
assert event["num_frames"] > 0
assert event["byte_length"] > 0
assert len(media) == sum(event["byte_length"] for event in events if event["type"] == "video.chunk_metadata")
assert done["stopped"] is False
assert done["chunks"] >= _NUM_CHUNKS