[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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user