Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion models/tt_dit/pipelines/pipeline_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +25,7 @@ def __call__(
seed: int,
traced: bool,
on_event: PipelineEventCallback | None,
**kwargs: Any,
) -> _R_co:
...

Expand All @@ -34,16 +35,27 @@ 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,
num_inference_steps=num_inference_steps,
seed=seed,
traced=True,
on_event=on_event,
**kwargs,
)
47 changes: 47 additions & 0 deletions models/tt_dit/tests/unit/test_pipeline_api.py
Original file line number Diff line number Diff line change
@@ -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