Skip to content
Open
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
8 changes: 4 additions & 4 deletions samples/cpp/image_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,17 @@ With adapter | Without adapter

## Run text to image with TaylorSeer caching optimization

The `taylorseer_text2image` sample demonstrates how to use TaylorSeer Lite caching to accelerate text to image generation. TaylorSeer is a caching optimization technique that uses Taylor series approximation to predict intermediate outputs during diffusion inference, reducing the number of computationally expensive transformer forward passes.
The `taylorseer_text2image` sample demonstrates how to use TaylorSeer Lite caching to accelerate text to image generation. TaylorSeer is a caching optimization technique that uses Taylor series approximation to predict intermediate outputs during diffusion inference, reducing the number of computationally expensive transformer forward passes. TaylorSeer caching is **enabled by default** for Flux and StableDiffusion3 Text2Image pipelines.

Run the sample with custom parameters:

```bash
./taylorseer_text2image ./flux.1-dev/FP16 "a beautiful sunset over mountains"
```

The sample generates two images with and without TaylorSeer config applied using the same prompt:
- `taylorseer.bmp` with TaylorSeer config applied
- `taylorseer_baseline.bmp` without TaylorSeer config applied
The sample generates two images using the same prompt:
- `taylorseer_baseline.bmp` without caching
- `taylorseer.bmp` with TaylorSeer caching applied

Check the difference:

Expand Down
7 changes: 6 additions & 1 deletion samples/cpp/image_generation/taylorseer_text2image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <chrono>
#include <iostream>
#include <optional>

int32_t main(int32_t argc, char* argv[]) try {
if (argc != 3) {
Expand All @@ -28,6 +29,10 @@ int32_t main(int32_t argc, char* argv[]) try {

ov::genai::Text2ImagePipeline pipe(models_path, device);
std::cout << "Generating baseline image without caching...\n";
auto generation_config = pipe.get_generation_config();
generation_config.taylorseer_config = std::nullopt; // explicitly disable caching
pipe.set_generation_config(generation_config);
Comment thread
l-bat marked this conversation as resolved.

auto start_time = std::chrono::high_resolution_clock::now();

ov::Tensor baseline_image = pipe.generate(prompt,
Expand All @@ -51,7 +56,7 @@ int32_t main(int32_t argc, char* argv[]) try {

ov::genai::TaylorSeerCacheConfig taylorseer_config{cache_interval, disable_before, disable_after};
std::cout << taylorseer_config.to_string() << "\n";
auto generation_config = pipe.get_generation_config();
generation_config = pipe.get_generation_config();
generation_config.taylorseer_config = taylorseer_config;
pipe.set_generation_config(generation_config);

Expand Down
8 changes: 4 additions & 4 deletions samples/python/image_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ With adapter | Without adapter

## Run text to image with TaylorSeer caching optimization

The `taylorseer_text2image.py` sample demonstrates how to use TaylorSeer Lite caching to accelerate text to image generation. TaylorSeer is a caching optimization technique that uses Taylor series approximation to predict intermediate outputs during diffusion inference, reducing the number of computationally expensive transformer forward passes.
The `taylorseer_text2image.py` sample demonstrates how to use TaylorSeer Lite caching to accelerate text to image generation. TaylorSeer is a caching optimization technique that uses Taylor series approximation to predict intermediate outputs during diffusion inference, reducing the number of computationally expensive transformer forward passes. TaylorSeer caching is **enabled by default** for Flux and StableDiffusion3 Text2Image pipelines.

Run the sample with custom parameters:

```bash
python taylorseer_text2image.py ./flux.1-dev/FP16 "a beautiful sunset over mountains"
```

The sample generates two images with and without TaylorSeer config applied using the same prompt:
- `taylorseer.bmp` with TaylorSeer config applied
- `taylorseer_baseline.bmp` without TaylorSeer config applied
The sample generates two images using the same prompt:
- `taylorseer_baseline.bmp` without caching
- `taylorseer.bmp` with TaylorSeer caching applied

Check the difference:

Expand Down
4 changes: 4 additions & 0 deletions samples/python/image_generation/taylorseer_text2image.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def callback(step, num_steps, latent):

# Generate baseline for comparison
print(f"\nGenerating baseline image without caching...")
baseline_config = pipe.get_generation_config()
baseline_config.taylorseer_config = None # explicitly disable caching
pipe.set_generation_config(baseline_config)

start_time = time.time()
baseline_tensor = pipe.generate(args.prompt, **generate_kwargs)
baseline_time = time.time() - start_time
Expand Down
16 changes: 14 additions & 2 deletions site/docs/concepts/optimization-techniques/diffusion-caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ taylorseer_config.disable_cache_after_step = -1
```

### Image Generation (Flux / StableDiffusion3)
TaylorSeer caching is **enabled by default** for Flux and StableDiffusion3 Text2Image pipelines.

Comment thread
l-bat marked this conversation as resolved.
```python
pipe = openvino_genai.Text2ImagePipeline(models_path, device)
# Apply TaylorSeerCacheConfig to generation config
# TaylorSeer is active out of the box
res = pipe.generate(prompt, num_inference_steps=28)
```

To customize caching parameters, use `set_generation_config()`:
```python
generation_config = pipe.get_generation_config()
generation_config.taylorseer_config = taylorseer_config
pipe.set_generation_config(generation_config)
```

res = pipe.generate(prompt, num_inference_steps=28)
To disable caching entirely:
```python
generation_config = pipe.get_generation_config()
generation_config.taylorseer_config = None # disable caching
pipe.set_generation_config(generation_config)
```

### Video Generation (LTX-Video)
Expand Down
1 change: 1 addition & 0 deletions src/cpp/src/image_generation/flux_pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ class FluxPipeline : public DiffusionPipeline {
m_generation_config.guidance_scale = 3.5f;
m_generation_config.num_inference_steps = 28;
m_generation_config.strength = 1.0f;
m_generation_config.taylorseer_config = TaylorSeerCacheConfig{};
Comment thread
l-bat marked this conversation as resolved.
} else if (m_pipeline_type == PipelineType::IMAGE_2_IMAGE || m_pipeline_type == PipelineType::INPAINTING) {
m_generation_config.guidance_scale = 7.0f;
m_generation_config.num_inference_steps = 28;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ class StableDiffusion3Pipeline : public DiffusionPipeline {
m_generation_config.num_inference_steps = 28;
m_generation_config.max_sequence_length = 256;
m_generation_config.strength = m_pipeline_type == PipelineType::TEXT_2_IMAGE ? 1.0f : 0.6f;
if (m_pipeline_type == PipelineType::TEXT_2_IMAGE) {
m_generation_config.taylorseer_config = TaylorSeerCacheConfig{};
}
} else {
OPENVINO_THROW("Unsupported class_name '", class_name, "'. Please, contact OpenVINO GenAI developers");
}
Expand Down
1 change: 1 addition & 0 deletions tests/python_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def pytest_configure(config: pytest.Config):
"tiny-random-latent-consistency": "echarlaix/tiny-random-latent-consistency",
"tiny-random-flux": "optimum-intel-internal-testing/tiny-random-flux",
"tiny-random-sdxl": "echarlaix/tiny-random-stable-diffusion-xl",
"tiny-random-sd3": "optimum-intel-internal-testing/stable-diffusion-3-tiny-random",
}

DEFAULT_IMAGE_GEN_MODEL_ID = "tiny-random-latent-consistency"
Expand Down
7 changes: 7 additions & 0 deletions tests/python_tests/test_image_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from utils.ov_genai_pipelines import should_skip_npuw_tests

FLUX_MODEL_ID = "tiny-random-flux"
SD3_MODEL_ID = "tiny-random-sd3"
SDXL_MODEL_ID = "tiny-random-sdxl"


Expand Down Expand Up @@ -191,6 +192,12 @@ def callback(step, num_steps, latent):
assert image is not None
assert len(callback_calls) > 0

@pytest.mark.parametrize("image_generation_model", [FLUX_MODEL_ID, SD3_MODEL_ID], indirect=True)
def test_taylorseer_default_on(self, image_generation_model):
"""Test that TaylorSeer is enabled by default for Flux and StableDiffusion3 Text2Image pipelines."""
pipe = ov_genai.Text2ImagePipeline(image_generation_model, "CPU")
assert pipe.get_generation_config().taylorseer_config is not None


class TestImageGenerationOnNpuByNpuwCpu:
def _construct_reshaped(self, model_dir):
Expand Down
2 changes: 1 addition & 1 deletion tools/llm_bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ python benchmark.py -m models/dreamlike_anime_1_0_ov/FP16 -p "cat wizard, gandal
- `--static_reshape`: Reshape image generation pipeline to specific width & height at pipeline creation time.
- `--guidance_scale`: guidance_scale parameter for pipeline, supported via json JSON input only.
- `--images`: Like a `--media`, path to the directory or single image.
- `--taylorseer_config`: TaylorSeer cache configuration, supported via JSON string or path to JSON file.
- `--taylorseer_config`: TaylorSeer cache configuration, supported via JSON string or path to JSON file. **Note:** TaylorSeer caching is enabled by default for Flux and StableDiffusion3 Text2Image pipelines. To disable it for a baseline benchmark, pass `--taylorseer_config '{"disable_cache_after_step": 0}'`.
Comment thread
l-bat marked this conversation as resolved.

> **Supported Image Generation model types:** stable-diffusion, ssd, tiny-sd, small-sd, lcm, sdxl, dreamlike, flux

Expand Down
72 changes: 40 additions & 32 deletions tools/who_what_benchmark/tests/test_cli_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,44 +121,52 @@ def test_image_model_genai(model_id, model_type, tmp_path):
assert GT_FILE.exists()
assert (tmp_path / "reference").exists()

output = run_wwb([
"--target-model",
MODEL_PATH,
"--num-samples",
"1",
"--gt-data",
GT_FILE,
"--device",
"CPU",
"--model-type",
model_type,
"--genai",
"--num-inference-steps",
"2",
])
output = run_wwb(
[
"--target-model",
MODEL_PATH,
"--num-samples",
"1",
"--gt-data",
GT_FILE,
"--device",
"CPU",
"--model-type",
model_type,
"--genai",
"--num-inference-steps",
"2",
"--taylorseer-config",
'{"disable_cache_after_step": 0}',
]
)
Comment thread
l-bat marked this conversation as resolved.

assert "Metrics for model" in output
similarity = get_similarity(output)
assert similarity >= 0.97751 # Ticket 166496
assert (tmp_path / "target").exists()

run_wwb([
"--target-model",
MODEL_PATH,
"--num-samples",
"1",
"--gt-data",
GT_FILE,
"--device",
"CPU",
"--model-type",
model_type,
"--output",
tmp_path,
"--genai",
"--num-inference-steps",
"2",
])
run_wwb(
[
"--target-model",
MODEL_PATH,
"--num-samples",
"1",
"--gt-data",
GT_FILE,
"--device",
"CPU",
"--model-type",
model_type,
"--output",
tmp_path,
"--genai",
"--num-inference-steps",
"2",
"--taylorseer-config",
'{"disable_cache_after_step": 0}',
]
)
assert (tmp_path / "target").exists()
assert (tmp_path / "target.csv").exists()

Expand Down
Loading