Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

StreamDiffusion

> 编程语言
Open source

StreamDiffusion: A Pipeline-Level Solution for Real-Time Interactive Generation

10.8K stars0 likes0 views
WebsiteGitHub

About

StreamDiffusion: A Pipeline-Level Solution for Real-Time Interactive Generation

StreamDiffusion

English | 日本語 | 한국어

StreamDiffusion: A Pipeline-Level Solution for Real-Time Interactive Generation

Authors: Akio Kodaira*, Chenfeng Xu*, Toshiki Hazama*, Takanori Yoshimoto, Kohei Ohno, Shogo Mitsuhori, Soichi Sugano, Hanying Cho, Zhijian Liu, Masayoshi Tomizuka, Kurt Keutzer

StreamDiffusion is an innovative diffusion pipeline designed for real-time interactive generation. It introduces significant performance enhancements to current diffusion-based image generation techniques. We sincerely thank Taku Fujimoto and Radamés Ajna and Hugging Face team for their invaluable feedback, courteous support, and insightful discussions.

Key Features

  1. Stream Batch

    • Streamlined data processing through efficient batch operations.
  2. Residual Classifier-Free Guidance - Learn More

    • Improved guidance mechanism that minimizes computational redundancy.
  3. Stochastic Similarity Filter - Learn More

    • Improves GPU utilization efficiency through advanced filtering techniques.
  4. IO Queues

    • Efficiently manages input and output operations for smoother execution.
  5. Pre-Computation for KV-Caches

    • Optimizes caching strategies for accelerated processing.
  6. Model Acceleration Tools

    • Utilizes various tools for model optimization and performance boost.

When images are produced using our proposed StreamDiffusion pipeline in an environment with GPU: RTX 4090, CPU: Core i9-13900K, and OS: Ubuntu 22.04.3 LTS.

model Denoising Step fps on Txt2Img fps on Img2Img
SD-turbo 1 106.16 93.897
LCM-LoRA
+
KohakuV2
4 38.023 37.133

Feel free to explore each feature by following the provided links to learn more about StreamDiffusion's capabilities. If you find it helpful, please consider citing our work:

bash
@article{kodaira2023streamdiffusion,
      title={StreamDiffusion: A Pipeline-level Solution for Real-time Interactive Generation},
      author={Akio Kodaira and Chenfeng Xu and Toshiki Hazama and Takanori Yoshimoto and Kohei Ohno and Shogo Mitsuhori and Soichi Sugano and Hanying Cho and Zhijian Liu and Kurt Keutzer},
      year={2023},
      eprint={2312.12491},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

Installation

Step0: clone this repository

bash
git clone https://github.com/cumulo-autumn/StreamDiffusion.git

Step1: Make Environment

You can install StreamDiffusion via pip, conda, or Docker(explanation below).

bash
conda create -n streamdiffusion python=3.10
conda activate streamdiffusion

OR

cmd
python -m venv .venv
# Windows
.\.venv\Scripts\activate
# Linux
source .venv/bin/activate

Step2: Install PyTorch

Select the appropriate version for your system.

CUDA 11.8

bash
pip3 install torch==2.1.0 torchvision==0.16.0 xformers --index-url https://download.pytorch.org/whl/cu118

CUDA 12.1

bash
pip3 install torch==2.1.0 torchvision==0.16.0 xformers --index-url https://download.pytorch.org/whl/cu121

details: https://pytorch.org/

Step3: Install StreamDiffusion

For User

Install StreamDiffusion

bash
#for Latest Version (recommended)
pip install git+https://github.com/cumulo-autumn/StreamDiffusion.git@main#egg=streamdiffusion[tensorrt]

#or

#for Stable Version
pip install streamdiffusion[tensorrt]

Install TensorRT extension

bash
python -m streamdiffusion.tools.install-tensorrt

(Only for Windows) You may need to install pywin32 additionally, if you installed Stable Version(pip install streamdiffusion[tensorrt]).

bash
pip install --force-reinstall pywin32

For Developer

bash
python setup.py develop easy_install streamdiffusion[tensorrt]
python -m streamdiffusion.tools.install-tensorrt

Docker Installation (TensorRT Ready)

bash
git clone https://github.com/cumulo-autumn/StreamDiffusion.git
cd StreamDiffusion
docker build -t stream-diffusion:latest -f Dockerfile .
docker run --gpus all -it -v $(pwd):/home/ubuntu/streamdiffusion stream-diffusion:latest

Quick Start

You can try StreamDiffusion in examples directory.

Real-Time Txt2Img Demo

There is an interactive txt2img demo in demo/realtime-txt2img directory!

Real-Time Img2Img Demo

There is a real time img2img demo with a live webcam feed or screen capture on a web browser in demo/realtime-img2img directory!

Usage Example

We provide a simple example of how to use StreamDiffusion. For more detailed examples, please refer to examples directory.

Image-to-Image

…

Text-to-Image

…

You can make it faster by using SD-Turbo.

Faster generation

Replace the following code in the above example.

python
pipe.enable_xformers_memory_efficient_attention()

To

python
from streamdiffusion.acceleration.tensorrt import accelerate_with_tensorrt

stream = accelerate_with_tensorrt(
    stream, "engines", max_batch_size=2,
)

It requires TensorRT extension and time to build the engine, but it will be faster than the above example.

Optionals

Stochastic Similarity Filter

Stochastic Similarity Filter reduces processing during video input by minimizing conversion operations when there is little change from the previous frame, thereby alleviating GPU processing load, as shown by the red frame in the above GIF. The usage is as follows:

python
stream = StreamDiffusion(
    pipe,
    [32, 45],
    torch_dtype=torch.float16,
)
stream.enable_similar_image_filter(
    similar_image_filter_threshold,
    similar_image_filter_max_skip_frame,
)

There are the following parameters that can be set as arguments in the function:

similar_image_filter_threshold

  • The threshold for similarity between the previous frame and the current frame before the processing is paused.

similar_image_filter_max_skip_frame

  • The maximum interval during the pause before resuming the conversion.

Residual CFG (RCFG)

RCFG is a method for approximately realizing CFG with competitive computational complexity compared to cases where CFG is not used. It can be specified through the cfg_type argument in the StreamDiffusion. There are two types of RCFG: one with no specified items for negative prompts RCFG Self-Negative and one where negative prompts can be specified RCFG Onetime-Negative. In terms of computational complexity, denoting the complexity without CFG as N and the complexity with a regular CFG as 2N, RCFG Self-Negative can be computed in N steps, while RCFG Onetime-Negative can be computed in N+1 steps.

The usage is as follows:

python
# w/0 CFG
cfg_type = "none"
# CFG
cfg_type = "full"
# RCFG Self-Negative
cfg_type = "self"
# RCFG Onetime-Negative
cfg_type = "initialize"
stream = StreamDiffusion(
    pipe,
    [32, 45],
    torch_dtype=torch.float16,
    cfg_type=cfg_type,
)
stream.prepare(
    prompt="1girl, purple hair",
    guidance_scale=guidance_scale,
    delta=delta,
)

The delta has a moderating effect on the effectiveness of RCFG.

Development Team

Aki, Ararat, Chenfeng Xu, ddPn08, kizamimi, ramune, teftef, Tonimono, Verb,

(*alphabetical order)

Acknowledgements

The video and image demos in this GitHub repository were generated using LCM-LoRA + KohakuV2 and SD-Turbo.

Special thanks to LCM-LoRA authors for providing the LCM-LoRA and Kohaku BlueLeaf (@KBlueleaf) for providing the KohakuV2 model and ,to Stability AI for SD-Turbo.

KohakuV2 Models can be downloaded from Civitai and Hugging Face.

SD-Turbo is also available on Hugging Face Space.

Contributors

Issues· 113 open

View all issuesOpen on GitHub
  • #198

    스테이블디퓰젼

    Updated Aug 20, 2026
  • #193

    Does this apply to the rectified flow model?

    Updated Nov 30, 2025
  • #196

    How did you connect the Photoshop interface with the python script of your examples of your project's GIFs

    Updated Aug 15, 2025
  • #191

    Support for CUDA 12.8 and PyTorch Compatibility with 50xx GPUs

    Updated Aug 15, 2025
  • #186

    New readme instructions (VSCODE)

    Updated Jul 16, 2025
  • #141

    Does this work with SDXL LCM?

    Updated Jul 10, 2025
  • #172

    3060ti with 5fps

    Updated Jul 4, 2025
  • #185

    onnxruntime 1.16.3 dependency is no longer available

    Updated Jun 12, 2025
  • #190

    compatibility with rtx 50 series blackwell

    Updated May 1, 2025
  • #179

    hugging_face_hub

    Updated Mar 28, 2025

> Tags

Python

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 28, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言