diff --git a/models/tt_dit/pipelines/pipeline_api.py b/models/tt_dit/pipelines/pipeline_api.py index c56c63861750..0cf5580e4825 100644 --- a/models/tt_dit/pipelines/pipeline_api.py +++ b/models/tt_dit/pipelines/pipeline_api.py @@ -4,7 +4,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Protocol, TypeVar +from typing import TYPE_CHECKING, Any, Protocol, TypeVar if TYPE_CHECKING: from collections.abc import Sequence @@ -25,6 +25,7 @@ def __call__( seed: int, traced: bool, on_event: PipelineEventCallback | None, + **kwargs: Any, ) -> _R_co: ... @@ -34,11 +35,21 @@ def run_single_prompt( self: _Pipeline[_R_co], *, prompt: str, + prompt_2: str | None = None, negative_prompt: str | None = None, + negative_prompt_2: str | None = None, num_inference_steps: int, + guidance_scale: float | None = None, seed: int = 0, on_event: PipelineEventCallback | None = None, ) -> _R_co: + kwargs: dict[str, Any] = {} + if prompt_2 is not None: + kwargs["prompts_2"] = [prompt_2] + if negative_prompt_2 is not None: + kwargs["negative_prompts_2"] = [negative_prompt_2] + if guidance_scale is not None: + kwargs["guidance_scale"] = guidance_scale return self( prompts=[prompt], negative_prompts=[negative_prompt] if negative_prompt is not None else None, @@ -46,4 +57,5 @@ def run_single_prompt( seed=seed, traced=True, on_event=on_event, + **kwargs, ) diff --git a/models/tt_dit/tests/unit/test_pipeline_api.py b/models/tt_dit/tests/unit/test_pipeline_api.py new file mode 100644 index 000000000000..b0ea04f01db2 --- /dev/null +++ b/models/tt_dit/tests/unit/test_pipeline_api.py @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: © 2026 Tenstorrent USA, Inc. + +# SPDX-License-Identifier: Apache-2.0 + +"""Device-free coverage for PipelineAPIMixin.run_single_prompt: which keyword arguments reach the pipeline.""" + +from __future__ import annotations + +from ...pipelines.pipeline_api import PipelineAPIMixin + + +class _RecordingPipeline(PipelineAPIMixin): + def __call__(self, **kwargs): + self.kwargs = kwargs + return "image" + + +def test_defaults_pass_only_the_original_arguments(): + pipeline = _RecordingPipeline() + assert pipeline.run_single_prompt(prompt="a cat", num_inference_steps=4) == "image" + assert pipeline.kwargs == { + "prompts": ["a cat"], + "negative_prompts": None, + "num_inference_steps": 4, + "seed": 0, + "traced": True, + "on_event": None, + } + + +def test_guidance_and_second_prompts_are_forwarded_as_lists(): + pipeline = _RecordingPipeline() + pipeline.run_single_prompt( + prompt="a cat", + prompt_2="a tabby cat", + negative_prompt="blurry", + negative_prompt_2="noisy", + num_inference_steps=4, + guidance_scale=4.5, + seed=7, + ) + assert pipeline.kwargs["prompts"] == ["a cat"] + assert pipeline.kwargs["prompts_2"] == ["a tabby cat"] + assert pipeline.kwargs["negative_prompts"] == ["blurry"] + assert pipeline.kwargs["negative_prompts_2"] == ["noisy"] + assert pipeline.kwargs["guidance_scale"] == 4.5 + assert pipeline.kwargs["seed"] == 7