[Core][Frontend] Support request-level batching for diffusion pipelines (#4079)
Signed-off-by: jader <yjader@foxmail.com> Co-authored-by: Samit <285365963@qq.com>
This commit is contained in:
1 parent
504698dec8
commit
c45ac74d43
123 files changed
+4160
-2233
No files matched your search
@@ -220,76 +220,11 @@ async def run_batch(
|
||||
return elapsed
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Explicit batch — single generate() call with list of prompts
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
|
||||
async def run_batch_explicit(
|
||||
omni: AsyncOmni,
|
||||
prompts: list[dict[str, str]],
|
||||
label: str = "batch_explicit",
|
||||
) -> float:
|
||||
"""Send all prompts as a single batch via generate(prompt=[...]).
|
||||
|
||||
Passes a *list* of prompts so that all are processed in **one**
|
||||
``DiffusionEngine.step()`` call. The orchestrator detects
|
||||
``isinstance(prompt, list)`` and routes to the batch path.
|
||||
|
||||
A single ``OmniRequestOutput`` is yielded containing ALL generated
|
||||
images combined.
|
||||
"""
|
||||
print(f"⚡ Running {label.upper()} mode – {len(prompts)} prompts in ONE engine call ...")
|
||||
sp = _default_sampling_params()
|
||||
request_id = f"{label}-{uuid.uuid4().hex[:8]}"
|
||||
start = time.perf_counter()
|
||||
|
||||
result: OmniRequestOutput | None = None
|
||||
async for output in omni.generate(
|
||||
prompt=prompts,
|
||||
request_id=request_id,
|
||||
sampling_params_list=[sp],
|
||||
):
|
||||
result = output
|
||||
|
||||
elapsed = time.perf_counter() - start
|
||||
if result is not None:
|
||||
images = _extract_images(result)
|
||||
print(f" Got {len(images)} images total from batch, request_id={result.request_id}")
|
||||
else:
|
||||
print(" ⚠️ No output received from batch generate()")
|
||||
|
||||
print(f" ✅ Total {label} mode: {elapsed:.2f}s\n")
|
||||
return elapsed
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Async validation helpers
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
|
||||
async def validate_batch_explicit(omni: AsyncOmni, prompts: list[dict[str, str]]) -> None:
|
||||
"""Validate generate(prompt=[...]) returns a single result with all images."""
|
||||
print(f"🔍 Validating batch generate() correctness with {len(prompts)} prompts ...")
|
||||
sp = _default_sampling_params()
|
||||
request_id = f"validate-batch-{uuid.uuid4().hex[:8]}"
|
||||
|
||||
result: OmniRequestOutput | None = None
|
||||
async for output in omni.generate(
|
||||
prompt=prompts,
|
||||
request_id=request_id,
|
||||
sampling_params_list=[sp],
|
||||
):
|
||||
result = output
|
||||
|
||||
assert result is not None, "No output received from batch generate()"
|
||||
images = _extract_images(result)
|
||||
# Batch mode returns ONE output with ALL images combined
|
||||
assert len(images) == len(prompts), f"Expected {len(prompts)} images (one per prompt), got {len(images)}"
|
||||
assert result.request_id == request_id, f"Expected request_id={request_id}, got {result.request_id}"
|
||||
print(f" ✅ Batch returned {len(images)} images with correct request_id.\n")
|
||||
|
||||
|
||||
async def validate_concurrent(omni: AsyncOmni, prompts: list[dict[str, str]]) -> None:
|
||||
"""Validate that every concurrent request receives a distinct result
|
||||
with its own request_id."""
|
||||
@@ -330,17 +265,14 @@ async def compare_single_vs_parallel(
|
||||
await warmup(omni, WARMUP_PROMPTS)
|
||||
single_time = await run_single(omni, prompts)
|
||||
parallel_time = await run_batch(omni, prompts, label="parallel")
|
||||
explicit_time = await run_batch_explicit(omni, prompts, label="batch_explicit")
|
||||
finally:
|
||||
omni.shutdown()
|
||||
|
||||
speedup_parallel = single_time / parallel_time if parallel_time > 0 else float("inf")
|
||||
speedup_explicit = single_time / explicit_time if explicit_time > 0 else float("inf")
|
||||
print("=" * 60)
|
||||
print(f"📊 Summary ({len(prompts)} prompts)")
|
||||
print(f" Sequential : {single_time:.2f}s")
|
||||
print(f" Parallel (gather) : {parallel_time:.2f}s ({speedup_parallel:.2f}x)")
|
||||
print(f" Explicit batch : {explicit_time:.2f}s ({speedup_explicit:.2f}x)")
|
||||
print("=" * 60)
|
||||
|
||||
|
||||
@@ -362,12 +294,8 @@ async def main(model: str, num_prompts: int, mode: str, batch_size: int = 1) ->
|
||||
|
||||
if mode == "validate":
|
||||
await validate_concurrent(omni, prompts)
|
||||
elif mode == "validate_batch":
|
||||
await validate_batch_explicit(omni, prompts)
|
||||
elif mode == "batch":
|
||||
await run_batch(omni, prompts, label="measurement")
|
||||
elif mode == "batch_explicit":
|
||||
await run_batch_explicit(omni, prompts)
|
||||
elif mode == "single":
|
||||
await run_single(omni, prompts)
|
||||
else:
|
||||
@@ -495,13 +423,10 @@ def test_diffusion_batching_async_concurrent(model_name: str):
|
||||
@pytest.mark.diffusion
|
||||
@hardware_test(res={"cuda": "L4", "rocm": "MI325", "xpu": "B60"})
|
||||
@pytest.mark.parametrize("model_name", models)
|
||||
def test_diffusion_batching_async_explicit_batch(model_name: str):
|
||||
"""Test that AsyncOmni batch mode (generate(prompt=[...])) dispatches
|
||||
all prompts in a single engine call and returns a single combined result.
|
||||
|
||||
The list-prompt path routes through the orchestrator's
|
||||
``add_batch_request_async`` → ``AsyncOmni.generate_batch``
|
||||
and yields ONE ``OmniRequestOutput`` with ALL images combined.
|
||||
def test_diffusion_batching_list_prompt_rejected(model_name: str):
|
||||
"""Test that list-prompt batch requests are rejected at the diffusion
|
||||
stage boundary. Users should submit multiple independent requests to
|
||||
leverage scheduler batching instead.
|
||||
"""
|
||||
|
||||
async def _inner():
|
||||
@@ -511,25 +436,14 @@ def test_diffusion_batching_async_explicit_batch(model_name: str):
|
||||
sp = _default_sampling_params()
|
||||
request_id = f"explicit-batch-{uuid.uuid4().hex[:8]}"
|
||||
|
||||
# Batch mode: pass list of prompts → single request_id
|
||||
result: OmniRequestOutput | None = None
|
||||
async for output in omni.generate(
|
||||
prompt=prompts,
|
||||
request_id=request_id,
|
||||
sampling_params_list=[sp],
|
||||
):
|
||||
result = output
|
||||
|
||||
assert result is not None, "No output received from batch generate()"
|
||||
|
||||
images = _extract_images(result)
|
||||
# One image per prompt, all in a single output
|
||||
assert len(images) == len(prompts), f"Expected {len(prompts)} images in combined output, got {len(images)}"
|
||||
assert result.request_id == request_id, f"Expected request_id={request_id}, got {result.request_id}"
|
||||
for i, img in enumerate(images):
|
||||
assert img.width == 256, f"Image {i} width mismatch"
|
||||
assert img.height == 256, f"Image {i} height mismatch"
|
||||
print(f" ✅ Batch returned {len(images)} images, request_id={result.request_id}")
|
||||
with pytest.raises(ValueError, match="Diffusion stages accept only a single prompt per request"):
|
||||
async for _output in omni.generate(
|
||||
prompt=prompts,
|
||||
request_id=request_id,
|
||||
sampling_params_list=[sp],
|
||||
):
|
||||
pass
|
||||
print(" ✅ List-prompt batch correctly rejected")
|
||||
finally:
|
||||
omni.shutdown()
|
||||
|
||||
@@ -613,12 +527,11 @@ if __name__ == "__main__":
|
||||
parser.add_argument("--batch-size", type=int, default=1, help="Diffusion batch size (1 = no batching)")
|
||||
parser.add_argument(
|
||||
"--mode",
|
||||
choices=["batch", "batch_explicit", "single", "compare", "validate", "validate_batch"],
|
||||
choices=["batch", "single", "compare", "validate"],
|
||||
default="compare",
|
||||
help=(
|
||||
"Run mode: 'batch' (parallel gather), 'batch_explicit' (list-prompt batch API), "
|
||||
"'single' (sequential), 'compare' (all three), "
|
||||
"'validate' (concurrent correctness), 'validate_batch' (list-prompt correctness)"
|
||||
"Run mode: 'batch' (parallel gather), 'single' (sequential), "
|
||||
"'compare' (single vs parallel), 'validate' (concurrent correctness)"
|
||||
),
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -18,6 +18,7 @@ from vllm_omni.diffusion.data import (
|
||||
)
|
||||
from vllm_omni.diffusion.models.diffusers_adapter import DiffusersAdapterPipeline
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
pytestmark = [pytest.mark.diffusion]
|
||||
@@ -48,7 +49,7 @@ def _make_request(**overrides) -> OmniDiffusionRequest:
|
||||
prompt_obj["negative_prompt"] = negative_prompt
|
||||
|
||||
defaults = {
|
||||
"prompts": [prompt_obj],
|
||||
"prompt": prompt_obj,
|
||||
"sampling_params": OmniDiffusionSamplingParams(
|
||||
num_inference_steps=20,
|
||||
guidance_scale=7.5,
|
||||
@@ -66,6 +67,11 @@ def _make_request(**overrides) -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(**defaults)
|
||||
|
||||
|
||||
def _make_batch(**overrides) -> DiffusionRequestBatch:
|
||||
"""Wrap a single request in a DiffusionRequestBatch, matching the forward contract."""
|
||||
return DiffusionRequestBatch(requests=[_make_request(**overrides)])
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
class TestPipelineArgumentsHandling:
|
||||
@@ -84,7 +90,7 @@ class TestPipelineArgumentsHandling:
|
||||
"__call__",
|
||||
return_value=MockPipelineOutput(image=stub_image),
|
||||
)
|
||||
output = adapter.forward(request)
|
||||
output = adapter.forward(DiffusionRequestBatch(requests=[request]))
|
||||
|
||||
assert isinstance(output, DiffusionOutput)
|
||||
assert isinstance(output.output, MockPipelineOutput)
|
||||
@@ -145,7 +151,7 @@ class TestPipelineArgumentsHandling:
|
||||
"__call__",
|
||||
return_value=raw_output,
|
||||
)
|
||||
output = adapter.forward(_make_request())
|
||||
output = adapter.forward(_make_batch())
|
||||
|
||||
assert isinstance(output, DiffusionOutput)
|
||||
assert output.output == raw_output
|
||||
@@ -205,7 +211,7 @@ class TestPipelineArgumentsHandling:
|
||||
),
|
||||
)
|
||||
|
||||
kwargs = adapter._build_call_kwargs(req)
|
||||
kwargs = adapter._build_call_kwargs(DiffusionRequestBatch(requests=[req]))
|
||||
|
||||
assert kwargs["prompt"] == "a cat on mars"
|
||||
assert kwargs["negative_prompt"] == "low quality"
|
||||
@@ -403,7 +409,7 @@ class TestPipelineArgumentsHandling:
|
||||
),
|
||||
)
|
||||
with pytest.raises(ValueError):
|
||||
pipeline.forward(problematic_request)
|
||||
pipeline.forward(DiffusionRequestBatch(requests=[problematic_request]))
|
||||
|
||||
|
||||
@pytest.mark.advanced_model
|
||||
|
||||
@@ -15,6 +15,8 @@ import torch
|
||||
from PIL import Image
|
||||
from torch import nn
|
||||
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
|
||||
@@ -243,6 +245,31 @@ def make_sampling_params(**overrides: Any) -> SimpleNamespace:
|
||||
return SimpleNamespace(**values)
|
||||
|
||||
|
||||
def make_request_batch(prompt: Any, sampling_params: SimpleNamespace) -> DiffusionRequestBatch:
|
||||
if isinstance(prompt, list):
|
||||
return DiffusionRequestBatch(
|
||||
requests=[
|
||||
SimpleNamespace(
|
||||
prompt=item,
|
||||
request_id=f"cosmos3-test-{idx}",
|
||||
sampling_params=sampling_params,
|
||||
kv_sender_info=None,
|
||||
)
|
||||
for idx, item in enumerate(prompt)
|
||||
]
|
||||
)
|
||||
return DiffusionRequestBatch(
|
||||
requests=[
|
||||
SimpleNamespace(
|
||||
prompt=prompt,
|
||||
request_id="cosmos3-test",
|
||||
sampling_params=sampling_params,
|
||||
kv_sender_info=None,
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def _ids(value: int) -> torch.Tensor:
|
||||
return torch.tensor([[value]], dtype=torch.long)
|
||||
|
||||
@@ -466,34 +493,34 @@ def test_preprocess_i2v_image_and_action_video_inputs() -> None:
|
||||
|
||||
preprocess = get_cosmos3_pre_process_func(SimpleNamespace())
|
||||
i2v = SimpleNamespace(
|
||||
prompts=[{"prompt": "A slow camera push.", "multi_modal_data": {"image": Image.new("RGB", (320, 160))}}],
|
||||
sampling_params=SimpleNamespace(height=None, width=None, extra_args={}),
|
||||
prompt={"prompt": "A slow camera push.", "multi_modal_data": {"image": Image.new("RGB", (320, 160))}},
|
||||
sampling_params=make_sampling_params(height=None, width=None, extra_args={}),
|
||||
)
|
||||
|
||||
result = preprocess(i2v)
|
||||
assert (result.sampling_params.height, result.sampling_params.width) == (672, 1344)
|
||||
assert tuple(result.prompts[0]["additional_information"]["preprocessed_image"].shape[-2:]) == (672, 1344)
|
||||
assert tuple(result.prompt["additional_information"]["preprocessed_image"].shape[-2:]) == (672, 1344)
|
||||
|
||||
frames = [Image.new("RGB", (8, 4), color) for color in ("red", "green", "blue")]
|
||||
action = SimpleNamespace(
|
||||
prompts=[{"prompt": "Move.", "multi_modal_data": {"video": frames}}],
|
||||
sampling_params=SimpleNamespace(height=16, width=32, extra_args={"action_mode": "forward_dynamics"}),
|
||||
prompt={"prompt": "Move.", "multi_modal_data": {"video": frames}},
|
||||
sampling_params=make_sampling_params(height=16, width=32, extra_args={"action_mode": "forward_dynamics"}),
|
||||
)
|
||||
|
||||
additional = preprocess(action).prompts[0]["additional_information"]
|
||||
additional = preprocess(action).prompt["additional_information"]
|
||||
assert tuple(additional["preprocessed_image"].shape) == (1, 3, 16, 32)
|
||||
assert tuple(additional["preprocessed_video"].shape) == (1, 3, 3, 16, 32)
|
||||
|
||||
frames = [Image.new("RGB", (8, 4), color) for color in ("red", "green", "blue", "yellow", "purple", "black")]
|
||||
v2v = SimpleNamespace(
|
||||
prompts=[{"prompt": "Continue.", "multi_modal_data": {"video": frames}}],
|
||||
sampling_params=SimpleNamespace(
|
||||
prompt={"prompt": "Continue.", "multi_modal_data": {"video": frames}},
|
||||
sampling_params=make_sampling_params(
|
||||
height=16,
|
||||
width=32,
|
||||
extra_args={"condition_frame_indexes_vision": [0, 1], "condition_video_keep": "last"},
|
||||
),
|
||||
)
|
||||
additional = preprocess(v2v).prompts[0]["additional_information"]
|
||||
additional = preprocess(v2v).prompt["additional_information"]
|
||||
assert tuple(additional["preprocessed_video"].shape) == (1, 3, 5, 16, 32)
|
||||
assert additional["condition_frame_indexes_vision"] == [0, 1]
|
||||
|
||||
@@ -565,15 +592,16 @@ def test_transfer_config_media_helpers_and_preprocess_budget(monkeypatch: pytest
|
||||
fps = 12.5
|
||||
|
||||
frames = FramesWithFps(Image.new("RGB", (8, 4), color) for color in ("red", "green", "blue", "yellow", "black"))
|
||||
prompt = {"prompt": "transfer", "multi_modal_data": {"video": frames}}
|
||||
request = SimpleNamespace(
|
||||
prompts=[{"prompt": "transfer", "multi_modal_data": {"video": frames}}],
|
||||
prompt=prompt,
|
||||
sampling_params=SimpleNamespace(
|
||||
height=16,
|
||||
width=32,
|
||||
extra_args={"edge": True, "max_frames": 4, "resolution": "256"},
|
||||
),
|
||||
)
|
||||
additional = preprocess(request).prompts[0]["additional_information"]
|
||||
additional = preprocess(request).prompt["additional_information"]
|
||||
assert (request.sampling_params.height, request.sampling_params.width) == (192, 320)
|
||||
assert tuple(additional["preprocessed_transfer_video"].shape) == (1, 3, 4, 192, 320)
|
||||
assert additional["transfer_input_fps"] == 12.5
|
||||
@@ -1332,7 +1360,7 @@ class TestForwardRouting:
|
||||
pipeline = make_cosmos3_pipeline()
|
||||
captured = self._install_forward_stubs(pipeline)
|
||||
|
||||
output = pipeline.forward(SimpleNamespace(prompts=[prompt], sampling_params=sampling_params))
|
||||
output = pipeline.forward(make_request_batch(prompt, sampling_params))
|
||||
|
||||
assert expected["key"] in output.output
|
||||
assert captured["format"]["is_t2i"] is expected["is_t2i"]
|
||||
@@ -1353,15 +1381,13 @@ class TestForwardRouting:
|
||||
torch.zeros(1, 2, 1, 1, 1),
|
||||
)
|
||||
pipeline.forward(
|
||||
SimpleNamespace(
|
||||
prompts=[
|
||||
{
|
||||
"prompt": "move",
|
||||
"modalities": ["video"],
|
||||
"additional_information": {"preprocessed_image": image_tensor},
|
||||
}
|
||||
],
|
||||
sampling_params=make_sampling_params(height=16, width=16, num_frames=5),
|
||||
make_request_batch(
|
||||
{
|
||||
"prompt": "move",
|
||||
"modalities": ["video"],
|
||||
"additional_information": {"preprocessed_image": image_tensor},
|
||||
},
|
||||
make_sampling_params(height=16, width=16, num_frames=5),
|
||||
)
|
||||
)
|
||||
assert captured["diffuse_calls"][-1]["shared_kwargs"]["noisy_frame_mask"] is velocity_mask
|
||||
@@ -1375,18 +1401,16 @@ class TestForwardRouting:
|
||||
v2v_condition,
|
||||
)
|
||||
pipeline.forward(
|
||||
SimpleNamespace(
|
||||
prompts=[
|
||||
{
|
||||
"prompt": "continue",
|
||||
"modalities": ["video"],
|
||||
"additional_information": {
|
||||
"preprocessed_video": video_tensor,
|
||||
"condition_frame_indexes_vision": [0],
|
||||
},
|
||||
}
|
||||
],
|
||||
sampling_params=make_sampling_params(height=16, width=16, num_frames=5),
|
||||
make_request_batch(
|
||||
{
|
||||
"prompt": "continue",
|
||||
"modalities": ["video"],
|
||||
"additional_information": {
|
||||
"preprocessed_video": video_tensor,
|
||||
"condition_frame_indexes_vision": [0],
|
||||
},
|
||||
},
|
||||
make_sampling_params(height=16, width=16, num_frames=5),
|
||||
)
|
||||
)
|
||||
assert captured["flow_shifts"][-1] == 10.0
|
||||
@@ -1401,9 +1425,9 @@ class TestForwardRouting:
|
||||
pipeline._prepare_sound_latents = lambda *args: (sound_latents, 4)
|
||||
pipeline._decode_sound_latents = lambda *args: torch.ones(1, 2, 20)
|
||||
output = pipeline.forward(
|
||||
SimpleNamespace(
|
||||
prompts=[{"prompt": "A robot", "modalities": ["video"], "generate_sound": True}],
|
||||
sampling_params=make_sampling_params(num_frames=9, frame_rate=3.0),
|
||||
make_request_batch(
|
||||
{"prompt": "A robot", "modalities": ["video"], "generate_sound": True},
|
||||
make_sampling_params(num_frames=9, frame_rate=3.0),
|
||||
)
|
||||
)
|
||||
assert captured["diffuse_calls"][-1]["sound_latents"] is sound_latents
|
||||
@@ -1411,15 +1435,13 @@ class TestForwardRouting:
|
||||
|
||||
pipeline.transformer = pipeline.transformer.__class__(latent_channel_size=2, action_gen=True, action_dim=4)
|
||||
output = pipeline.forward(
|
||||
SimpleNamespace(
|
||||
prompts=[
|
||||
{
|
||||
"prompt": "Pick the block.",
|
||||
"modalities": ["video"],
|
||||
"additional_information": {"preprocessed_image": image_tensor},
|
||||
}
|
||||
],
|
||||
sampling_params=make_sampling_params(
|
||||
make_request_batch(
|
||||
{
|
||||
"prompt": "Pick the block.",
|
||||
"modalities": ["video"],
|
||||
"additional_information": {"preprocessed_image": image_tensor},
|
||||
},
|
||||
make_sampling_params(
|
||||
height=16,
|
||||
width=16,
|
||||
extra_args={
|
||||
@@ -1498,7 +1520,7 @@ class TestForwardRouting:
|
||||
AssertionError("RoboLab should not decode video")
|
||||
)
|
||||
|
||||
output = pipeline.forward(SimpleNamespace(prompts=["ignored"], sampling_params=make_sampling_params()))
|
||||
output = pipeline.forward(make_request_batch("ignored", make_sampling_params()))
|
||||
|
||||
assert captured["format"] == {
|
||||
"prompt": "Pick the cube.",
|
||||
@@ -1528,24 +1550,24 @@ class TestForwardRouting:
|
||||
("prompt", "sampling_params", "message"),
|
||||
[
|
||||
(["one", "two"], make_sampling_params(), "single prompt"),
|
||||
([{"prompt": "one", "modalities": ["image", "video"]}], make_sampling_params(), "both image and video"),
|
||||
({"prompt": "one", "modalities": ["image", "video"]}, make_sampling_params(), "both image and video"),
|
||||
(
|
||||
[{"prompt": "x", "modalities": ["image"], "generate_sound": True}],
|
||||
{"prompt": "x", "modalities": ["image"], "generate_sound": True},
|
||||
make_sampling_params(),
|
||||
"only for video",
|
||||
),
|
||||
(
|
||||
[{"prompt": "x", "modalities": ["image"]}],
|
||||
{"prompt": "x", "modalities": ["image"]},
|
||||
make_sampling_params(extra_args={"edge": {"control_path": "/tmp/control.mp4"}}),
|
||||
"transfer inference is supported only for video outputs",
|
||||
),
|
||||
(
|
||||
[{"prompt": "x", "modalities": ["video"], "generate_sound": True}],
|
||||
{"prompt": "x", "modalities": ["video"], "generate_sound": True},
|
||||
make_sampling_params(extra_args={"edge": {"control_path": "/tmp/control.mp4"}}),
|
||||
"cannot be combined with sound generation",
|
||||
),
|
||||
(
|
||||
[{"prompt": "x", "modalities": ["video"]}],
|
||||
{"prompt": "x", "modalities": ["video"]},
|
||||
make_sampling_params(
|
||||
extra_args={
|
||||
"edge": {"control_path": "/tmp/control.mp4"},
|
||||
@@ -1567,4 +1589,4 @@ class TestForwardRouting:
|
||||
pipeline.transformer = pipeline.transformer.__class__(latent_channel_size=2, sound_gen=True, sound_dim=3)
|
||||
|
||||
with pytest.raises(ValueError, match=message):
|
||||
pipeline.forward(SimpleNamespace(prompts=prompt, sampling_params=sampling_params))
|
||||
pipeline.forward(make_request_batch(prompt, sampling_params))
|
||||
@@ -43,10 +43,10 @@ def _make_pipeline(cls):
|
||||
return pipeline
|
||||
|
||||
|
||||
def _make_request(prompts=None, **sp_kwargs) -> OmniDiffusionRequest:
|
||||
def _make_request(prompt=None, **sp_kwargs) -> OmniDiffusionRequest:
|
||||
sp = OmniDiffusionSamplingParams(**sp_kwargs)
|
||||
return OmniDiffusionRequest(
|
||||
prompts=prompts or [{"prompt": "a cat dancing"}],
|
||||
prompt=prompt if prompt is not None else {"prompt": "a cat dancing"},
|
||||
sampling_params=sp,
|
||||
request_id="dmd2-sanitize",
|
||||
)
|
||||
@@ -133,35 +133,23 @@ def test_is_cfg_negative_forced_false(pipeline):
|
||||
|
||||
|
||||
def test_negative_prompt_stripped_from_prompt_dict(pipeline):
|
||||
req = _make_request(prompts=[{"prompt": "a cat", "negative_prompt": "blurry"}])
|
||||
req = _make_request(prompt={"prompt": "a cat", "negative_prompt": "blurry"})
|
||||
pipeline._sanitize_dmd2_request(req)
|
||||
assert "negative_prompt" not in req.prompts[0]
|
||||
assert req.prompts[0]["prompt"] == "a cat"
|
||||
assert "negative_prompt" not in req.prompt
|
||||
assert req.prompt["prompt"] == "a cat"
|
||||
|
||||
|
||||
def test_no_negative_prompt_unchanged(pipeline):
|
||||
req = _make_request(prompts=[{"prompt": "a cat"}])
|
||||
req = _make_request(prompt={"prompt": "a cat"})
|
||||
pipeline._sanitize_dmd2_request(req)
|
||||
assert req.prompts[0] == {"prompt": "a cat"}
|
||||
assert req.prompt == {"prompt": "a cat"}
|
||||
|
||||
|
||||
def test_string_prompt_not_mutated(pipeline):
|
||||
"""String prompts (not dicts) must pass through unchanged."""
|
||||
req = _make_request(prompts=["a cat dancing"])
|
||||
req = _make_request(prompt="a cat dancing")
|
||||
pipeline._sanitize_dmd2_request(req)
|
||||
assert req.prompts == ["a cat dancing"]
|
||||
|
||||
|
||||
def test_multiple_prompts_all_sanitized(pipeline):
|
||||
req = _make_request(
|
||||
prompts=[
|
||||
{"prompt": "a cat", "negative_prompt": "blurry"},
|
||||
{"prompt": "a dog", "negative_prompt": "ugly"},
|
||||
]
|
||||
)
|
||||
pipeline._sanitize_dmd2_request(req)
|
||||
for p in req.prompts:
|
||||
assert "negative_prompt" not in p
|
||||
assert req.prompt == "a cat dancing"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -48,7 +48,7 @@ def _make_pipeline(cls):
|
||||
|
||||
def _make_request(**sp_kwargs) -> OmniDiffusionRequest:
|
||||
sp = OmniDiffusionSamplingParams(**sp_kwargs)
|
||||
return OmniDiffusionRequest(prompts=[{"prompt": "a cat"}], sampling_params=sp, request_id="dmd2-scheduler")
|
||||
return OmniDiffusionRequest(prompt={"prompt": "a cat"}, sampling_params=sp, request_id="dmd2-scheduler")
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from torch import nn
|
||||
|
||||
from vllm_omni.diffusion.models.flux.pipeline_flux import FluxPipeline
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _make_flux_sampling(**overrides):
|
||||
values = {
|
||||
"height": 32,
|
||||
"width": 32,
|
||||
"num_inference_steps": 2,
|
||||
"sigmas": None,
|
||||
"guidance_scale": 3.5,
|
||||
"generator": None,
|
||||
"true_cfg_scale": 4.0,
|
||||
"num_outputs_per_prompt": 0,
|
||||
"latents": None,
|
||||
}
|
||||
values.update(overrides)
|
||||
return SimpleNamespace(**values)
|
||||
|
||||
|
||||
def _make_flux_pipeline():
|
||||
pipeline = object.__new__(FluxPipeline)
|
||||
nn.Module.__init__(pipeline)
|
||||
pipeline.default_sample_size = 128
|
||||
pipeline.vae_scale_factor = 8
|
||||
pipeline.device = torch.device("cpu")
|
||||
pipeline.text_encoder = None
|
||||
pipeline.transformer = SimpleNamespace(
|
||||
in_channels=4,
|
||||
guidance_embeds=False,
|
||||
dtype=torch.float32,
|
||||
)
|
||||
return pipeline
|
||||
|
||||
|
||||
def test_forward_collates_request_prompt_tensors_for_flux(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.models.flux.pipeline_flux.get_classifier_free_guidance_world_size",
|
||||
lambda: 1,
|
||||
)
|
||||
pipeline = _make_flux_pipeline()
|
||||
encode_calls = []
|
||||
prepare_latents_call = {}
|
||||
diffuse_call = {}
|
||||
|
||||
def _fake_encode_prompt(**kwargs):
|
||||
encode_calls.append(kwargs)
|
||||
return (
|
||||
kwargs["prompt_embeds"],
|
||||
kwargs["pooled_prompt_embeds"],
|
||||
torch.zeros(kwargs["prompt_embeds"].shape[1], 3),
|
||||
)
|
||||
|
||||
def _fake_prepare_latents(
|
||||
batch_size,
|
||||
num_channels_latents,
|
||||
height,
|
||||
width,
|
||||
dtype,
|
||||
device,
|
||||
generator,
|
||||
latents,
|
||||
):
|
||||
prepare_latents_call.update(
|
||||
{
|
||||
"batch_size": batch_size,
|
||||
"num_channels_latents": num_channels_latents,
|
||||
"height": height,
|
||||
"width": width,
|
||||
"dtype": dtype,
|
||||
"device": device,
|
||||
"generator": generator,
|
||||
"latents": latents,
|
||||
}
|
||||
)
|
||||
return torch.zeros(batch_size, 1, 1), torch.zeros(1, 3)
|
||||
|
||||
def _fake_diffuse(
|
||||
prompt_embeds,
|
||||
pooled_prompt_embeds,
|
||||
negative_prompt_embeds,
|
||||
negative_pooled_prompt_embeds,
|
||||
*args,
|
||||
**kwargs,
|
||||
):
|
||||
diffuse_call.update(
|
||||
{
|
||||
"prompt_embeds": prompt_embeds,
|
||||
"pooled_prompt_embeds": pooled_prompt_embeds,
|
||||
"negative_prompt_embeds": negative_prompt_embeds,
|
||||
"negative_pooled_prompt_embeds": negative_pooled_prompt_embeds,
|
||||
}
|
||||
)
|
||||
return torch.arange(2, dtype=torch.float32).view(2, 1)
|
||||
|
||||
pipeline.encode_prompt = _fake_encode_prompt
|
||||
pipeline.prepare_latents = _fake_prepare_latents
|
||||
pipeline.prepare_timesteps = lambda *args, **kwargs: (torch.tensor([1.0]), 1)
|
||||
pipeline.diffuse = _fake_diffuse
|
||||
|
||||
prompt_embeds_a = torch.zeros(2, 3)
|
||||
prompt_embeds_b = torch.ones(2, 3)
|
||||
pooled_prompt_embeds_a = torch.full((4,), 2.0)
|
||||
pooled_prompt_embeds_b = torch.full((4,), 3.0)
|
||||
negative_prompt_embeds_a = torch.full((2, 3), 4.0)
|
||||
negative_prompt_embeds_b = torch.full((2, 3), 5.0)
|
||||
negative_pooled_prompt_embeds_a = torch.full((4,), 6.0)
|
||||
negative_pooled_prompt_embeds_b = torch.full((4,), 7.0)
|
||||
latents_a = torch.zeros(1, 1, 1)
|
||||
latents_b = torch.ones(1, 1, 1)
|
||||
gen_a = torch.Generator(device="cpu").manual_seed(1)
|
||||
gen_b = torch.Generator(device="cpu").manual_seed(2)
|
||||
|
||||
batch = DiffusionRequestBatch(
|
||||
requests=[
|
||||
SimpleNamespace(
|
||||
request_id="flux-prompt-a",
|
||||
prompt={
|
||||
"prompt": "prompt-a",
|
||||
"negative_prompt": "negative-a",
|
||||
"prompt_embeds": prompt_embeds_a,
|
||||
"pooled_prompt_embeds": pooled_prompt_embeds_a,
|
||||
"negative_prompt_embeds": negative_prompt_embeds_a,
|
||||
"negative_pooled_prompt_embeds": negative_pooled_prompt_embeds_a,
|
||||
},
|
||||
sampling_params=_make_flux_sampling(generator=gen_a, latents=latents_a),
|
||||
),
|
||||
SimpleNamespace(
|
||||
request_id="flux-prompt-b",
|
||||
prompt={
|
||||
"prompt": "prompt-b",
|
||||
"negative_prompt": "negative-b",
|
||||
"additional_information": {
|
||||
"prompt_embeds": [prompt_embeds_b],
|
||||
"pooled_prompt_embeds": [pooled_prompt_embeds_b],
|
||||
"negative_prompt_embeds": [negative_prompt_embeds_b],
|
||||
"negative_pooled_prompt_embeds": [negative_pooled_prompt_embeds_b],
|
||||
},
|
||||
},
|
||||
sampling_params=_make_flux_sampling(generator=gen_b, latents=latents_b),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
outputs = pipeline.forward(batch, output_type="latent")
|
||||
|
||||
assert encode_calls[0]["prompt"] is None
|
||||
assert encode_calls[0]["prompt_2"] is None
|
||||
torch.testing.assert_close(
|
||||
encode_calls[0]["prompt_embeds"],
|
||||
torch.stack([prompt_embeds_a, prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
encode_calls[0]["pooled_prompt_embeds"],
|
||||
torch.stack([pooled_prompt_embeds_a, pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
assert encode_calls[1]["prompt"] is None
|
||||
assert encode_calls[1]["prompt_2"] is None
|
||||
torch.testing.assert_close(
|
||||
encode_calls[1]["prompt_embeds"],
|
||||
torch.stack([negative_prompt_embeds_a, negative_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
encode_calls[1]["pooled_prompt_embeds"],
|
||||
torch.stack([negative_pooled_prompt_embeds_a, negative_pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
diffuse_call["negative_pooled_prompt_embeds"],
|
||||
torch.stack([negative_pooled_prompt_embeds_a, negative_pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
assert prepare_latents_call["generator"] == [gen_a, gen_b]
|
||||
torch.testing.assert_close(prepare_latents_call["latents"], torch.cat([latents_a, latents_b], dim=0))
|
||||
torch.testing.assert_close(outputs[0].output, torch.tensor([[0.0]]))
|
||||
torch.testing.assert_close(outputs[1].output, torch.tensor([[1.0]]))
|
||||
@@ -39,7 +39,7 @@ def _make_minimal_request(
|
||||
)
|
||||
req = MagicMock()
|
||||
req.sampling_params = params
|
||||
req.prompts = [prompt]
|
||||
req.prompt = prompt
|
||||
req.multi_modal_data = {}
|
||||
return req
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ def test_pipeline_initializes_local_policy():
|
||||
def test_forward_returns_dict_actions_in_output():
|
||||
pipeline = _pipeline()
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=["pick"],
|
||||
prompt="pick",
|
||||
request_id="req",
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
extra_args={
|
||||
@@ -118,7 +118,7 @@ def test_forward_returns_dict_actions_in_output():
|
||||
def test_dummy_warmup_returns_shape_correct_zero_actions():
|
||||
pipeline = _pipeline()
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=["dummy run"],
|
||||
prompt="dummy run",
|
||||
request_id="dummy_req_id",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
)
|
||||
|
||||
@@ -19,6 +19,7 @@ from vllm_omni.diffusion.models.hunyuan_image3.pipeline_hunyuan_image3 import (
|
||||
HunyuanImage3Pipeline,
|
||||
)
|
||||
from vllm_omni.diffusion.worker.input_batch import InputBatch
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
from vllm_omni.diffusion.worker.utils import DiffusionRequestState
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
@@ -41,7 +42,7 @@ def _state(request_id: str, step_index: int) -> DiffusionRequestState:
|
||||
state = DiffusionRequestState(
|
||||
request_id=request_id,
|
||||
sampling=SimpleNamespace(),
|
||||
prompts=["prompt"],
|
||||
prompt="prompt",
|
||||
)
|
||||
state.step_index = step_index
|
||||
state.timesteps = torch.tensor([1.0, 0.5, 0.25, 0.0])
|
||||
@@ -135,7 +136,7 @@ def test_prepare_encode_preserves_normal_hunyuan_bot_task_semantics(
|
||||
state = DiffusionRequestState(
|
||||
request_id="req-bot-task",
|
||||
sampling=sampling,
|
||||
prompts=[prompt_item],
|
||||
prompt=prompt_item,
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="stop after prepare_model_inputs"):
|
||||
@@ -160,10 +161,14 @@ def test_forward_uses_same_hunyuan_bot_task_semantics(monkeypatch):
|
||||
|
||||
monkeypatch.setattr(hy3_module, "get_system_prompt", fake_get_system_prompt)
|
||||
pipeline.prepare_model_inputs = fake_prepare_model_inputs
|
||||
req = SimpleNamespace(
|
||||
request_id="req-forward-bot-task",
|
||||
sampling_params=_sampling_params(bot_task="think_recaption", use_system_prompt="dynamic"),
|
||||
prompts=[{"prompt": "prompt", "bot_task": "vanilla"}],
|
||||
req = DiffusionRequestBatch(
|
||||
requests=[
|
||||
SimpleNamespace(
|
||||
request_id="req-forward-bot-task",
|
||||
sampling_params=_sampling_params(bot_task="think_recaption", use_system_prompt="dynamic"),
|
||||
prompt={"prompt": "prompt", "bot_task": "vanilla"},
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="stop after prepare_model_inputs"):
|
||||
|
||||
@@ -10,6 +10,7 @@ Tests cover:
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import PIL.Image
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
@@ -19,6 +20,21 @@ import vllm_omni.diffusion.models.hunyuan_video.pipeline_hunyuan_video_1_5_i2v a
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
|
||||
def test_i2v_pre_process_uses_single_request_prompt():
|
||||
preprocess = i2v_module.get_hunyuan_video_15_i2v_pre_process_func(SimpleNamespace())
|
||||
image = PIL.Image.new("RGB", (640, 320))
|
||||
request = SimpleNamespace(
|
||||
prompt={"prompt": "turn this into a video", "multi_modal_data": {"image": image}},
|
||||
sampling_params=SimpleNamespace(height=None, width=None),
|
||||
)
|
||||
|
||||
result = preprocess(request)
|
||||
|
||||
assert result is request
|
||||
assert request.sampling_params.height == 448
|
||||
assert request.sampling_params.width == 896
|
||||
|
||||
|
||||
class TestHunyuanVideoQuantConfigPropagation:
|
||||
"""Verify quant_config is propagated to the transformer model in HunyuanVideo-1.5 pipelines."""
|
||||
|
||||
|
||||
@@ -465,6 +465,99 @@ class TestCFGParallelHelpers:
|
||||
class TestCFGParallelForwardPath:
|
||||
"""Test the LTX-2.3 CFG-parallel denoising path without loading model weights."""
|
||||
|
||||
def test_forward_collates_request_prompt_embeds_and_mask_aliases(self, monkeypatch):
|
||||
from vllm_omni.diffusion.models.ltx2 import pipeline_ltx2_3 as ltx23
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
pipe = object.__new__(ltx23.LTX23Pipeline)
|
||||
torch.nn.Module.__init__(pipe)
|
||||
pipe.device = torch.device("cpu")
|
||||
pipe.tokenizer_max_length = 4
|
||||
monkeypatch.setattr(ltx23, "get_classifier_free_guidance_world_size", lambda: 1)
|
||||
|
||||
class StopAtEncodePromptError(Exception):
|
||||
pass
|
||||
|
||||
captured = {}
|
||||
|
||||
def fake_encode_prompt(**kwargs):
|
||||
captured.update(kwargs)
|
||||
raise StopAtEncodePromptError
|
||||
|
||||
object.__setattr__(pipe, "encode_prompt", fake_encode_prompt)
|
||||
|
||||
prompt_embeds_a = torch.zeros(2, 3)
|
||||
prompt_embeds_b = torch.ones(2, 3)
|
||||
negative_prompt_embeds_a = torch.full((2, 3), 2.0)
|
||||
negative_prompt_embeds_b = torch.full((2, 3), 3.0)
|
||||
prompt_attention_mask_a = torch.tensor([True, True])
|
||||
prompt_attention_mask_b = torch.tensor([True, False])
|
||||
negative_attention_mask_a = torch.tensor([False, True])
|
||||
negative_attention_mask_b = torch.tensor([False, False])
|
||||
|
||||
requests = [
|
||||
OmniDiffusionRequest(
|
||||
prompt={
|
||||
"prompt": "prompt-a",
|
||||
"negative_prompt": "negative-a",
|
||||
"prompt_embeds": prompt_embeds_a,
|
||||
"negative_prompt_embeds": negative_prompt_embeds_a,
|
||||
"prompt_attention_mask": prompt_attention_mask_a,
|
||||
"negative_prompt_attention_mask": negative_attention_mask_a,
|
||||
},
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
height=32,
|
||||
width=32,
|
||||
num_frames=1,
|
||||
frame_rate=1.0,
|
||||
num_inference_steps=2,
|
||||
),
|
||||
request_id="ltx23-prompt-local-a",
|
||||
),
|
||||
OmniDiffusionRequest(
|
||||
prompt={
|
||||
"prompt": "prompt-b",
|
||||
"negative_prompt": "negative-b",
|
||||
"prompt_embeds": prompt_embeds_b,
|
||||
"negative_prompt_embeds": negative_prompt_embeds_b,
|
||||
"attention_mask": prompt_attention_mask_b,
|
||||
"negative_attention_mask": negative_attention_mask_b,
|
||||
},
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
height=32,
|
||||
width=32,
|
||||
num_frames=1,
|
||||
frame_rate=1.0,
|
||||
num_inference_steps=2,
|
||||
),
|
||||
request_id="ltx23-prompt-local-b",
|
||||
),
|
||||
]
|
||||
|
||||
with pytest.raises(StopAtEncodePromptError):
|
||||
pipe.forward(DiffusionRequestBatch(requests=requests))
|
||||
|
||||
assert captured["prompt"] is None
|
||||
assert captured["negative_prompt"] is None
|
||||
torch.testing.assert_close(
|
||||
captured["prompt_embeds"],
|
||||
torch.stack([prompt_embeds_a, prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
captured["negative_prompt_embeds"],
|
||||
torch.stack([negative_prompt_embeds_a, negative_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
captured["prompt_attention_mask"],
|
||||
torch.stack([prompt_attention_mask_a, prompt_attention_mask_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
captured["negative_prompt_attention_mask"],
|
||||
torch.stack([negative_attention_mask_a, negative_attention_mask_b], dim=0),
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize(("cfg_rank", "expected_prompt_value"), [(0, 1.0), (1, 0.0)])
|
||||
@pytest.mark.parametrize(
|
||||
("frame_rate_input", "audio_sampling_rate", "expected_frame_rate"),
|
||||
@@ -481,6 +574,7 @@ class TestCFGParallelForwardPath:
|
||||
):
|
||||
from vllm_omni.diffusion.models.ltx2 import pipeline_ltx2_3 as ltx23
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
pipe = object.__new__(ltx23.LTX23Pipeline)
|
||||
@@ -616,7 +710,7 @@ class TestCFGParallelForwardPath:
|
||||
video_latents = torch.tensor([[[1.0, -2.0]]])
|
||||
audio_latents = torch.tensor([[[0.5, 3.0]]])
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=[{"prompt": "prompt", "negative_prompt": "negative"}],
|
||||
prompt={"prompt": "prompt", "negative_prompt": "negative"},
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
height=32,
|
||||
width=32,
|
||||
@@ -631,7 +725,7 @@ class TestCFGParallelForwardPath:
|
||||
request_id="ltx23-cfg-parallel-forward-test",
|
||||
)
|
||||
|
||||
output = pipe.forward(req)
|
||||
output = pipe.forward(DiffusionRequestBatch(requests=[req]))[0]
|
||||
|
||||
expected_video_noise = ltx23.LTX23Pipeline._combine_x0_space_cfg(
|
||||
video_latents,
|
||||
|
||||
@@ -24,6 +24,7 @@ from vllm_omni.diffusion.data import OmniDiffusionConfig, TransformerConfig
|
||||
from vllm_omni.diffusion.distributed.utils import get_local_device
|
||||
from vllm_omni.diffusion.models.ovis_image.pipeline_ovis_image import OvisImagePipeline
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
|
||||
@@ -166,7 +167,7 @@ def test_basic_generation(ovis_pipeline):
|
||||
"""Test the forward pass logic."""
|
||||
# Setup request
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=["A photo of a cat"],
|
||||
prompt="A photo of a cat",
|
||||
request_id="ovis-basic",
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
height=256,
|
||||
@@ -176,7 +177,7 @@ def test_basic_generation(ovis_pipeline):
|
||||
),
|
||||
)
|
||||
|
||||
output = ovis_pipeline(req)
|
||||
output = ovis_pipeline(DiffusionRequestBatch(requests=[req]))
|
||||
|
||||
assert output is not None
|
||||
assert output.output is not None
|
||||
@@ -201,12 +202,10 @@ def test_guidance_scale(ovis_pipeline, monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setattr(f"{_cfg_parallel}.get_classifier_free_guidance_rank", lambda: 0)
|
||||
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=[
|
||||
{
|
||||
"prompt": "A photo of a cat",
|
||||
"negative_prompt": "bad quality",
|
||||
}
|
||||
],
|
||||
prompt={
|
||||
"prompt": "A photo of a cat",
|
||||
"negative_prompt": "bad quality",
|
||||
},
|
||||
request_id="ovis-guidance",
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
height=256,
|
||||
@@ -216,7 +215,7 @@ def test_guidance_scale(ovis_pipeline, monkeypatch: pytest.MonkeyPatch):
|
||||
),
|
||||
)
|
||||
|
||||
ovis_pipeline(req)
|
||||
ovis_pipeline(DiffusionRequestBatch(requests=[req]))
|
||||
assert ovis_pipeline.transformer.call_count >= 2
|
||||
|
||||
|
||||
@@ -226,7 +225,7 @@ def test_resolution_check(ovis_pipeline):
|
||||
"""Test resolution divisible validation logic if present."""
|
||||
# Pass odd resolution
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=["test"],
|
||||
prompt="test",
|
||||
request_id="ovis-resolution",
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
height=250, # Not divisible by 16 (8*2)
|
||||
@@ -237,7 +236,7 @@ def test_resolution_check(ovis_pipeline):
|
||||
# Should warn but proceed (as per code I read earlier) or resize?
|
||||
# The code had `logger.warning(...)`
|
||||
|
||||
output = ovis_pipeline(req)
|
||||
output = ovis_pipeline(DiffusionRequestBatch(requests=[req]))
|
||||
assert output is not None
|
||||
|
||||
|
||||
|
||||
@@ -25,12 +25,10 @@ def test_qwen_image_edit_plus_rejects_too_many_input_images(tmp_path: Path):
|
||||
pre_process = get_qwen_image_edit_plus_pre_process_func(SimpleNamespace(model=str(tmp_path)))
|
||||
image = Image.fromarray(np.zeros((32, 32, 3), dtype=np.uint8))
|
||||
request = SimpleNamespace(
|
||||
prompts=[
|
||||
{
|
||||
"prompt": "combine",
|
||||
"multi_modal_data": {"image": [image, image, image, image, image]},
|
||||
}
|
||||
],
|
||||
prompt={
|
||||
"prompt": "combine",
|
||||
"multi_modal_data": {"image": [image, image, image, image, image]},
|
||||
},
|
||||
sampling_params=SimpleNamespace(height=None, width=None),
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from vllm_omni.diffusion.models.qwen_image.pipeline_qwen_image_edit_plus import
|
||||
from vllm_omni.diffusion.models.qwen_image.pipeline_qwen_image_layered import (
|
||||
QwenImageLayeredPipeline,
|
||||
)
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
@@ -160,7 +161,7 @@ def test_prepare_encode_defaults_to_tokenizer_max_length():
|
||||
|
||||
pipeline._prepare_generation_context = _fake_prepare_generation_context
|
||||
state = SimpleNamespace(
|
||||
prompts=["prompt"],
|
||||
prompt="prompt",
|
||||
sampling=SimpleNamespace(
|
||||
height=None,
|
||||
width=None,
|
||||
@@ -179,6 +180,104 @@ def test_prepare_encode_defaults_to_tokenizer_max_length():
|
||||
assert captured["max_sequence_length"] == 1024
|
||||
|
||||
|
||||
def _make_request_batch_prompt_sampling(**overrides):
|
||||
values = {
|
||||
"height": 32,
|
||||
"width": 32,
|
||||
"num_inference_steps": 2,
|
||||
"sigmas": None,
|
||||
"max_sequence_length": None,
|
||||
"num_outputs_per_prompt": 0,
|
||||
"generator": None,
|
||||
"latents": None,
|
||||
"true_cfg_scale": None,
|
||||
"guidance_scale_provided": False,
|
||||
"guidance_scale": 1.0,
|
||||
}
|
||||
values.update(overrides)
|
||||
return SimpleNamespace(**values)
|
||||
|
||||
|
||||
def test_forward_collates_request_prompt_tensors_for_qwen_image():
|
||||
pipeline = object.__new__(QwenImagePipeline)
|
||||
nn.Module.__init__(pipeline)
|
||||
pipeline.vae_scale_factor = 8
|
||||
pipeline.default_sample_size = 128
|
||||
|
||||
class StopAfterPrepareContextError(Exception):
|
||||
pass
|
||||
|
||||
captured = {}
|
||||
|
||||
def _fake_prepare_generation_context(**kwargs):
|
||||
captured.update(kwargs)
|
||||
raise StopAfterPrepareContextError
|
||||
|
||||
pipeline._prepare_generation_context = _fake_prepare_generation_context
|
||||
|
||||
prompt_embeds_a = torch.zeros(2, 3)
|
||||
prompt_embeds_b = torch.ones(2, 3)
|
||||
prompt_embeds_mask_a = torch.tensor([True, True])
|
||||
prompt_embeds_mask_b = torch.tensor([True, False])
|
||||
negative_prompt_embeds_a = torch.full((2, 3), 2.0)
|
||||
negative_prompt_embeds_b = torch.full((2, 3), 3.0)
|
||||
negative_prompt_embeds_mask_a = torch.tensor([False, True])
|
||||
negative_prompt_embeds_mask_b = torch.tensor([False, False])
|
||||
|
||||
batch = DiffusionRequestBatch(
|
||||
requests=[
|
||||
SimpleNamespace(
|
||||
request_id="qwen-prompt-a",
|
||||
prompt={
|
||||
"prompt": "prompt-a",
|
||||
"negative_prompt": "negative-a",
|
||||
"prompt_embeds": prompt_embeds_a,
|
||||
"prompt_embeds_mask": prompt_embeds_mask_a,
|
||||
"negative_prompt_embeds": negative_prompt_embeds_a,
|
||||
"negative_prompt_embeds_mask": negative_prompt_embeds_mask_a,
|
||||
},
|
||||
sampling_params=_make_request_batch_prompt_sampling(),
|
||||
),
|
||||
SimpleNamespace(
|
||||
request_id="qwen-prompt-b",
|
||||
prompt={
|
||||
"prompt": "prompt-b",
|
||||
"negative_prompt": "negative-b",
|
||||
"additional_information": {
|
||||
"prompt_embeds": [prompt_embeds_b],
|
||||
"prompt_embeds_mask": [prompt_embeds_mask_b],
|
||||
"negative_prompt_embeds": [negative_prompt_embeds_b],
|
||||
"negative_prompt_embeds_mask": [negative_prompt_embeds_mask_b],
|
||||
},
|
||||
},
|
||||
sampling_params=_make_request_batch_prompt_sampling(),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
with pytest.raises(StopAfterPrepareContextError):
|
||||
pipeline.forward(batch)
|
||||
|
||||
assert captured["prompt"] is None
|
||||
assert captured["negative_prompt"] is None
|
||||
torch.testing.assert_close(
|
||||
captured["prompt_embeds"],
|
||||
torch.stack([prompt_embeds_a, prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
captured["prompt_embeds_mask"],
|
||||
torch.stack([prompt_embeds_mask_a, prompt_embeds_mask_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
captured["negative_prompt_embeds"],
|
||||
torch.stack([negative_prompt_embeds_a, negative_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
captured["negative_prompt_embeds_mask"],
|
||||
torch.stack([negative_prompt_embeds_mask_a, negative_prompt_embeds_mask_b], dim=0),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("pipeline_class", "drop_idx"),
|
||||
[
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from torch import nn
|
||||
|
||||
from vllm_omni.diffusion.models.sd3.pipeline_sd3 import StableDiffusion3Pipeline
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _make_sd3_sampling(**overrides):
|
||||
values = {
|
||||
"height": 32,
|
||||
"width": 32,
|
||||
"num_inference_steps": 2,
|
||||
"sigmas": None,
|
||||
"max_sequence_length": None,
|
||||
"num_outputs_per_prompt": 0,
|
||||
"generator": None,
|
||||
"latents": None,
|
||||
"guidance_scale": 4.0,
|
||||
}
|
||||
values.update(overrides)
|
||||
return SimpleNamespace(**values)
|
||||
|
||||
|
||||
def _make_sd3_pipeline():
|
||||
pipeline = object.__new__(StableDiffusion3Pipeline)
|
||||
nn.Module.__init__(pipeline)
|
||||
pipeline.vae_scale_factor = 8
|
||||
pipeline.patch_size = 2
|
||||
pipeline.default_sample_size = 128
|
||||
pipeline.transformer = SimpleNamespace(in_channels=1)
|
||||
return pipeline
|
||||
|
||||
|
||||
def test_forward_collates_request_prompt_tensors_for_sd3():
|
||||
pipeline = _make_sd3_pipeline()
|
||||
|
||||
class StopAfterDiffuseError(Exception):
|
||||
pass
|
||||
|
||||
encode_calls = []
|
||||
diffuse_call = {}
|
||||
|
||||
def _fake_encode_prompt(**kwargs):
|
||||
encode_calls.append(kwargs)
|
||||
prompt_embeds = kwargs["prompt_embeds"]
|
||||
if prompt_embeds is None:
|
||||
prompt_embeds = torch.empty(2, 2, 3)
|
||||
return prompt_embeds, kwargs.get("pooled_prompt_embeds")
|
||||
|
||||
def _fake_diffuse(**kwargs):
|
||||
diffuse_call.update(kwargs)
|
||||
raise StopAfterDiffuseError
|
||||
|
||||
pipeline.encode_prompt = _fake_encode_prompt
|
||||
pipeline.prepare_latents = lambda *args, **kwargs: torch.zeros(2, 1, 1, 1)
|
||||
pipeline.prepare_timesteps = lambda *args, **kwargs: (torch.tensor([1.0]), 1)
|
||||
pipeline.diffuse = _fake_diffuse
|
||||
|
||||
prompt_embeds_a = torch.zeros(2, 3)
|
||||
prompt_embeds_b = torch.ones(2, 3)
|
||||
pooled_prompt_embeds_a = torch.full((4,), 2.0)
|
||||
pooled_prompt_embeds_b = torch.full((4,), 3.0)
|
||||
negative_prompt_embeds_a = torch.full((2, 3), 4.0)
|
||||
negative_prompt_embeds_b = torch.full((2, 3), 5.0)
|
||||
negative_pooled_prompt_embeds_a = torch.full((4,), 6.0)
|
||||
negative_pooled_prompt_embeds_b = torch.full((4,), 7.0)
|
||||
|
||||
batch = DiffusionRequestBatch(
|
||||
requests=[
|
||||
SimpleNamespace(
|
||||
request_id="sd3-prompt-a",
|
||||
prompt={
|
||||
"prompt": "prompt-a",
|
||||
"negative_prompt": "negative-a",
|
||||
"prompt_embeds": prompt_embeds_a,
|
||||
"pooled_prompt_embeds": pooled_prompt_embeds_a,
|
||||
"negative_prompt_embeds": negative_prompt_embeds_a,
|
||||
"negative_pooled_prompt_embeds": negative_pooled_prompt_embeds_a,
|
||||
},
|
||||
sampling_params=_make_sd3_sampling(),
|
||||
),
|
||||
SimpleNamespace(
|
||||
request_id="sd3-prompt-b",
|
||||
prompt={
|
||||
"prompt": "prompt-b",
|
||||
"negative_prompt": "negative-b",
|
||||
"additional_information": {
|
||||
"prompt_embeds": [prompt_embeds_b],
|
||||
"pooled_prompt_embeds": [pooled_prompt_embeds_b],
|
||||
"negative_prompt_embeds": [negative_prompt_embeds_b],
|
||||
"negative_pooled_prompt_embeds": [negative_pooled_prompt_embeds_b],
|
||||
},
|
||||
},
|
||||
sampling_params=_make_sd3_sampling(),
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
with pytest.raises(StopAfterDiffuseError):
|
||||
pipeline.forward(batch)
|
||||
|
||||
assert encode_calls[0]["prompt"] is None
|
||||
assert encode_calls[0]["prompt_2"] is None
|
||||
assert encode_calls[0]["prompt_3"] is None
|
||||
torch.testing.assert_close(
|
||||
encode_calls[0]["prompt_embeds"],
|
||||
torch.stack([prompt_embeds_a, prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
encode_calls[0]["pooled_prompt_embeds"],
|
||||
torch.stack([pooled_prompt_embeds_a, pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
|
||||
assert encode_calls[1]["prompt"] is None
|
||||
assert encode_calls[1]["prompt_2"] is None
|
||||
assert encode_calls[1]["prompt_3"] is None
|
||||
torch.testing.assert_close(
|
||||
encode_calls[1]["prompt_embeds"],
|
||||
torch.stack([negative_prompt_embeds_a, negative_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
encode_calls[1]["pooled_prompt_embeds"],
|
||||
torch.stack([negative_pooled_prompt_embeds_a, negative_pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
diffuse_call["pooled_prompt_embeds"],
|
||||
torch.stack([pooled_prompt_embeds_a, pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
diffuse_call["negative_pooled_prompt_embeds"],
|
||||
torch.stack([negative_pooled_prompt_embeds_a, negative_pooled_prompt_embeds_b], dim=0),
|
||||
)
|
||||
|
||||
|
||||
def test_encode_prompt_preserves_direct_pooled_prompt_embeds():
|
||||
pipeline = _make_sd3_pipeline()
|
||||
prompt_embeds = torch.zeros(1, 2, 3)
|
||||
pooled_prompt_embeds = torch.ones(1, 4)
|
||||
|
||||
actual_prompt_embeds, actual_pooled_prompt_embeds = pipeline.encode_prompt(
|
||||
prompt=None,
|
||||
prompt_2=None,
|
||||
prompt_3=None,
|
||||
prompt_embeds=prompt_embeds,
|
||||
pooled_prompt_embeds=pooled_prompt_embeds,
|
||||
)
|
||||
|
||||
assert actual_prompt_embeds is prompt_embeds
|
||||
assert actual_pooled_prompt_embeds is pooled_prompt_embeds
|
||||
@@ -34,19 +34,19 @@ def _make_i2v_pipeline(*, expand_timesteps: bool) -> Wan22I2VPipeline:
|
||||
def test_i2v_preprocess_requires_image_and_resizes_to_480p_aspect() -> None:
|
||||
preprocess = get_wan22_i2v_pre_process_func(SimpleNamespace())
|
||||
request = SimpleNamespace(
|
||||
prompts=[{"prompt": "p", "multi_modal_data": {"image": Image.new("RGB", (320, 160), "red")}}],
|
||||
prompt={"prompt": "p", "multi_modal_data": {"image": Image.new("RGB", (320, 160), "red")}},
|
||||
sampling_params=SimpleNamespace(height=None, width=None),
|
||||
)
|
||||
|
||||
result = preprocess(request)
|
||||
prompt = result.prompts[0]
|
||||
prompt = result.prompt
|
||||
|
||||
assert result.sampling_params.height == 432
|
||||
assert result.sampling_params.width == 880
|
||||
assert prompt["multi_modal_data"]["image"].size == (880, 432)
|
||||
|
||||
missing_image = SimpleNamespace(
|
||||
prompts=[{"prompt": "p", "multi_modal_data": {}}],
|
||||
prompt={"prompt": "p", "multi_modal_data": {}},
|
||||
sampling_params=SimpleNamespace(height=None, width=None),
|
||||
)
|
||||
with pytest.raises(ValueError, match="No image is provided"):
|
||||
@@ -100,7 +100,10 @@ def test_i2v_diffuse_selects_stage_guidance_and_expands_timesteps() -> None:
|
||||
timestep_dtype = calls[0]["timestep_values"].dtype
|
||||
torch.testing.assert_close(calls[0]["timestep_values"][0, :4], torch.zeros(4, dtype=timestep_dtype))
|
||||
torch.testing.assert_close(calls[0]["timestep_values"][0, 4:], torch.full((4,), 900, dtype=timestep_dtype))
|
||||
torch.testing.assert_close(calls[0]["hidden_states"][:, :, 0], torch.ones(1, 4, 4, 4))
|
||||
torch.testing.assert_close(
|
||||
calls[0]["hidden_states"][:, :, 0],
|
||||
torch.ones_like(calls[0]["hidden_states"][:, :, 0]),
|
||||
)
|
||||
torch.testing.assert_close(result, torch.full_like(latents, 2.0))
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import torch
|
||||
from torch import nn
|
||||
|
||||
from vllm_omni.diffusion.models.wan2_2.pipeline_wan2_2 import Wan22Pipeline
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
@@ -77,8 +78,9 @@ def test_forward_delegates_denoising_to_diffuse(monkeypatch) -> None:
|
||||
|
||||
pipeline.diffuse = _fake_diffuse # type: ignore[method-assign]
|
||||
|
||||
req = SimpleNamespace(
|
||||
prompts=["prompt"],
|
||||
mock_req = SimpleNamespace(
|
||||
prompt="prompt",
|
||||
request_id="test-req",
|
||||
sampling_params=SimpleNamespace(
|
||||
height=None,
|
||||
width=None,
|
||||
@@ -96,8 +98,9 @@ def test_forward_delegates_denoising_to_diffuse(monkeypatch) -> None:
|
||||
extra_args={},
|
||||
),
|
||||
)
|
||||
batch = DiffusionRequestBatch(requests=[mock_req])
|
||||
|
||||
output = pipeline.forward(req, prompt_embeds=prompt_embeds, output_type="latent", guidance_scale=1.0)
|
||||
output = pipeline.forward(batch, prompt_embeds=prompt_embeds, output_type="latent", guidance_scale=1.0)
|
||||
|
||||
assert torch.equal(output.output, torch.ones((1, 4, 1, 8, 8)))
|
||||
assert torch.equal(captured["timesteps"], pipeline.scheduler.timesteps)
|
||||
|
||||
@@ -38,21 +38,19 @@ def test_vace_preprocess_collects_reference_video_and_mask_inputs() -> None:
|
||||
frame = Image.new("RGB", (64, 64), "black")
|
||||
mask = Image.new("L", (64, 64), 255)
|
||||
request = SimpleNamespace(
|
||||
prompts=[
|
||||
{
|
||||
"prompt": "p",
|
||||
"multi_modal_data": {
|
||||
"image": ref,
|
||||
"video": [frame],
|
||||
"mask": mask,
|
||||
},
|
||||
}
|
||||
],
|
||||
prompt={
|
||||
"prompt": "p",
|
||||
"multi_modal_data": {
|
||||
"image": ref,
|
||||
"video": [frame],
|
||||
"mask": mask,
|
||||
},
|
||||
},
|
||||
sampling_params=SimpleNamespace(height=None, width=None),
|
||||
)
|
||||
|
||||
result = preprocess(request)
|
||||
additional_info = result.prompts[0]["additional_information"]
|
||||
additional_info = result.prompt["additional_information"]
|
||||
|
||||
assert result.sampling_params.height == 432
|
||||
assert result.sampling_params.width == 880
|
||||
|
||||
@@ -11,8 +11,20 @@ from typing import Any
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from vllm_omni.diffusion.diffusion_engine import _move_tensor_tree_to_cpu
|
||||
import vllm_omni.diffusion.diffusion_engine as diffusion_engine_module
|
||||
from vllm_omni.diffusion.data import DiffusionOutput, OmniDiffusionConfig
|
||||
from vllm_omni.diffusion.diffusion_engine import DiffusionEngine, _move_tensor_tree_to_cpu
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.sched.interface import (
|
||||
CachedRequestData,
|
||||
NewRequestData,
|
||||
)
|
||||
from vllm_omni.diffusion.sched.interface import (
|
||||
DiffusionSchedulerOutput as RealDiffusionSchedulerOutput,
|
||||
)
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -66,6 +78,324 @@ class MockScheduler:
|
||||
return [req.request_id for req in sched_output.scheduled_new_reqs]
|
||||
|
||||
|
||||
class _BatchCapablePipeline:
|
||||
supports_request_batch = True
|
||||
|
||||
|
||||
class _SingleRequestPipeline:
|
||||
pass
|
||||
|
||||
|
||||
class _SingleRequestOverridePipeline(_BatchCapablePipeline):
|
||||
def forward(self, req, prompt_ids=None):
|
||||
return DiffusionOutput(output=None)
|
||||
|
||||
|
||||
def _make_request_mode_sched_output(*request_ids: str) -> RealDiffusionSchedulerOutput:
|
||||
new_reqs = [
|
||||
NewRequestData(
|
||||
request_id=request_id,
|
||||
req=OmniDiffusionRequest(
|
||||
prompt=f"prompt_{request_id}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id=request_id,
|
||||
),
|
||||
)
|
||||
for request_id in request_ids
|
||||
]
|
||||
return RealDiffusionSchedulerOutput(
|
||||
step_id=0,
|
||||
scheduled_new_reqs=new_reqs,
|
||||
scheduled_cached_reqs=CachedRequestData.make_empty(),
|
||||
finished_req_ids=set(),
|
||||
num_running_reqs=len(new_reqs),
|
||||
num_waiting_reqs=0,
|
||||
)
|
||||
|
||||
|
||||
class TestRequestBatchCapability:
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
def test_supports_request_batch_uses_registered_model_class(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
od_config = SimpleNamespace(model_class_name="BatchPipeline", custom_pipeline_args=None)
|
||||
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: _BatchCapablePipeline if model_class_name == "BatchPipeline" else None,
|
||||
)
|
||||
|
||||
assert diffusion_engine_module.supports_request_batch(od_config) is True
|
||||
|
||||
def test_supports_request_batch_uses_custom_pipeline_class(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="SinglePipeline",
|
||||
custom_pipeline_args={"pipeline_class": _BatchCapablePipeline},
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: _SingleRequestPipeline,
|
||||
)
|
||||
|
||||
assert diffusion_engine_module.supports_request_batch(od_config) is True
|
||||
|
||||
def test_supports_request_batch_uses_custom_pipeline_class_name(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="SinglePipeline",
|
||||
custom_pipeline_args={"pipeline_class": "test.module.BatchPipeline"},
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module,
|
||||
"resolve_obj_by_qualname",
|
||||
lambda qualname: _BatchCapablePipeline if qualname == "test.module.BatchPipeline" else None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: _SingleRequestPipeline,
|
||||
)
|
||||
|
||||
assert diffusion_engine_module.supports_request_batch(od_config) is True
|
||||
|
||||
def test_supports_request_batch_uses_only_explicit_pipeline_attribute_for_custom_override(
|
||||
self, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="BatchPipeline",
|
||||
custom_pipeline_args={"pipeline_class": _SingleRequestOverridePipeline},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: None,
|
||||
)
|
||||
|
||||
assert diffusion_engine_module.supports_request_batch(od_config) is True
|
||||
|
||||
def test_supports_request_batch_honors_explicit_false_on_custom_override(
|
||||
self, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
class _ExplicitlyUnsupportedOverride(_BatchCapablePipeline):
|
||||
supports_request_batch = False
|
||||
|
||||
def forward(self, req, prompt_ids=None):
|
||||
return DiffusionOutput(output=None)
|
||||
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="BatchPipeline",
|
||||
custom_pipeline_args={"pipeline_class": _ExplicitlyUnsupportedOverride},
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: None,
|
||||
)
|
||||
|
||||
assert diffusion_engine_module.supports_request_batch(od_config) is False
|
||||
|
||||
def test_supports_request_batch_rejects_invalid_custom_pipeline_class_name(
|
||||
self,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="BatchPipeline",
|
||||
custom_pipeline_args={"pipeline_class": "test.module.MissingPipeline"},
|
||||
)
|
||||
|
||||
def fail_resolve(qualname):
|
||||
raise ImportError(qualname)
|
||||
|
||||
monkeypatch.setattr(diffusion_engine_module, "resolve_obj_by_qualname", fail_resolve)
|
||||
registry_load = mocker.Mock(return_value=_BatchCapablePipeline)
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
registry_load,
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="Failed to resolve custom diffusion pipeline class"):
|
||||
diffusion_engine_module.supports_request_batch(od_config)
|
||||
registry_load.assert_not_called()
|
||||
|
||||
def test_engine_disables_batch_dispatch_for_single_request_pipeline(
|
||||
self,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="SinglePipeline",
|
||||
custom_pipeline_args=None,
|
||||
streaming_output=False,
|
||||
)
|
||||
fake_executor = SimpleNamespace(
|
||||
execute_request=mocker.Mock(return_value="per-request"),
|
||||
execute_batch=mocker.Mock(return_value="batch"),
|
||||
execute_step=mocker.Mock(return_value="step"),
|
||||
)
|
||||
fake_executor_cls = mocker.Mock(return_value=fake_executor)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.diffusion_engine.get_diffusion_post_process_func",
|
||||
lambda *args, **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.diffusion_engine.get_diffusion_pre_process_func",
|
||||
lambda *args, **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.diffusion_engine.DiffusionExecutor.get_class",
|
||||
lambda *args, **kwargs: fake_executor_cls,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: _SingleRequestPipeline,
|
||||
)
|
||||
monkeypatch.setattr(DiffusionEngine, "_dummy_run", lambda self: None)
|
||||
|
||||
engine = DiffusionEngine(od_config)
|
||||
output = engine.execute_fn(_make_request_mode_sched_output("req-a", "req-b"))
|
||||
|
||||
assert engine.supports_request_batch is False
|
||||
assert output == "per-request"
|
||||
fake_executor.execute_request.assert_called_once()
|
||||
fake_executor.execute_batch.assert_not_called()
|
||||
|
||||
@pytest.mark.parametrize("request_ids", [("req-a",), ("req-a", "req-b")])
|
||||
def test_engine_enables_batch_dispatch_for_request_batch_pipeline(
|
||||
self,
|
||||
request_ids: tuple[str, ...],
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
od_config = SimpleNamespace(
|
||||
model_class_name="BatchPipeline",
|
||||
custom_pipeline_args=None,
|
||||
streaming_output=False,
|
||||
)
|
||||
fake_executor = SimpleNamespace(
|
||||
execute_request=mocker.Mock(return_value="per-request"),
|
||||
execute_batch=mocker.Mock(return_value="batch"),
|
||||
execute_step=mocker.Mock(return_value="step"),
|
||||
)
|
||||
fake_executor_cls = mocker.Mock(return_value=fake_executor)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.diffusion_engine.get_diffusion_post_process_func",
|
||||
lambda *args, **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.diffusion_engine.get_diffusion_pre_process_func",
|
||||
lambda *args, **kwargs: None,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"vllm_omni.diffusion.diffusion_engine.DiffusionExecutor.get_class",
|
||||
lambda *args, **kwargs: fake_executor_cls,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
diffusion_engine_module.DiffusionModelRegistry,
|
||||
"_try_load_model_cls",
|
||||
lambda model_class_name: _BatchCapablePipeline,
|
||||
)
|
||||
monkeypatch.setattr(DiffusionEngine, "_dummy_run", lambda self: None)
|
||||
|
||||
engine = DiffusionEngine(od_config)
|
||||
output = engine.execute_fn(_make_request_mode_sched_output(*request_ids))
|
||||
|
||||
assert engine.supports_request_batch is True
|
||||
assert output == "batch"
|
||||
fake_executor.execute_batch.assert_called_once()
|
||||
fake_executor.execute_request.assert_not_called()
|
||||
|
||||
|
||||
class TestRequestBatchAdmission:
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
def test_config_rejects_negative_request_batch_max_wait_ms(self) -> None:
|
||||
with pytest.raises(ValueError, match="request_batch_max_wait_ms"):
|
||||
OmniDiffusionConfig(model="test", request_batch_max_wait_ms=-1.0)
|
||||
|
||||
def test_config_normalizes_request_batch_max_wait_ms_to_float(self) -> None:
|
||||
config = OmniDiffusionConfig(model="test", request_batch_max_wait_ms=5)
|
||||
|
||||
assert config.request_batch_max_wait_ms == 5.0
|
||||
assert isinstance(config.request_batch_max_wait_ms, float)
|
||||
|
||||
def test_scheduler_exposes_waiting_and_running_counts(self) -> None:
|
||||
from vllm_omni.diffusion.sched import RequestScheduler
|
||||
|
||||
od_config = SimpleNamespace(max_num_seqs=4)
|
||||
scheduler = RequestScheduler()
|
||||
scheduler.initialize(od_config)
|
||||
|
||||
assert scheduler.num_waiting_requests() == 0
|
||||
assert scheduler.num_running_requests() == 0
|
||||
|
||||
scheduler.add_request(
|
||||
OmniDiffusionRequest(
|
||||
prompt="prompt_a",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="req-a",
|
||||
)
|
||||
)
|
||||
scheduler.add_request(
|
||||
OmniDiffusionRequest(
|
||||
prompt="prompt_b",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="req-b",
|
||||
)
|
||||
)
|
||||
assert scheduler.num_waiting_requests() == 2
|
||||
assert scheduler.num_running_requests() == 0
|
||||
|
||||
scheduler.schedule()
|
||||
assert scheduler.num_waiting_requests() == 0
|
||||
assert scheduler.num_running_requests() == 2
|
||||
|
||||
def test_request_batch_admission_exits_early_when_waiting_queue_stable(self) -> None:
|
||||
from vllm_omni.diffusion.sched import RequestScheduler
|
||||
|
||||
od_config = SimpleNamespace(
|
||||
max_num_seqs=32,
|
||||
request_batch_max_wait_ms=1000.0,
|
||||
step_execution=False,
|
||||
)
|
||||
scheduler = RequestScheduler()
|
||||
scheduler.initialize(od_config)
|
||||
for idx in range(2):
|
||||
scheduler.add_request(
|
||||
OmniDiffusionRequest(
|
||||
prompt=f"prompt_{idx}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id=f"req-{idx}",
|
||||
)
|
||||
)
|
||||
|
||||
engine = object.__new__(DiffusionEngine)
|
||||
engine.od_config = od_config
|
||||
engine.scheduler = scheduler
|
||||
engine.step_execution = False
|
||||
engine.supports_request_batch = True
|
||||
engine.stop_event = threading.Event()
|
||||
engine._rpc_lock = threading.RLock()
|
||||
engine._cv = threading.Condition(engine._rpc_lock)
|
||||
|
||||
start = time.monotonic()
|
||||
with engine._cv:
|
||||
engine._wait_for_request_batch_admission_locked()
|
||||
waited_s = time.monotonic() - start
|
||||
|
||||
# Stable-window exit (~50ms), not the full 1000ms deadline.
|
||||
assert waited_s < 0.5
|
||||
assert waited_s >= 0.04
|
||||
assert scheduler.num_waiting_requests() == 2
|
||||
assert scheduler.num_running_requests() == 0
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.diffusion
|
||||
@pytest.mark.cpu
|
||||
@@ -142,8 +472,6 @@ def test_move_tensor_tree_moves_nested_cuda_tensors_to_cpu() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_async_add_req_and_wait_for_response():
|
||||
from vllm_omni.diffusion.diffusion_engine import DiffusionEngine
|
||||
|
||||
engine = object.__new__(DiffusionEngine)
|
||||
engine.scheduler = MockScheduler()
|
||||
engine._out_queue = {}
|
||||
@@ -153,8 +481,10 @@ async def test_async_add_req_and_wait_for_response():
|
||||
engine._cv = threading.Condition(engine._rpc_lock)
|
||||
engine._init_lock = asyncio.Lock()
|
||||
engine._closed = False
|
||||
engine.od_config = SimpleNamespace(streaming_output=False)
|
||||
engine._loop_started = False
|
||||
engine.main_loop = None
|
||||
engine.supports_request_batch = False
|
||||
|
||||
engine._finalize_finished_request = lambda rid, out, err: out.result
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
def _make_request(request_id: str) -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(
|
||||
prompts=[f"prompt_{request_id}"],
|
||||
prompt=f"prompt_{request_id}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id=request_id,
|
||||
)
|
||||
|
||||
@@ -32,12 +32,12 @@ import pytest
|
||||
from vllm_omni.diffusion.data import DiffusionOutput
|
||||
from vllm_omni.diffusion.diffusion_engine import DiffusionEngine, _RpcTask
|
||||
from vllm_omni.diffusion.sched import RequestScheduler
|
||||
from vllm_omni.diffusion.sched.interface import SamplingParamsKey
|
||||
from vllm_omni.diffusion.sched.interface import RequestBatchSamplingParamsKey
|
||||
from vllm_omni.diffusion.worker.utils import RunnerOutput
|
||||
|
||||
# Default values for every batch-key field, so SimpleNamespace-based
|
||||
# sampling_params satisfy ``get_sampling_params_key``'s attribute lookups.
|
||||
_SAMPLING_KEY_DEFAULTS = {f.name: f.default for f in _dc_fields(SamplingParamsKey)}
|
||||
_SAMPLING_KEY_DEFAULTS = {f.name: f.default for f in _dc_fields(RequestBatchSamplingParamsKey)}
|
||||
|
||||
pytestmark = [pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
@@ -59,6 +59,7 @@ class _ConcurrencyTrackingExecutor:
|
||||
self.rpc_delay = rpc_delay
|
||||
self.is_failed = False
|
||||
self._closed = False
|
||||
self.od_config = SimpleNamespace()
|
||||
|
||||
def collective_rpc(
|
||||
self,
|
||||
@@ -101,14 +102,15 @@ class _ConcurrencyTrackingExecutor:
|
||||
# Mimic the real MultiprocDiffusionExecutor.execute_request: it
|
||||
# forwards a single request through collective_rpc.
|
||||
new_req = scheduler_output.scheduled_new_reqs[0]
|
||||
req = new_req.req
|
||||
result = self.collective_rpc(
|
||||
"execute_model",
|
||||
args=(new_req.req,),
|
||||
args=(req, self.od_config),
|
||||
unique_reply_rank=0,
|
||||
exec_all_ranks=True,
|
||||
)
|
||||
return RunnerOutput(
|
||||
request_id=new_req.request_id,
|
||||
request_id=req.request_id,
|
||||
step_index=None,
|
||||
finished=True,
|
||||
result=result,
|
||||
@@ -119,10 +121,12 @@ class _ConcurrencyTrackingExecutor:
|
||||
|
||||
|
||||
def _make_request(tag: str):
|
||||
sampling_params = dict(_SAMPLING_KEY_DEFAULTS)
|
||||
sampling_params["num_inference_steps"] = 1
|
||||
return SimpleNamespace(
|
||||
request_id=tag,
|
||||
prompts=[f"prompt_{tag}"],
|
||||
sampling_params=SimpleNamespace(num_inference_steps=1, **_SAMPLING_KEY_DEFAULTS),
|
||||
prompt=f"prompt_{tag}",
|
||||
sampling_params=SimpleNamespace(**sampling_params),
|
||||
)
|
||||
|
||||
|
||||
@@ -137,17 +141,20 @@ def _make_engine_with_loop(
|
||||
"""
|
||||
engine = DiffusionEngine.__new__(DiffusionEngine)
|
||||
engine._closed = False
|
||||
engine.od_config = SimpleNamespace(streaming_output=False)
|
||||
engine.executor = _ConcurrencyTrackingExecutor(rpc_delay=rpc_delay)
|
||||
|
||||
sched = RequestScheduler()
|
||||
sched.initialize(SimpleNamespace(max_num_seqs=1))
|
||||
engine.scheduler = sched
|
||||
engine.step_execution = False
|
||||
engine.supports_request_batch = False
|
||||
engine.execute_fn = engine.executor.execute_request
|
||||
|
||||
engine._rpc_lock = threading.RLock()
|
||||
engine._cv = threading.Condition(engine._rpc_lock)
|
||||
engine._out_queue = {}
|
||||
engine._out_queue_streaming = {}
|
||||
engine._closed = False
|
||||
engine.abort_queue = queue.Queue()
|
||||
engine._rpc_queue = queue.Queue()
|
||||
|
||||
@@ -15,6 +15,7 @@ from vllm_omni.diffusion.ipc import (
|
||||
pack_diffusion_output_shm,
|
||||
unpack_diffusion_output_shm,
|
||||
)
|
||||
from vllm_omni.diffusion.worker.utils import BatchRunnerOutput, RunnerOutput
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
@@ -107,6 +108,30 @@ def test_rpc_result_envelope_diffusion_output_round_trips_through_shm() -> None:
|
||||
assert unpacked["rank_statuses"] == [{"rank": 0, "ok": True}]
|
||||
|
||||
|
||||
def test_batch_runner_output_round_trips_nested_results_through_shm() -> None:
|
||||
first = torch.arange(_large_numel(torch.float32), dtype=torch.float32)
|
||||
second = torch.arange(_large_numel(torch.float32), dtype=torch.float32) + 1
|
||||
output = BatchRunnerOutput.from_list(
|
||||
[
|
||||
RunnerOutput(request_id="req-0", finished=True, result=DiffusionOutput(output=first)),
|
||||
RunnerOutput(request_id="req-1", finished=True, result=DiffusionOutput(output={"image": second})),
|
||||
RunnerOutput(request_id="req-error", finished=True, result=DiffusionOutput(error="boom")),
|
||||
]
|
||||
)
|
||||
|
||||
pack_diffusion_output_shm(output)
|
||||
|
||||
assert output.runner_outputs[0].result.output["__tensor_shm__"] is True
|
||||
assert output.runner_outputs[1].result.output["image"]["__tensor_shm__"] is True
|
||||
assert output.runner_outputs[2].result.error == "boom"
|
||||
|
||||
unpack_diffusion_output_shm(output)
|
||||
|
||||
torch.testing.assert_close(output["req-0"].result.output, first)
|
||||
torch.testing.assert_close(output["req-1"].result.output["image"], second)
|
||||
assert output["req-error"].result.error == "boom"
|
||||
|
||||
|
||||
def test_pack_value_keeps_tensor_at_threshold_inline() -> None:
|
||||
tensor = torch.arange(
|
||||
_SHM_TENSOR_THRESHOLD // torch.empty((), dtype=torch.float32).element_size(),
|
||||
|
||||
@@ -11,6 +11,7 @@ import vllm_omni.diffusion.worker.diffusion_model_runner as model_runner_module
|
||||
from tests.helpers.mark import hardware_test
|
||||
from vllm_omni.diffusion.data import DiffusionOutput
|
||||
from vllm_omni.diffusion.worker.diffusion_model_runner import DiffusionModelRunner
|
||||
from vllm_omni.diffusion.worker.request_batch import DiffusionRequestBatch, split_diffusion_output_by_request
|
||||
|
||||
pytestmark = [pytest.mark.diffusion]
|
||||
|
||||
@@ -22,14 +23,39 @@ def _noop_forward_context(*args, **kwargs):
|
||||
|
||||
|
||||
class _DummyPipeline:
|
||||
supports_request_batch = True
|
||||
|
||||
def __init__(self, output):
|
||||
self._output = output
|
||||
self.forward_calls = 0
|
||||
self.last_req = None
|
||||
|
||||
def forward(self, req):
|
||||
del req
|
||||
self.last_req = req
|
||||
self.forward_calls += 1
|
||||
return self._output
|
||||
return [self._output]
|
||||
|
||||
|
||||
class _SingleRequestBatchPipeline:
|
||||
supports_request_batch = False
|
||||
|
||||
def __init__(self):
|
||||
self.last_req = None
|
||||
|
||||
def forward(self, req):
|
||||
self.last_req = req
|
||||
return [DiffusionOutput(output=req.prompts[0])]
|
||||
|
||||
|
||||
class _SingleRequestDiffusionOutputPipeline:
|
||||
supports_request_batch = False
|
||||
|
||||
def __init__(self):
|
||||
self.last_req = None
|
||||
|
||||
def forward(self, req):
|
||||
self.last_req = req
|
||||
return DiffusionOutput(output=req.prompts[0])
|
||||
|
||||
|
||||
class _ChunkStepPipeline:
|
||||
@@ -81,9 +107,28 @@ def _make_request(skip_cache_refresh: bool = True):
|
||||
)
|
||||
return SimpleNamespace(
|
||||
request_id="req-test",
|
||||
prompts=["a prompt"],
|
||||
prompt="a prompt",
|
||||
sampling_params=sampling_params,
|
||||
skip_cache_refresh=skip_cache_refresh,
|
||||
kv_sender_info=None,
|
||||
)
|
||||
|
||||
|
||||
def _make_request_with_params(req_id: str, sampling_params):
|
||||
return SimpleNamespace(
|
||||
request_id=req_id,
|
||||
prompt=f"prompt-{req_id}",
|
||||
prompts=[f"prompt-{req_id}"],
|
||||
sampling_params=sampling_params,
|
||||
skip_cache_refresh=True,
|
||||
)
|
||||
|
||||
|
||||
def _fake_platform_for_peak_memory():
|
||||
return SimpleNamespace(
|
||||
reset_peak_memory_stats=lambda: None,
|
||||
max_memory_reserved=lambda: 0,
|
||||
max_memory_allocated=lambda: 0,
|
||||
)
|
||||
|
||||
|
||||
@@ -91,7 +136,7 @@ def _make_runner(cache_backend, cache_backend_name: str, enable_cache_dit_summar
|
||||
runner = object.__new__(DiffusionModelRunner)
|
||||
runner.vllm_config = object()
|
||||
runner.device = torch.device("cpu")
|
||||
runner.pipeline = _DummyPipeline(output=SimpleNamespace(output="ok"))
|
||||
runner.pipeline = _DummyPipeline(output=DiffusionOutput(output="ok"))
|
||||
runner.cache_backend = cache_backend
|
||||
runner.offload_backend = None
|
||||
runner.state_cache = {}
|
||||
@@ -238,6 +283,232 @@ def test_execute_model_emits_cache_summary_with_active_cache_dit_backend(monkeyp
|
||||
assert cache_summary_calls == [(runner.pipeline, True)]
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_passes_single_request_batch_to_non_admission_pipeline(monkeypatch):
|
||||
runner = _make_runner(cache_backend=None, cache_backend_name="none")
|
||||
runner.pipeline = _SingleRequestBatchPipeline()
|
||||
req = _make_request(skip_cache_refresh=True)
|
||||
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
|
||||
output = DiffusionModelRunner.execute_model(runner, req)
|
||||
|
||||
assert output.output == "a prompt"
|
||||
assert isinstance(runner.pipeline.last_req, DiffusionRequestBatch)
|
||||
assert runner.pipeline.last_req.num_reqs == 1
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_accepts_bare_diffusion_output_from_single_request_pipeline(monkeypatch):
|
||||
runner = _make_runner(cache_backend=None, cache_backend_name="none")
|
||||
runner.pipeline = _SingleRequestDiffusionOutputPipeline()
|
||||
req = _make_request(skip_cache_refresh=True)
|
||||
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
|
||||
output = DiffusionModelRunner.execute_model(runner, req)
|
||||
|
||||
assert output.output == "a prompt"
|
||||
assert isinstance(runner.pipeline.last_req, DiffusionRequestBatch)
|
||||
assert runner.pipeline.last_req.num_reqs == 1
|
||||
|
||||
|
||||
class _BatchPipeline:
|
||||
"""Pipeline returning a configurable list of outputs from forward()."""
|
||||
|
||||
supports_request_batch = True
|
||||
|
||||
def __init__(self, outputs):
|
||||
self._outputs = outputs
|
||||
self.last_batch = None
|
||||
|
||||
def forward(self, batch):
|
||||
self.last_batch = batch
|
||||
return list(self._outputs)
|
||||
|
||||
|
||||
class _SingleRequestPipeline:
|
||||
def forward(self, batch):
|
||||
del batch
|
||||
return [DiffusionOutput(output="single")]
|
||||
|
||||
|
||||
class _BatchSingleOutputPipeline:
|
||||
supports_request_batch = True
|
||||
|
||||
def forward(self, batch):
|
||||
return DiffusionOutput(output=batch.prompts[0])
|
||||
|
||||
|
||||
def _make_batch_runner(pipeline):
|
||||
runner = object.__new__(DiffusionModelRunner)
|
||||
runner.vllm_config = object()
|
||||
runner.device = torch.device("cpu")
|
||||
runner.pipeline = pipeline
|
||||
runner.cache_backend = None
|
||||
runner.offload_backend = None
|
||||
runner.od_config = SimpleNamespace(
|
||||
cache_backend="none",
|
||||
enable_cache_dit_summary=False,
|
||||
parallel_config=SimpleNamespace(use_hsdp=False),
|
||||
)
|
||||
runner.kv_transfer_manager = SimpleNamespace(
|
||||
receive_multi_kv_cache_distributed=lambda req, cfg_kv_collect_func=None, target_device=None: None,
|
||||
)
|
||||
return runner
|
||||
|
||||
|
||||
def _make_scheduler_output(num_reqs: int):
|
||||
reqs = [_make_request() for _ in range(num_reqs)]
|
||||
for i, req in enumerate(reqs):
|
||||
req.request_id = f"req-{i}"
|
||||
return SimpleNamespace(scheduled_new_reqs=[SimpleNamespace(req=req) for req in reqs])
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_batch_rejects_output_count_mismatch(monkeypatch):
|
||||
"""A pipeline returning the wrong number of outputs must fail loudly,
|
||||
not silently drop requests or IndexError on the per-request mapping."""
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", _fake_platform_for_peak_memory())
|
||||
# forward returns 1 output for 2 scheduled requests
|
||||
runner = _make_batch_runner(_BatchPipeline(outputs=[DiffusionOutput(output="only-one")]))
|
||||
sched = _make_scheduler_output(num_reqs=2)
|
||||
|
||||
with pytest.raises(RuntimeError, match="returned 1 outputs for 2 requests"):
|
||||
DiffusionModelRunner.execute_model_batch(runner, sched, runner.od_config)
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_batch_routes_one_output_per_request(monkeypatch):
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", _fake_platform_for_peak_memory())
|
||||
outs = [DiffusionOutput(output="a"), DiffusionOutput(output="b")]
|
||||
runner = _make_batch_runner(_BatchPipeline(outputs=outs))
|
||||
sched = _make_scheduler_output(num_reqs=2)
|
||||
|
||||
result = DiffusionModelRunner.execute_model_batch(runner, sched, runner.od_config)
|
||||
|
||||
assert len(result.runner_outputs) == 2
|
||||
assert result.runner_outputs[0].request_id == "req-0"
|
||||
assert result.runner_outputs[0].result.output == "a"
|
||||
assert result.runner_outputs[1].request_id == "req-1"
|
||||
assert result.runner_outputs[1].result.output == "b"
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_batch_preserves_per_request_sampling_and_seeds_generators(monkeypatch):
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", _fake_platform_for_peak_memory())
|
||||
outputs = [DiffusionOutput(output="a"), DiffusionOutput(output="b")]
|
||||
pipeline = _BatchPipeline(outputs=outputs)
|
||||
runner = _make_batch_runner(pipeline)
|
||||
sched = _make_scheduler_output(num_reqs=2)
|
||||
sched.scheduled_new_reqs[0].req.sampling_params.seed = 111
|
||||
sched.scheduled_new_reqs[1].req.sampling_params.seed = 222
|
||||
|
||||
DiffusionModelRunner.execute_model_batch(runner, sched, runner.od_config)
|
||||
|
||||
assert pipeline.last_batch is not None
|
||||
assert [sp.seed for sp in pipeline.last_batch.sampling_params_list] == [111, 222]
|
||||
assert [sp.generator.initial_seed() for sp in pipeline.last_batch.sampling_params_list] == [111, 222]
|
||||
with pytest.raises(AssertionError, match="multiple requests"):
|
||||
_ = pipeline.last_batch.sampling_params
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_batch_rejects_pipeline_without_request_batch_support(monkeypatch):
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", _fake_platform_for_peak_memory())
|
||||
runner = _make_batch_runner(_SingleRequestPipeline())
|
||||
sched = _make_scheduler_output(num_reqs=2)
|
||||
|
||||
with pytest.raises(RuntimeError, match="does not support request-batch forward"):
|
||||
DiffusionModelRunner.execute_model_batch(runner, sched, runner.od_config)
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_batch_rejects_single_diffusion_output(monkeypatch):
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", _fake_platform_for_peak_memory())
|
||||
runner = _make_batch_runner(_BatchSingleOutputPipeline())
|
||||
sched = _make_scheduler_output(num_reqs=1)
|
||||
|
||||
with pytest.raises(RuntimeError, match="request-batch forward must return list\\[DiffusionOutput\\]"):
|
||||
DiffusionModelRunner.execute_model_batch(runner, sched, runner.od_config)
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_execute_model_batch_uses_runner_output_helper(monkeypatch):
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", _fake_platform_for_peak_memory())
|
||||
outs = [DiffusionOutput(output="a"), DiffusionOutput(output="b")]
|
||||
runner = _make_batch_runner(_BatchPipeline(outputs=outs))
|
||||
sched = _make_scheduler_output(num_reqs=2)
|
||||
helper_calls = []
|
||||
original_from_outputs = DiffusionModelRunner._runner_output_from_outputs
|
||||
|
||||
def _recording_from_outputs(self, reqs, outputs):
|
||||
helper_calls.append(([req.request_id for req in reqs], [output.output for output in outputs]))
|
||||
return original_from_outputs(self, reqs, outputs)
|
||||
|
||||
monkeypatch.setattr(DiffusionModelRunner, "_runner_output_from_outputs", _recording_from_outputs)
|
||||
|
||||
result = DiffusionModelRunner.execute_model_batch(runner, sched, runner.od_config)
|
||||
|
||||
assert [runner_output.result.output for runner_output in result.runner_outputs] == ["a", "b"]
|
||||
assert helper_calls == [(["req-0", "req-1"], ["a", "b"])]
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_split_diffusion_output_by_request_slices_single_and_multi_request_outputs():
|
||||
reqs = [_make_request(), _make_request()]
|
||||
reqs[0].request_id = "req-0"
|
||||
reqs[1].request_id = "req-1"
|
||||
batch = DiffusionRequestBatch(requests=reqs)
|
||||
result = DiffusionOutput(output=["img-0a", "img-0b", "img-1a", "img-1b"], stage_durations={"decode": 1.0})
|
||||
|
||||
outputs = split_diffusion_output_by_request(result, batch, num_outputs_per_prompt=2)
|
||||
|
||||
assert [output.output for output in outputs] == [["img-0a", "img-0b"], ["img-1a", "img-1b"]]
|
||||
assert [output.stage_durations for output in outputs] == [{"decode": 1.0}, {"decode": 1.0}]
|
||||
|
||||
single = split_diffusion_output_by_request(
|
||||
result, DiffusionRequestBatch(requests=reqs[:1]), num_outputs_per_prompt=2
|
||||
)
|
||||
|
||||
assert single[0].output == ["img-0a", "img-0b"]
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_split_diffusion_output_by_request_slices_tuple_outputs():
|
||||
reqs = [_make_request(), _make_request()]
|
||||
batch = DiffusionRequestBatch(requests=reqs)
|
||||
result = DiffusionOutput(
|
||||
output=(
|
||||
["video-0", "video-1"],
|
||||
torch.tensor([10, 20]),
|
||||
)
|
||||
)
|
||||
|
||||
outputs = split_diffusion_output_by_request(result, batch, num_outputs_per_prompt=1)
|
||||
|
||||
assert outputs[0].output[0] == ["video-0"]
|
||||
assert torch.equal(outputs[0].output[1], torch.tensor([10]))
|
||||
assert outputs[1].output[0] == ["video-1"]
|
||||
assert torch.equal(outputs[1].output[1], torch.tensor([20]))
|
||||
|
||||
|
||||
@pytest.mark.core_model
|
||||
@pytest.mark.cpu
|
||||
def test_load_model_clears_cache_backend_for_unsupported_pipeline(monkeypatch):
|
||||
|
||||
@@ -23,12 +23,12 @@ pytestmark = [pytest.mark.diffusion, pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _request(
|
||||
prompts: list[str] | None = None,
|
||||
prompt: str | dict | None = None,
|
||||
*,
|
||||
num_outputs_per_prompt: int = 1,
|
||||
) -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(
|
||||
prompts=prompts or ["prompt"],
|
||||
prompt=prompt or "prompt",
|
||||
request_id="req-1",
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
num_inference_steps=1,
|
||||
@@ -69,7 +69,7 @@ def test_formatter_preserves_single_video_audio_actions_and_custom_output(
|
||||
)
|
||||
|
||||
results = format_diffusion_outputs(
|
||||
request=_request(["prompt-0"]),
|
||||
request=_request("prompt-0"),
|
||||
od_config=_config(),
|
||||
diffusion_output=DiffusionOutput(
|
||||
output=None,
|
||||
@@ -118,7 +118,7 @@ def test_formatter_preserves_text_custom_output(monkeypatch: pytest.MonkeyPatch)
|
||||
)
|
||||
|
||||
[result] = format_diffusion_outputs(
|
||||
request=_request(["describe this"]),
|
||||
request=_request("describe this"),
|
||||
od_config=_config(),
|
||||
diffusion_output=DiffusionOutput(output="caption"),
|
||||
output_data="caption",
|
||||
@@ -147,7 +147,7 @@ def test_formatter_preserves_audio_output_with_model_sample_rate_fallback(
|
||||
postprocess_output = normalize_diffusion_postprocess_output(["waveform"], {})
|
||||
|
||||
[result] = format_diffusion_outputs(
|
||||
request=_request(["speak"]),
|
||||
request=_request("speak"),
|
||||
od_config=_config("audio_model"),
|
||||
diffusion_output=DiffusionOutput(output=["waveform"]),
|
||||
output_data=["waveform"],
|
||||
@@ -180,7 +180,7 @@ def test_formatter_preserves_audio_model_video_audio_and_actions(
|
||||
)
|
||||
|
||||
[result] = format_diffusion_outputs(
|
||||
request=_request(["watch and listen"]),
|
||||
request=_request("watch and listen"),
|
||||
od_config=_config("audio_video_model"),
|
||||
diffusion_output=DiffusionOutput(output=None),
|
||||
output_data={"raw": "output"},
|
||||
@@ -212,7 +212,7 @@ def test_formatter_preserves_audio_only_postprocess_dict(
|
||||
)
|
||||
|
||||
[result] = format_diffusion_outputs(
|
||||
request=_request(["speak"]),
|
||||
request=_request("speak"),
|
||||
od_config=_config("audio_model"),
|
||||
diffusion_output=DiffusionOutput(output=None),
|
||||
output_data={"raw": "output"},
|
||||
@@ -241,7 +241,7 @@ def test_formatter_preserves_single_prompt_multiple_audio_outputs(
|
||||
postprocess_output = normalize_diffusion_postprocess_output(["waveform-0", "waveform-1"], {})
|
||||
|
||||
[result] = format_diffusion_outputs(
|
||||
request=_request(["speak"], num_outputs_per_prompt=2),
|
||||
request=_request("speak", num_outputs_per_prompt=2),
|
||||
od_config=_config("audio_model"),
|
||||
diffusion_output=DiffusionOutput(output=["waveform-0", "waveform-1"]),
|
||||
output_data=["waveform-0", "waveform-1"],
|
||||
@@ -255,7 +255,7 @@ def test_formatter_preserves_single_prompt_multiple_audio_outputs(
|
||||
assert result.multimodal_output == {"audio": ["waveform-0", "waveform-1"]}
|
||||
|
||||
|
||||
def test_formatter_preserves_multi_prompt_audio_and_action_slicing(
|
||||
def test_formatter_preserves_single_prompt_audio_and_action_payloads(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(output_formatter, "supports_audio_output", lambda _: False)
|
||||
@@ -271,7 +271,7 @@ def test_formatter_preserves_multi_prompt_audio_and_action_slicing(
|
||||
)
|
||||
|
||||
results = format_diffusion_outputs(
|
||||
request=_request(["prompt-0", "prompt-1"]),
|
||||
request=_request("prompt-0"),
|
||||
od_config=_config(),
|
||||
diffusion_output=DiffusionOutput(output=None),
|
||||
output_data={"raw": "output"},
|
||||
@@ -279,29 +279,22 @@ def test_formatter_preserves_multi_prompt_audio_and_action_slicing(
|
||||
timings=_timings(),
|
||||
)
|
||||
|
||||
assert len(results) == 2
|
||||
assert results[0].images == ["frame-0"]
|
||||
assert results[1].images == ["frame-1"]
|
||||
assert len(results) == 1
|
||||
assert results[0].images == ["frame-0", "frame-1"]
|
||||
assert results[0].prompt == "prompt-0"
|
||||
assert results[0].custom_output == {"shared": True}
|
||||
assert results[1].custom_output == {"shared": True}
|
||||
assert results[0].multimodal_output["audio"] == "audio-0"
|
||||
assert results[1].multimodal_output["audio"] == "audio-1"
|
||||
assert results[0].multimodal_output["audio"] == ["audio-0", "audio-1"]
|
||||
assert results[0].multimodal_output["fps"] == 12.5
|
||||
assert results[1].multimodal_output["fps"] == 12.5
|
||||
torch.testing.assert_close(
|
||||
results[0].multimodal_output["actions"],
|
||||
torch.tensor([1.0, 2.0]),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
results[1].multimodal_output["actions"],
|
||||
torch.tensor([3.0, 4.0]),
|
||||
torch.tensor([[1.0, 2.0], [3.0, 4.0]]),
|
||||
)
|
||||
|
||||
|
||||
def test_format_empty_diffusion_outputs_preserves_empty_response_shape() -> None:
|
||||
results = format_empty_diffusion_outputs(_request(["prompt-0", "prompt-1"]))
|
||||
results = format_empty_diffusion_outputs(_request("prompt-0"))
|
||||
|
||||
assert len(results) == 2
|
||||
assert [result.prompt for result in results] == ["prompt-0", "prompt-1"]
|
||||
assert [result.images for result in results] == [[], []]
|
||||
assert [result.metrics for result in results] == [{}, {}]
|
||||
assert len(results) == 1
|
||||
assert [result.prompt for result in results] == ["prompt-0"]
|
||||
assert [result.images for result in results] == [[]]
|
||||
assert [result.metrics for result in results] == [{}]
|
||||
@@ -13,7 +13,7 @@ pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
def _make_request() -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(
|
||||
prompts=[{"prompt": "a cup of coffee on a table"}],
|
||||
prompt={"prompt": "a cup of coffee on a table"},
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="request-test",
|
||||
)
|
||||
@@ -22,7 +22,7 @@ def _make_request() -> OmniDiffusionRequest:
|
||||
def test_request_id_is_required():
|
||||
with pytest.raises(TypeError, match="request_id"):
|
||||
OmniDiffusionRequest(
|
||||
prompts=[{"prompt": "a cup of coffee on a table"}],
|
||||
prompt={"prompt": "a cup of coffee on a table"},
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_request_ids_identity_list_is_removed():
|
||||
def test_request_id_must_be_non_empty():
|
||||
with pytest.raises(ValueError, match="request_id must be a non-empty string"):
|
||||
OmniDiffusionRequest(
|
||||
prompts=[{"prompt": "a cup of coffee on a table"}],
|
||||
prompt={"prompt": "a cup of coffee on a table"},
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="",
|
||||
)
|
||||
@@ -45,7 +45,7 @@ def test_request_id_must_be_non_empty():
|
||||
|
||||
def test_dummy_run_request_is_identified_by_reserved_request_id():
|
||||
req = OmniDiffusionRequest(
|
||||
prompts=[{"prompt": "dummy run"}],
|
||||
prompt={"prompt": "dummy run"},
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id=DUMMY_DIFFUSION_REQUEST_ID,
|
||||
)
|
||||
|
||||
@@ -29,7 +29,7 @@ pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
def _make_request(req_id: str) -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(
|
||||
prompts=[f"prompt_{req_id}"],
|
||||
prompt=f"prompt_{req_id}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id=req_id,
|
||||
)
|
||||
@@ -67,7 +67,7 @@ def _make_step_request(
|
||||
sampling_params: OmniDiffusionSamplingParams | None = None,
|
||||
) -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(
|
||||
prompts=[f"prompt_{req_id}"],
|
||||
prompt=f"prompt_{req_id}",
|
||||
sampling_params=sampling_params
|
||||
or OmniDiffusionSamplingParams(
|
||||
num_inference_steps=num_inference_steps,
|
||||
@@ -128,6 +128,12 @@ class _StubScheduler(SchedulerInterface):
|
||||
def has_requests(self) -> bool:
|
||||
return not self._scheduled
|
||||
|
||||
def num_waiting_requests(self) -> int:
|
||||
return 0 if self._scheduled else 1
|
||||
|
||||
def num_running_requests(self) -> int:
|
||||
return 1 if self._scheduled else 0
|
||||
|
||||
def get_request_state(self, request_id: str):
|
||||
del request_id
|
||||
return self._state
|
||||
@@ -164,7 +170,7 @@ class TestGetSamplingParamsKey:
|
||||
)
|
||||
sp.lora_scale = lora_scale
|
||||
return OmniDiffusionRequest(
|
||||
prompts=["prompt"],
|
||||
prompt="prompt",
|
||||
sampling_params=sp,
|
||||
request_id=f"req-{lora_int_id}-{lora_scale}",
|
||||
)
|
||||
@@ -196,6 +202,41 @@ class TestGetSamplingParamsKey:
|
||||
assert a == b
|
||||
|
||||
|
||||
class TestGetRequestBatchSamplingParamsKey:
|
||||
"""Pure-function tests for the request-batch compatibility key builder."""
|
||||
|
||||
@staticmethod
|
||||
def _make(
|
||||
*,
|
||||
num_inference_steps: int = 2,
|
||||
seed: int | None = 123,
|
||||
generator: torch.Generator | None = None,
|
||||
) -> OmniDiffusionRequest:
|
||||
sp = OmniDiffusionSamplingParams(
|
||||
num_inference_steps=num_inference_steps,
|
||||
seed=seed,
|
||||
generator=generator,
|
||||
)
|
||||
return OmniDiffusionRequest(prompt="prompt", sampling_params=sp, request_id=f"req-{num_inference_steps}")
|
||||
|
||||
def test_distinguishes_num_inference_steps(self) -> None:
|
||||
from vllm_omni.diffusion.sched.base_scheduler import get_request_batch_sampling_params_key
|
||||
|
||||
assert get_request_batch_sampling_params_key(
|
||||
self._make(num_inference_steps=2)
|
||||
) != get_request_batch_sampling_params_key(self._make(num_inference_steps=4))
|
||||
|
||||
def test_ignores_seed_and_generator(self) -> None:
|
||||
from vllm_omni.diffusion.sched.base_scheduler import get_request_batch_sampling_params_key
|
||||
|
||||
gen_a = torch.Generator(device="cpu").manual_seed(1)
|
||||
gen_b = torch.Generator(device="cpu").manual_seed(2)
|
||||
|
||||
assert get_request_batch_sampling_params_key(
|
||||
self._make(seed=1, generator=gen_a)
|
||||
) == get_request_batch_sampling_params_key(self._make(seed=2, generator=gen_b))
|
||||
|
||||
|
||||
class TestRequestScheduler:
|
||||
def setup_method(self) -> None:
|
||||
self.scheduler: RequestScheduler = RequestScheduler()
|
||||
@@ -297,8 +338,18 @@ class TestRequestScheduler:
|
||||
scheduler = RequestScheduler()
|
||||
scheduler.initialize(SimpleNamespace(max_num_seqs=2))
|
||||
|
||||
req_id_a = scheduler.add_request(_make_request("a"))
|
||||
req_id_b = scheduler.add_request(_make_request("b"))
|
||||
req_id_a = scheduler.add_request(
|
||||
_make_step_request(
|
||||
"a",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1, seed=123),
|
||||
)
|
||||
)
|
||||
req_id_b = scheduler.add_request(
|
||||
_make_step_request(
|
||||
"b",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1, seed=123),
|
||||
)
|
||||
)
|
||||
|
||||
sched_output = scheduler.schedule()
|
||||
|
||||
@@ -306,6 +357,50 @@ class TestRequestScheduler:
|
||||
assert sched_output.num_running_reqs == 2
|
||||
assert sched_output.num_waiting_reqs == 0
|
||||
|
||||
def test_batches_incompatible_request_sampling_params_separately(self) -> None:
|
||||
scheduler = RequestScheduler()
|
||||
scheduler.initialize(SimpleNamespace(max_num_seqs=2))
|
||||
|
||||
req_id_a = scheduler.add_request(
|
||||
_make_step_request(
|
||||
"a", num_inference_steps=2, sampling_params=OmniDiffusionSamplingParams(num_inference_steps=2, seed=123)
|
||||
)
|
||||
)
|
||||
scheduler.add_request(
|
||||
_make_step_request(
|
||||
"b", num_inference_steps=4, sampling_params=OmniDiffusionSamplingParams(num_inference_steps=4, seed=123)
|
||||
)
|
||||
)
|
||||
|
||||
first = scheduler.schedule()
|
||||
|
||||
assert _new_ids(first) == [req_id_a]
|
||||
assert first.num_running_reqs == 1
|
||||
assert first.num_waiting_reqs == 1
|
||||
|
||||
def test_batches_different_request_local_seed_together(self) -> None:
|
||||
scheduler = RequestScheduler()
|
||||
scheduler.initialize(SimpleNamespace(max_num_seqs=2))
|
||||
|
||||
req_id_a = scheduler.add_request(
|
||||
_make_step_request(
|
||||
"a",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=2, seed=123),
|
||||
)
|
||||
)
|
||||
req_id_b = scheduler.add_request(
|
||||
_make_step_request(
|
||||
"b",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=2, seed=456),
|
||||
)
|
||||
)
|
||||
|
||||
first = scheduler.schedule()
|
||||
|
||||
assert _new_ids(first) == [req_id_a, req_id_b]
|
||||
assert first.num_running_reqs == 2
|
||||
assert first.num_waiting_reqs == 0
|
||||
|
||||
def test_incompatible_waiting_head_blocks_later_compatible_request(self) -> None:
|
||||
scheduler = RequestScheduler()
|
||||
scheduler.initialize(SimpleNamespace(max_num_seqs=3))
|
||||
@@ -313,7 +408,7 @@ class TestRequestScheduler:
|
||||
req_id_a = scheduler.add_request(_make_request("a"))
|
||||
req_id_b = scheduler.add_request(
|
||||
OmniDiffusionRequest(
|
||||
prompts=["prompt_b"],
|
||||
prompt="prompt_b",
|
||||
sampling_params=OmniDiffusionSamplingParams(width=768),
|
||||
request_id="b",
|
||||
)
|
||||
@@ -374,7 +469,7 @@ class TestRequestScheduler:
|
||||
|
||||
def test_request_id_is_scheduler_key(self) -> None:
|
||||
request = OmniDiffusionRequest(
|
||||
prompts=["prompt_map_a", "prompt_map_b"],
|
||||
prompt="prompt_map_a",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="map-parent",
|
||||
)
|
||||
@@ -618,124 +713,6 @@ class TestDiffusionEngine:
|
||||
with pytest.raises(RuntimeError, match="Dummy run failed: boom"):
|
||||
engine._dummy_run()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_step_multi_request_reuses_multimodal_slice_logic(self, mocker: MockerFixture) -> None:
|
||||
engine = DiffusionEngine.__new__(DiffusionEngine)
|
||||
engine.od_config = SimpleNamespace(
|
||||
model_class_name="mock_model",
|
||||
enable_cpu_offload=False,
|
||||
)
|
||||
engine.pre_process_func = None
|
||||
engine.post_process_func = None
|
||||
engine._check_and_start_background_loop = mocker.AsyncMock()
|
||||
engine.async_add_req_and_wait_for_response = mocker.AsyncMock(
|
||||
return_value=DiffusionOutput(
|
||||
output={
|
||||
"video": ["frame-0", "frame-1"],
|
||||
"audio": ["audio-0", "audio-1"],
|
||||
"actions": torch.tensor([[1.0, 2.0], [3.0, 4.0]]),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
request = OmniDiffusionRequest(
|
||||
prompts=["prompt-0", "prompt-1"],
|
||||
sampling_params=OmniDiffusionSamplingParams(
|
||||
num_inference_steps=1,
|
||||
num_outputs_per_prompt=1,
|
||||
),
|
||||
request_id="req-batch",
|
||||
)
|
||||
|
||||
mocker.patch("vllm_omni.diffusion.output_formatter.supports_audio_output", return_value=False)
|
||||
outputs = await engine.step(request)
|
||||
|
||||
assert len(outputs) == 2
|
||||
assert outputs[0].images == ["frame-0"]
|
||||
assert outputs[1].images == ["frame-1"]
|
||||
assert outputs[0].multimodal_output["audio"] == "audio-0"
|
||||
assert outputs[1].multimodal_output["audio"] == "audio-1"
|
||||
torch.testing.assert_close(
|
||||
outputs[0].multimodal_output["actions"],
|
||||
torch.tensor([1.0, 2.0]),
|
||||
)
|
||||
torch.testing.assert_close(
|
||||
outputs[1].multimodal_output["actions"],
|
||||
torch.tensor([3.0, 4.0]),
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_step_empty_dict_output_still_runs_postprocess(self, mocker: MockerFixture) -> None:
|
||||
engine = DiffusionEngine.__new__(DiffusionEngine)
|
||||
engine.od_config = SimpleNamespace(
|
||||
model_class_name="mock_model",
|
||||
enable_cpu_offload=False,
|
||||
)
|
||||
engine.pre_process_func = None
|
||||
engine.post_process_func = mocker.Mock(return_value={"video": ["processed"]})
|
||||
engine._post_process_accepts_sampling_params = False
|
||||
engine._check_and_start_background_loop = mocker.AsyncMock()
|
||||
engine.async_add_req_and_wait_for_response = mocker.AsyncMock(
|
||||
return_value=DiffusionOutput(
|
||||
output={},
|
||||
custom_output={"actions": torch.tensor([[1.0, 2.0]])},
|
||||
)
|
||||
)
|
||||
|
||||
request = OmniDiffusionRequest(
|
||||
prompts=["prompt"],
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="req-action",
|
||||
)
|
||||
|
||||
mocker.patch("vllm_omni.diffusion.diffusion_engine.supports_audio_output", return_value=False)
|
||||
outputs = await engine.step(request)
|
||||
|
||||
engine.post_process_func.assert_called_once_with({})
|
||||
assert outputs[0].images == ["processed"]
|
||||
torch.testing.assert_close(outputs[0].multimodal_output["actions"], torch.tensor([[1.0, 2.0]]))
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_step_action_only_flag_skips_postprocess(self, mocker: MockerFixture) -> None:
|
||||
engine = DiffusionEngine.__new__(DiffusionEngine)
|
||||
engine.od_config = SimpleNamespace(
|
||||
model_class_name="mock_model",
|
||||
enable_cpu_offload=False,
|
||||
)
|
||||
engine.pre_process_func = None
|
||||
engine.post_process_func = mocker.Mock(side_effect=AssertionError("postprocess should be skipped"))
|
||||
engine.action_post_process_func = mocker.Mock(return_value=torch.tensor([[3.0, 4.0]]))
|
||||
engine._post_process_accepts_sampling_params = False
|
||||
engine._action_post_process_accepts_custom_output = True
|
||||
engine._action_post_process_accepts_sampling_params = False
|
||||
engine._check_and_start_background_loop = mocker.AsyncMock()
|
||||
raw_action = torch.tensor([[1.0, 2.0]])
|
||||
engine.async_add_req_and_wait_for_response = mocker.AsyncMock(
|
||||
return_value=DiffusionOutput(
|
||||
output={},
|
||||
custom_output={
|
||||
"action": raw_action,
|
||||
"action_only_output": True,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
request = OmniDiffusionRequest(
|
||||
prompts=["prompt"],
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id="req-action",
|
||||
)
|
||||
|
||||
mocker.patch("vllm_omni.diffusion.diffusion_engine.supports_audio_output", return_value=False)
|
||||
outputs = await engine.step(request)
|
||||
|
||||
engine.post_process_func.assert_not_called()
|
||||
engine.action_post_process_func.assert_called_once()
|
||||
assert engine.action_post_process_func.call_args.args[0] is raw_action
|
||||
assert "custom_output" in engine.action_post_process_func.call_args.kwargs
|
||||
assert outputs[0].images == []
|
||||
torch.testing.assert_close(outputs[0].multimodal_output["actions"], torch.tensor([[3.0, 4.0]]))
|
||||
|
||||
|
||||
class TestStepScheduler:
|
||||
def setup_method(self) -> None:
|
||||
|
||||
@@ -114,6 +114,23 @@ class _InterruptingStepPipeline(_StepPipeline):
|
||||
raise AssertionError("post_decode should not run after interrupt")
|
||||
|
||||
|
||||
class _FakePeakMemoryPlatform:
|
||||
def __init__(self, reserved_mb: list[float]):
|
||||
self._reserved_mb = reserved_mb
|
||||
self.reset_calls = 0
|
||||
|
||||
def reset_peak_memory_stats(self):
|
||||
self.reset_calls += 1
|
||||
|
||||
def max_memory_reserved(self):
|
||||
index = min(self.reset_calls - 1, len(self._reserved_mb) - 1)
|
||||
return int(self._reserved_mb[index] * 1024**2)
|
||||
|
||||
def max_memory_allocated(self):
|
||||
index = min(self.reset_calls - 1, len(self._reserved_mb) - 1)
|
||||
return int((self._reserved_mb[index] - 100) * 1024**2)
|
||||
|
||||
|
||||
class _IdentityNoiseTransformer(torch.nn.Module):
|
||||
def forward(self, x: torch.Tensor, **kwargs):
|
||||
del kwargs
|
||||
@@ -205,15 +222,10 @@ class _DistributedStepPipeline(CFGParallelMixin):
|
||||
|
||||
|
||||
def _make_step_request(num_inference_steps: int = 2):
|
||||
return SimpleNamespace(
|
||||
prompts=["a prompt"],
|
||||
return OmniDiffusionRequest(
|
||||
prompt="a prompt",
|
||||
request_id="req-1",
|
||||
sampling_params=SimpleNamespace(
|
||||
generator=None,
|
||||
seed=None,
|
||||
generator_device=None,
|
||||
num_inference_steps=num_inference_steps,
|
||||
),
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=num_inference_steps),
|
||||
)
|
||||
|
||||
|
||||
@@ -226,7 +238,7 @@ def _assert_aborted_output(output: DiffusionOutput, request_id: str) -> None:
|
||||
|
||||
def _make_engine_request(req_id: str = "req-1", num_inference_steps: int = 2) -> OmniDiffusionRequest:
|
||||
return OmniDiffusionRequest(
|
||||
prompts=[f"prompt-{req_id}"],
|
||||
prompt=f"prompt-{req_id}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=num_inference_steps),
|
||||
request_id=req_id,
|
||||
)
|
||||
@@ -282,6 +294,7 @@ def _make_distributed_runner(mode: str, device: torch.device):
|
||||
|
||||
|
||||
def _make_scheduler_output(req, request_id="req-1", step_id=0, finished_req_ids=None):
|
||||
req.request_id = request_id
|
||||
return DiffusionSchedulerOutput(
|
||||
step_id=step_id,
|
||||
scheduled_new_reqs=[NewRequestData(request_id=request_id, req=req)],
|
||||
@@ -309,7 +322,7 @@ def _make_input_batch_state(request_id: str, latent_value: float) -> DiffusionRe
|
||||
state = DiffusionRequestState(
|
||||
request_id=request_id,
|
||||
sampling=SimpleNamespace(),
|
||||
prompts=None,
|
||||
prompt=None,
|
||||
)
|
||||
state.latents = torch.tensor([[latent_value]])
|
||||
state.timesteps = torch.tensor([1.0])
|
||||
@@ -456,6 +469,24 @@ class TestRunner:
|
||||
assert runner.pipeline.scheduler_calls == 2
|
||||
assert runner.pipeline.decode_calls == 1
|
||||
|
||||
def test_carries_peak_memory_across_stepwise_request_lifecycle(self, monkeypatch):
|
||||
runner = _make_runner()
|
||||
req = _make_step_request()
|
||||
fake_platform = _FakePeakMemoryPlatform([1500.0, 1200.0])
|
||||
monkeypatch.setattr(model_runner_module, "set_forward_context", _noop_forward_context)
|
||||
monkeypatch.setattr(model_runner_module, "current_omni_platform", fake_platform)
|
||||
|
||||
first = DiffusionModelRunner.execute_stepwise(runner, _make_scheduler_output(req, step_id=0))
|
||||
first_output = first.get_request_output("req-1")
|
||||
assert first_output.finished is False
|
||||
assert first_output.result is None
|
||||
|
||||
second = DiffusionModelRunner.execute_stepwise(runner, _make_cached_scheduler_output(step_id=1))
|
||||
second_output = second.get_request_output("req-1")
|
||||
assert second_output.finished is True
|
||||
assert second_output.result is not None
|
||||
assert second_output.result.peak_memory_mb == pytest.approx(1500.0)
|
||||
|
||||
def test_rejects_multi_request_step_batch(self):
|
||||
runner = _make_runner()
|
||||
req_1 = _make_step_request()
|
||||
|
||||
@@ -18,10 +18,16 @@ from vllm_omni.diffusion.data import DiffusionOutput
|
||||
from vllm_omni.diffusion.diffusion_engine import DiffusionEngine
|
||||
from vllm_omni.diffusion.executor.multiproc_executor import MultiprocDiffusionExecutor
|
||||
from vllm_omni.diffusion.ipc import DIFFUSION_RPC_RESULT_ENVELOPE
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
from vllm_omni.diffusion.sched import RequestScheduler
|
||||
from vllm_omni.diffusion.sched.interface import (
|
||||
CachedRequestData,
|
||||
DiffusionSchedulerOutput,
|
||||
NewRequestData,
|
||||
)
|
||||
from vllm_omni.diffusion.stage_diffusion_proc import StageDiffusionProc
|
||||
from vllm_omni.diffusion.worker.diffusion_worker import WorkerProc
|
||||
from vllm_omni.diffusion.worker.utils import RunnerOutput
|
||||
from vllm_omni.diffusion.worker.utils import BatchRunnerOutput, RunnerOutput
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
from vllm_omni.outputs import OmniRequestOutput
|
||||
|
||||
@@ -40,7 +46,7 @@ def _mock_request(tag: str):
|
||||
"""Return a lightweight request object identifiable by *tag*."""
|
||||
return SimpleNamespace(
|
||||
request_id=tag,
|
||||
prompts=[f"prompt_{tag}"],
|
||||
prompt=f"prompt_{tag}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
)
|
||||
|
||||
@@ -101,13 +107,24 @@ def _start_worker(req_q, res_q, count=2):
|
||||
req = req_q.get(timeout=10)
|
||||
method = req.get("method", "")
|
||||
args = req.get("args", ())
|
||||
if method in {"generate", "execute_model"} and args and hasattr(args[0], "request_id"):
|
||||
if method == "execute_model_batch" and args and isinstance(args[0], DiffusionSchedulerOutput):
|
||||
sched_output = args[0]
|
||||
runner_outputs = []
|
||||
for nr in sched_output.scheduled_new_reqs:
|
||||
tag = f"result_for_{nr.request_id}"
|
||||
runner_outputs.append(
|
||||
RunnerOutput(request_id=nr.request_id, finished=True, result=_tagged_output(tag))
|
||||
)
|
||||
res_q.put(BatchRunnerOutput.from_list(runner_outputs))
|
||||
elif method in {"generate", "execute_model"} and args and hasattr(args[0], "request_id"):
|
||||
tag = f"result_for_{args[0].request_id}"
|
||||
res_q.put(_tagged_output(tag))
|
||||
elif args:
|
||||
tag = f"result_for_{args[0]}"
|
||||
res_q.put(_tagged_output(tag))
|
||||
else:
|
||||
tag = f"result_for_{method}"
|
||||
res_q.put(_tagged_output(tag))
|
||||
res_q.put(_tagged_output(tag))
|
||||
|
||||
t = threading.Thread(target=_run, daemon=True)
|
||||
t.start()
|
||||
@@ -172,6 +189,64 @@ class TestConcurrentRequestExecution:
|
||||
assert results["B"].error == "result_for_B"
|
||||
|
||||
|
||||
# ───────────────── request-mode dispatch (per-request vs batch) ─────────────
|
||||
|
||||
|
||||
def _make_sched_output(*request_ids: str) -> DiffusionSchedulerOutput:
|
||||
"""Build a request-mode scheduler output with the given new requests."""
|
||||
new_reqs = [
|
||||
NewRequestData(
|
||||
request_id=rid,
|
||||
req=OmniDiffusionRequest(
|
||||
prompt=f"prompt_{rid}",
|
||||
sampling_params=OmniDiffusionSamplingParams(num_inference_steps=1),
|
||||
request_id=rid,
|
||||
),
|
||||
)
|
||||
for rid in request_ids
|
||||
]
|
||||
return DiffusionSchedulerOutput(
|
||||
step_id=0,
|
||||
scheduled_new_reqs=new_reqs,
|
||||
scheduled_cached_reqs=CachedRequestData.make_empty(),
|
||||
finished_req_ids=set(),
|
||||
num_running_reqs=len(new_reqs),
|
||||
num_waiting_reqs=0,
|
||||
)
|
||||
|
||||
|
||||
class TestRequestModeDispatch:
|
||||
"""Request-batch-capable dispatch uses ``execute_batch`` for request-mode cycles."""
|
||||
|
||||
@pytest.mark.parametrize("request_ids", [("solo",), ("A", "B", "C")])
|
||||
def test_request_batch_capable_pipeline_uses_execute_batch(self, request_ids):
|
||||
engine, executor, _, _ = _make_engine()
|
||||
executor.execute_request = Mock(return_value="per-request")
|
||||
executor.execute_batch = Mock(return_value="batch")
|
||||
engine.execute_fn = executor.execute_batch
|
||||
|
||||
out = engine.execute_fn(_make_sched_output(*request_ids))
|
||||
|
||||
executor.execute_batch.assert_called_once()
|
||||
assert out == "batch"
|
||||
executor.execute_request.assert_not_called()
|
||||
|
||||
@pytest.mark.parametrize("request_ids", [("solo",), ("A", "B")])
|
||||
def test_batch_path_routes_results_through_worker(self, request_ids):
|
||||
"""End-to-end: a request-batch cycle goes out as one ``execute_model_batch``
|
||||
RPC and comes back as a per-request-routed ``BatchRunnerOutput``."""
|
||||
engine, executor, req_q, res_q = _make_engine()
|
||||
engine.execute_fn = executor.execute_batch
|
||||
wt = _start_worker(req_q, res_q, count=1)
|
||||
|
||||
out = engine.execute_fn(_make_sched_output(*request_ids))
|
||||
wt.join(5)
|
||||
|
||||
assert isinstance(out, BatchRunnerOutput)
|
||||
results = {ro.request_id: ro.result.error for ro in out.runner_outputs}
|
||||
assert results == {request_id: f"result_for_{request_id}" for request_id in request_ids}
|
||||
|
||||
|
||||
# ───────────────── concurrent collective RPC ─────────────────
|
||||
|
||||
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
|
||||
import asyncio
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import asdict, dataclass
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -16,68 +14,6 @@ from vllm_omni.outputs import OmniRequestOutput
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.diffusion, pytest.mark.cpu]
|
||||
|
||||
|
||||
def test_process_batch_request_preserves_parent_request_id_and_kv_sender_info():
|
||||
async def run_test():
|
||||
captured = {}
|
||||
|
||||
async def step(request):
|
||||
captured["request"] = request
|
||||
return [
|
||||
SimpleNamespace(
|
||||
images=["img-1"],
|
||||
_multimodal_output={},
|
||||
_custom_output={},
|
||||
metrics={},
|
||||
stage_durations={},
|
||||
peak_memory_mb=0.0,
|
||||
latents=None,
|
||||
trajectory_latents=None,
|
||||
trajectory_timesteps=None,
|
||||
trajectory_log_probs=None,
|
||||
trajectory_decoded=None,
|
||||
final_output_type="image",
|
||||
),
|
||||
SimpleNamespace(
|
||||
images=["img-2"],
|
||||
_multimodal_output={},
|
||||
_custom_output={},
|
||||
metrics={},
|
||||
stage_durations={},
|
||||
peak_memory_mb=0.0,
|
||||
latents=None,
|
||||
trajectory_latents=None,
|
||||
trajectory_timesteps=None,
|
||||
trajectory_log_probs=None,
|
||||
trajectory_decoded=None,
|
||||
final_output_type="image",
|
||||
),
|
||||
]
|
||||
|
||||
proc = object.__new__(StageDiffusionProc)
|
||||
proc._engine = SimpleNamespace(step=step)
|
||||
proc._od_config = SimpleNamespace(streaming_output=False)
|
||||
proc._executor = ThreadPoolExecutor(max_workers=1)
|
||||
|
||||
try:
|
||||
result = await proc._process_batch_request(
|
||||
request_id="req-parent",
|
||||
prompts=["hello", "world"],
|
||||
sampling_params_dict=asdict(OmniDiffusionSamplingParams()),
|
||||
kv_sender_info={0: {"host": "10.0.0.2", "zmq_port": 50151}},
|
||||
)
|
||||
finally:
|
||||
proc._executor.shutdown(wait=True)
|
||||
|
||||
request = captured["request"]
|
||||
assert request.request_id == "req-parent"
|
||||
assert not hasattr(request, "request_ids")
|
||||
assert request.kv_sender_info == {0: {"host": "10.0.0.2", "zmq_port": 50151}}
|
||||
assert result.request_id == "req-parent"
|
||||
assert result.images == ["img-1", "img-2"]
|
||||
|
||||
asyncio.run(run_test())
|
||||
|
||||
|
||||
@dataclass
|
||||
class MockOmniRequestOutput:
|
||||
request_id: str = ""
|
||||
|
||||
Reference in new issue
Block a user