From 0e670c36d6f08eae207ecf9d4b83d7ca25c77d87 Mon Sep 17 00:00:00 2001 From: Ratish P <114130421+Ratish1@users.noreply.github.com> Date: Mon, 23 Feb 2026 09:34:06 +0530 Subject: [PATCH] fix(diffusion): enforce strict input_reference validation for T2V (#14825) Co-authored-by: Xiaoyu Zhang <35585791+BBuf@users.noreply.github.com> --- .../configs/sample/sampling_params.py | 7 ++++ .../runtime/entrypoints/openai/video_api.py | 7 ++-- .../test/server/test_server_common.py | 32 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/python/sglang/multimodal_gen/configs/sample/sampling_params.py b/python/sglang/multimodal_gen/configs/sample/sampling_params.py index 1e4c9a77e..36b19ac0a 100644 --- a/python/sglang/multimodal_gen/configs/sample/sampling_params.py +++ b/python/sglang/multimodal_gen/configs/sample/sampling_params.py @@ -330,6 +330,13 @@ class SamplingParams: f"Served model with task type '{pipeline_config.task_type.name}' requires an 'image_path' input, but none was provided" ) + if not pipeline_config.task_type.accepts_image_input(): + # does not support image input + if self.image_path is not None: + raise ValueError( + f"input_reference is not supported for {pipeline_config.task_type.name} models." + ) + def _adjust( self, server_args, diff --git a/python/sglang/multimodal_gen/runtime/entrypoints/openai/video_api.py b/python/sglang/multimodal_gen/runtime/entrypoints/openai/video_api.py index d0d55c2af..d98f0a5e2 100644 --- a/python/sglang/multimodal_gen/runtime/entrypoints/openai/video_api.py +++ b/python/sglang/multimodal_gen/runtime/entrypoints/openai/video_api.py @@ -140,7 +140,6 @@ async def _dispatch_job_async(job_id: str, batch: Req) -> None: # TODO: support image to video generation -# TODO: this is currently not used @router.post("", response_model=VideoResponse) async def create_video( request: Request, @@ -261,7 +260,11 @@ async def create_video( logger.debug(f"Server received from create_video endpoint: req={req}") - sampling_params = _build_video_sampling_params(request_id, req) + try: + sampling_params = _build_video_sampling_params(request_id, req) + except (ValueError, TypeError) as e: + raise HTTPException(status_code=400, detail=str(e)) + job = _video_job_from_sampling(request_id, req, sampling_params) await VIDEO_STORE.upsert(request_id, job) diff --git a/python/sglang/multimodal_gen/test/server/test_server_common.py b/python/sglang/multimodal_gen/test/server/test_server_common.py index 2c31be681..6efeba304 100644 --- a/python/sglang/multimodal_gen/test/server/test_server_common.py +++ b/python/sglang/multimodal_gen/test/server/test_server_common.py @@ -711,6 +711,37 @@ Consider updating perf_baselines.json with the snippets below: logger.info("[Models API] All /v1/models tests passed for %s", case.id) + def _test_t2v_rejects_input_reference( + self, ctx: ServerContext, case: DiffusionTestCase + ) -> None: + if case.server_args.modality != "video": + return + + base_url = f"http://localhost:{ctx.port}" + resp = requests.get(f"{base_url}/v1/models") + assert resp.status_code == 200, f"/v1/models failed: {resp.text}" + data = resp.json().get("data", []) + if not data: + pytest.fail("/v1/models returned empty model list") + + task_type = data[0].get("task_type") + if task_type != "T2V": + return + + prompt = case.sampling_params.prompt or "test" + payload = {"prompt": prompt, "input_reference": "dummy"} + if case.sampling_params.output_size: + payload["size"] = case.sampling_params.output_size + + resp = requests.post(f"{base_url}/v1/videos", json=payload) + assert ( + resp.status_code == 400 + ), f"Expected 400 for T2V input_reference, got {resp.status_code}: {resp.text}" + detail = resp.json().get("detail", "") + assert ( + "input_reference is not supported" in detail + ), f"Unexpected error detail for T2V input_reference: {detail}" + def test_diffusion_perf( self, case: DiffusionTestCase, @@ -744,6 +775,7 @@ Consider updating perf_baselines.json with the snippets below: # Test /v1/models endpoint for router compatibility self._test_v1_models_endpoint(diffusion_server, case) + self._test_t2v_rejects_input_reference(diffusion_server, case) # LoRA API functionality test with E2E validation (only for LoRA-enabled cases) if case.server_args.lora_path or case.server_args.dynamic_lora_path: