fix(diffusion): convert caller sampling params instead of discarding … (#4115)
Signed-off-by: BruceLoveDecimal <39156883+BruceLoveDecimal@users.noreply.github.com> Co-authored-by: Gao Han <hgaoaf@connect.ust.hk>
This commit is contained in:
1 parent
b8e7b21188
commit
1c6e731339
3 files changed
+95
-6
No files matched your search
@@ -0,0 +1,65 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
"""Regression tests for diffusion sampling params coercion."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from vllm.sampling_params import SamplingParams
|
||||
|
||||
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
|
||||
def _sampling_params(*, seed: int | None = None, extra_args: dict[str, Any] | None = None) -> SamplingParams:
|
||||
return SamplingParams(max_tokens=1, seed=seed, extra_args=extra_args)
|
||||
|
||||
|
||||
def test_from_params_returns_existing_omni_params() -> None:
|
||||
params = OmniDiffusionSamplingParams(num_inference_steps=20)
|
||||
|
||||
converted = OmniDiffusionSamplingParams.from_params(params)
|
||||
|
||||
assert converted is params
|
||||
|
||||
|
||||
def test_from_params_converts_sampling_params_seed_and_known_extra_args() -> None:
|
||||
params = _sampling_params(
|
||||
seed=1234,
|
||||
extra_args={
|
||||
"num_inference_steps": 50,
|
||||
"height": 1024,
|
||||
"width": 768,
|
||||
"guidance_scale": 7.5,
|
||||
},
|
||||
)
|
||||
|
||||
converted = OmniDiffusionSamplingParams.from_params(params)
|
||||
|
||||
assert converted.seed == 1234
|
||||
assert converted.num_inference_steps == 50
|
||||
assert converted.height == 1024
|
||||
assert converted.width == 768
|
||||
assert converted.guidance_scale == 7.5
|
||||
assert converted.extra_args == {}
|
||||
|
||||
|
||||
def test_from_params_preserves_unknown_extra_args() -> None:
|
||||
params = _sampling_params(
|
||||
extra_args={
|
||||
"height": 512,
|
||||
"pipeline_specific": "kept",
|
||||
},
|
||||
)
|
||||
|
||||
converted = OmniDiffusionSamplingParams.from_params(params)
|
||||
|
||||
assert converted.height == 512
|
||||
assert converted.extra_args == {"pipeline_specific": "kept"}
|
||||
|
||||
|
||||
def test_from_params_rejects_unsupported_types() -> None:
|
||||
with pytest.raises(TypeError, match="Diffusion stage requires OmniDiffusionSamplingParams"):
|
||||
OmniDiffusionSamplingParams.from_params({"height": 512})
|
||||
Reference in new issue
Block a user