[Model] Add HiDream-O1-Image support (#5194)
Signed-off-by: yixiaoer <shin@yixiaoer.sg>
This commit is contained in:
16 files changed
+1621
-6
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
@@ -0,0 +1,67 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from cache_dit import ForwardPattern
|
||||
from torch import nn
|
||||
|
||||
from vllm_omni.diffusion.cache.cachedit import CacheDiTAdapterConfig, CacheDiTBackend
|
||||
from vllm_omni.diffusion.models.hidream_o1_image.hidream_o1_image_transformer import (
|
||||
HiDreamO1TextModel,
|
||||
)
|
||||
from vllm_omni.diffusion.models.hidream_o1_image.pipeline_hidream_o1_image import (
|
||||
HiDreamO1ImagePipeline,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
|
||||
def _empty_text_model() -> HiDreamO1TextModel:
|
||||
model = HiDreamO1TextModel.__new__(HiDreamO1TextModel)
|
||||
nn.Module.__init__(model)
|
||||
model.layers = nn.ModuleList([nn.Identity()])
|
||||
return model
|
||||
|
||||
|
||||
def test_cache_dit_targets_the_decoder_module_that_owns_layers():
|
||||
text_model = _empty_text_model()
|
||||
pipeline = SimpleNamespace(
|
||||
_dit_modules=HiDreamO1ImagePipeline._dit_modules,
|
||||
model=SimpleNamespace(
|
||||
model=SimpleNamespace(language_model=text_model),
|
||||
),
|
||||
)
|
||||
|
||||
with (
|
||||
patch("vllm_omni.diffusion.cache.cachedit.backend.BlockAdapter") as block_adapter_cls,
|
||||
patch("vllm_omni.diffusion.cache.cachedit.backend.cache_dit") as cache_dit,
|
||||
):
|
||||
backend = CacheDiTBackend()
|
||||
backend.enable(pipeline)
|
||||
backend.refresh(pipeline, num_inference_steps=50)
|
||||
|
||||
adapter_config = HiDreamO1TextModel._cache_dit_adapter_config
|
||||
assert isinstance(adapter_config, CacheDiTAdapterConfig)
|
||||
assert adapter_config.block_forward_patterns == {"layers": ForwardPattern.Pattern_3}
|
||||
assert adapter_config.has_separate_cfg is True
|
||||
|
||||
block_adapter_cls.assert_called_once_with(
|
||||
transformer=text_model,
|
||||
blocks=[text_model.layers],
|
||||
forward_pattern=[ForwardPattern.Pattern_3],
|
||||
has_separate_cfg=True,
|
||||
check_forward_pattern=True,
|
||||
)
|
||||
cache_dit.enable_cache.assert_called_once()
|
||||
enable_call = cache_dit.enable_cache.call_args
|
||||
assert enable_call.args == (block_adapter_cls.return_value,)
|
||||
assert enable_call.kwargs["cache_config"].Fn_compute_blocks == 1
|
||||
assert enable_call.kwargs["calibrator_config"] is None
|
||||
cache_dit.refresh_context.assert_called_once_with(
|
||||
text_model,
|
||||
num_inference_steps=50,
|
||||
verbose=True,
|
||||
)
|
||||
@@ -0,0 +1,65 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from tests.e2e.accuracy.helpers import assert_similarity, model_output_dir
|
||||
from tests.helpers.mark import hardware_test
|
||||
from tests.helpers.runtime import OmniRunner
|
||||
from vllm_omni.diffusion.data import DiffusionParallelConfig
|
||||
from vllm_omni.diffusion.utils.image_output import extract_images_from_outputs
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
pytestmark = [pytest.mark.full_model, pytest.mark.diffusion]
|
||||
|
||||
MODEL_ID = "HiDream-ai/HiDream-O1-Image"
|
||||
PROMPT = "A cat is sitting next to a sign that says 'HiDream-O1 vLLM-Omni'"
|
||||
BASELINE_PATH = Path(__file__).resolve().parents[2] / "assets" / "hidream_o1" / "hidream_o1_baseline.png"
|
||||
SSIM_THRESHOLD = 0.8
|
||||
PSNR_THRESHOLD = 19.0
|
||||
|
||||
|
||||
@hardware_test(res={"cuda": "H100"}, num_cards=2)
|
||||
def test_hidream_o1_image_tp2_matches_baseline(
|
||||
accuracy_artifact_root: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setenv("DIFFUSION_ATTENTION_BACKEND", "TORCH_SDPA")
|
||||
model = os.environ.get("HIDREAM_O1_IMAGE_MODEL", MODEL_ID)
|
||||
with OmniRunner(
|
||||
model,
|
||||
parallel_config=DiffusionParallelConfig(tensor_parallel_size=2),
|
||||
enforce_eager=True,
|
||||
) as runner:
|
||||
outputs = runner.omni.generate(
|
||||
{"prompt": PROMPT},
|
||||
OmniDiffusionSamplingParams(
|
||||
height=2048,
|
||||
width=2048,
|
||||
num_inference_steps=50,
|
||||
guidance_scale=5.0,
|
||||
seed=42,
|
||||
),
|
||||
)
|
||||
images = extract_images_from_outputs(outputs)
|
||||
assert images
|
||||
image = images[0].convert("RGB")
|
||||
|
||||
output_dir = model_output_dir(accuracy_artifact_root, MODEL_ID)
|
||||
image.save(output_dir / "vllm_omni_tp2.png")
|
||||
assert BASELINE_PATH.exists()
|
||||
baseline = Image.open(BASELINE_PATH).convert("RGB")
|
||||
resized = image.resize(baseline.size, Image.Resampling.LANCZOS)
|
||||
assert_similarity(
|
||||
model_name=MODEL_ID,
|
||||
vllm_image=resized,
|
||||
diffusers_image=baseline,
|
||||
ssim_threshold=SSIM_THRESHOLD,
|
||||
psnr_threshold=PSNR_THRESHOLD,
|
||||
)
|
||||
@@ -74,6 +74,7 @@ EXCLUDED_MODELS = [
|
||||
"Cosmos3OmniPipeline",
|
||||
"DiffusersAdapterPipeline",
|
||||
"HiDreamImagePipeline",
|
||||
"HiDreamO1ImagePipeline",
|
||||
"DreamZeroPipeline",
|
||||
"StableDiffusionXLPipeline",
|
||||
"Gr00tN1d7Pipeline",
|
||||
|
||||
Reference in new issue
Block a user