[release v0.18.0.post1] Fix default sampling params for /v1/videos (#3021)
Signed-off-by: david6666666 <530634352@qq.com>
This commit is contained in:
1 parent
6d76e7d343
commit
2980618f70
3 files changed
+114
-15
No files matched your search
@@ -62,6 +62,7 @@ class MockVideoResult:
|
||||
class FakeAsyncOmni:
|
||||
def __init__(self):
|
||||
self.stage_configs = [SimpleNamespace(stage_type="diffusion")]
|
||||
self.default_sampling_params_list = [OmniDiffusionSamplingParams()]
|
||||
self.captured_prompt = None
|
||||
self.captured_sampling_params_list = None
|
||||
|
||||
@@ -457,6 +458,87 @@ def test_frame_interpolation_params_pass_to_diffusion_sampling_params(test_clien
|
||||
assert captured.frame_interpolation_model_path == "local-rife"
|
||||
|
||||
|
||||
def test_default_sampling_params_apply_to_video_requests(test_client, mocker: MockerFixture):
|
||||
mocker.patch(
|
||||
"vllm_omni.entrypoints.openai.serving_video._encode_video_bytes",
|
||||
return_value=b"fake-video",
|
||||
)
|
||||
engine = test_client.app.state.openai_serving_video._engine_client
|
||||
engine.default_sampling_params_list = [
|
||||
OmniDiffusionSamplingParams(
|
||||
num_inference_steps=4,
|
||||
guidance_scale=7.5,
|
||||
generator_device="cpu",
|
||||
enable_frame_interpolation=True,
|
||||
frame_interpolation_exp=2,
|
||||
frame_interpolation_scale=0.5,
|
||||
frame_interpolation_model_path="default-rife",
|
||||
)
|
||||
]
|
||||
|
||||
response = test_client.post(
|
||||
"/v1/videos",
|
||||
data={
|
||||
"prompt": "default param pass-through",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
video_id = response.json()["id"]
|
||||
_wait_for_status(test_client, video_id, VideoGenerationStatus.COMPLETED.value)
|
||||
|
||||
captured = engine.captured_sampling_params_list[0]
|
||||
assert captured.num_inference_steps == 4
|
||||
assert captured.guidance_scale == 7.5
|
||||
assert captured.generator_device == "cpu"
|
||||
assert captured.enable_frame_interpolation is True
|
||||
assert captured.frame_interpolation_exp == 2
|
||||
assert captured.frame_interpolation_scale == 0.5
|
||||
assert captured.frame_interpolation_model_path == "default-rife"
|
||||
|
||||
|
||||
def test_request_params_override_default_video_sampling_params(test_client, mocker: MockerFixture):
|
||||
mocker.patch(
|
||||
"vllm_omni.entrypoints.openai.serving_video._encode_video_bytes",
|
||||
return_value=b"fake-video",
|
||||
)
|
||||
engine = test_client.app.state.openai_serving_video._engine_client
|
||||
engine.default_sampling_params_list = [
|
||||
OmniDiffusionSamplingParams(
|
||||
num_inference_steps=4,
|
||||
guidance_scale=7.5,
|
||||
enable_frame_interpolation=True,
|
||||
frame_interpolation_exp=2,
|
||||
frame_interpolation_scale=0.5,
|
||||
frame_interpolation_model_path="default-rife",
|
||||
)
|
||||
]
|
||||
|
||||
response = test_client.post(
|
||||
"/v1/videos",
|
||||
data={
|
||||
"prompt": "explicit override",
|
||||
"num_inference_steps": "8",
|
||||
"enable_frame_interpolation": "false",
|
||||
"frame_interpolation_exp": "1",
|
||||
"frame_interpolation_scale": "1.0",
|
||||
"frame_interpolation_model_path": "custom-rife",
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
video_id = response.json()["id"]
|
||||
_wait_for_status(test_client, video_id, VideoGenerationStatus.COMPLETED.value)
|
||||
|
||||
captured = engine.captured_sampling_params_list[0]
|
||||
assert captured.num_inference_steps == 8
|
||||
assert captured.guidance_scale == 7.5
|
||||
assert captured.enable_frame_interpolation is False
|
||||
assert captured.frame_interpolation_exp == 1
|
||||
assert captured.frame_interpolation_scale == 1.0
|
||||
assert captured.frame_interpolation_model_path == "custom-rife"
|
||||
|
||||
|
||||
def test_worker_fps_multiplier_is_applied_to_async_encoding(test_client, mocker: MockerFixture):
|
||||
fps_values = []
|
||||
engine = test_client.app.state.openai_serving_video._engine_client
|
||||
|
||||
@@ -2033,9 +2033,9 @@ async def create_video(
|
||||
true_cfg_scale: float | None = Form(default=None),
|
||||
seed: int | None = Form(default=None),
|
||||
negative_prompt: str | None = Form(default=None),
|
||||
enable_frame_interpolation: bool = Form(default=False),
|
||||
frame_interpolation_exp: int = Form(default=1, ge=1),
|
||||
frame_interpolation_scale: float = Form(default=1.0, gt=0.0),
|
||||
enable_frame_interpolation: bool | None = Form(default=None),
|
||||
frame_interpolation_exp: int | None = Form(default=None, ge=1),
|
||||
frame_interpolation_scale: float | None = Form(default=None, gt=0.0),
|
||||
frame_interpolation_model_path: str | None = Form(default=None),
|
||||
lora: str | None = Form(default=None),
|
||||
extra_params: str | None = Form(default=None),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from http import HTTPStatus
|
||||
@@ -96,7 +97,7 @@ class OmniOpenAIServingVideo:
|
||||
if request.negative_prompt is not None:
|
||||
prompt["negative_prompt"] = request.negative_prompt
|
||||
|
||||
gen_params = OmniDiffusionSamplingParams()
|
||||
gen_params = self._resolve_default_sampling_params()
|
||||
|
||||
input_image = None if reference_image is None else reference_image.data
|
||||
vp = request.resolve_video_params()
|
||||
@@ -114,22 +115,27 @@ class OmniOpenAIServingVideo:
|
||||
if vp.fps is not None:
|
||||
gen_params.fps = vp.fps
|
||||
gen_params.frame_rate = float(vp.fps)
|
||||
gen_params.enable_frame_interpolation = request.enable_frame_interpolation
|
||||
gen_params.frame_interpolation_exp = request.frame_interpolation_exp
|
||||
gen_params.frame_interpolation_scale = request.frame_interpolation_scale
|
||||
gen_params.frame_interpolation_model_path = request.frame_interpolation_model_path
|
||||
provided_fields = request.model_fields_set
|
||||
if "enable_frame_interpolation" in provided_fields:
|
||||
gen_params.enable_frame_interpolation = request.enable_frame_interpolation
|
||||
if "frame_interpolation_exp" in provided_fields:
|
||||
gen_params.frame_interpolation_exp = request.frame_interpolation_exp
|
||||
if "frame_interpolation_scale" in provided_fields:
|
||||
gen_params.frame_interpolation_scale = request.frame_interpolation_scale
|
||||
if "frame_interpolation_model_path" in provided_fields:
|
||||
gen_params.frame_interpolation_model_path = request.frame_interpolation_model_path
|
||||
|
||||
if request.num_inference_steps is not None:
|
||||
if "num_inference_steps" in provided_fields and request.num_inference_steps is not None:
|
||||
gen_params.num_inference_steps = request.num_inference_steps
|
||||
if request.guidance_scale is not None:
|
||||
if "guidance_scale" in provided_fields and request.guidance_scale is not None:
|
||||
gen_params.guidance_scale = request.guidance_scale
|
||||
if request.guidance_scale_2 is not None:
|
||||
if "guidance_scale_2" in provided_fields and request.guidance_scale_2 is not None:
|
||||
gen_params.guidance_scale_2 = request.guidance_scale_2
|
||||
if request.true_cfg_scale is not None:
|
||||
if "true_cfg_scale" in provided_fields and request.true_cfg_scale is not None:
|
||||
gen_params.true_cfg_scale = request.true_cfg_scale
|
||||
if request.seed is not None:
|
||||
if "seed" in provided_fields and request.seed is not None:
|
||||
gen_params.seed = request.seed
|
||||
if request.boundary_ratio is not None:
|
||||
if "boundary_ratio" in provided_fields and request.boundary_ratio is not None:
|
||||
gen_params.boundary_ratio = request.boundary_ratio
|
||||
|
||||
logger.info(
|
||||
@@ -137,7 +143,7 @@ class OmniOpenAIServingVideo:
|
||||
request.boundary_ratio,
|
||||
gen_params.boundary_ratio,
|
||||
)
|
||||
if request.flow_shift is not None:
|
||||
if "flow_shift" in provided_fields and request.flow_shift is not None:
|
||||
gen_params.extra_args["flow_shift"] = request.flow_shift
|
||||
|
||||
if request.extra_params is not None:
|
||||
@@ -241,6 +247,17 @@ class OmniOpenAIServingVideo:
|
||||
video_codec_options = {str(k): str(v) for k, v in extra_codec_options.items()}
|
||||
return video_codec_options
|
||||
|
||||
def _resolve_default_sampling_params(self) -> OmniDiffusionSamplingParams:
|
||||
default_sampling_params_list = getattr(self._engine_client, "default_sampling_params_list", None)
|
||||
if default_sampling_params_list:
|
||||
for params in default_sampling_params_list:
|
||||
if isinstance(params, OmniDiffusionSamplingParams):
|
||||
# Requests mutate sampling params in-place, including
|
||||
# nested dict fields like extra_args. Deep-copy the stage
|
||||
# defaults so one request cannot leak state into another.
|
||||
return copy.deepcopy(params)
|
||||
return OmniDiffusionSamplingParams()
|
||||
|
||||
@staticmethod
|
||||
def _resolve_video_fps_multiplier(result: Any) -> int:
|
||||
custom_output = getattr(result, "custom_output", None)
|
||||
|
||||
Reference in new issue
Block a user