StreamDiffusion

repository·main·Indexed 27 days ago

https://github.com/cumulo-autumn/streamdiffusion

A pipeline-level solution for real-time interactive image generation. It provides performance enhancements over standard diffusion pipelines using techniques such as Stream Batch, Residual CFG (RCFG), and TensorRT acceleration. The library supports real-time text-to-image and image-to-image workflows, including a stochastic similarity filter to reduce GPU load during video input.

Tokens
8.2K
Snippets
26
Records
56
Agent score
95%

What's inside StreamDiffusion

  1. Run the Txt2Img Real-time Example

    main

    To run the real-time text-to-image generation demo, you must install the Python dependencies, build the frontend using pnpm, and then execute the main Python script. This example allows for real-time generation of 4x4 image grids based on changing text prompts.

    pip install -r requirements.txt
    cd frontend
    pnpm i
    pnpm run build
    cd ..
    python main.py
  2. Run the Img2Img Example with Docker

    main

    You can run the Img2Img example using Docker with TensorRT support. Use the following commands to build and run the container. Setting ENGINE_DIR and HF_HOME to a local directory allows for faster container restarts by caching models and engines locally.

    docker build -t img2img .
    docker run -ti -e ENGINE_DIR=/data -e HF_HOME=/data -v ~/.cache/huggingface:/data  -p 7860:7860 --gpus all img2img
  3. Install StreamDiffusion via Docker

    main

    Use Docker for a TensorRT-ready environment. This builds an image and runs it with GPU support.

    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
  4. Install StreamDiffusion

    main

    Follow these steps to set up StreamDiffusion in your environment.

    1. Clone the repository

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

    2. Create an environment

    Using Conda:

    conda create -n streamdiffusion python=3.10
    conda activate streamdiffusion

    Or using venv:

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

    3. Install PyTorch

    Install the version matching your CUDA setup:

    CUDA 11.8:

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

    CUDA 12.1:

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

    4. Install StreamDiffusion

    For Users (Recommended): To install the latest version with TensorRT support:

    pip install git+https://github.com/cumulo-autumn/StreamDiffusion.git@main#egg=streamdiffusion[tensorrt]

    To install the stable version:

    pip install streamdiffusion[tensorrt]

    After installation, install the TensorRT extension:

    python -m streamdiffusion.tools.install-tensorrt

    Note: On Windows, if you installed the stable version, you may need to install pywin32 manually:

    pip install --force-reinstall pywin32

    For Developers:

    python setup.py develop easy_install streamdiffusion[tensorrt]
    python -m streamdiffusion.tools.install-tensorrt
    git clone https://github.com/cumulo-autumn/StreamDiffusion.git
    conda create -n streamdiffusion python=3.10
    conda activate streamdiffusion
    pip3 install torch==2.1.0 torchvision==0.16.0 xformers --index-url https://download.pytorch.org/whl/cu121
    pip install git+https://github.com/cumulo-autumn/StreamDiffusion.git@main#egg=streamdiffusion[tensorrt]
    python -m streamdiffusion.tools.install-tensorrt
  5. Install StreamDiffusion via Docker (TensorRT Ready)

    main

    To use StreamDiffusion with TensorRT support via Docker, run the following commands:

    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
  6. Run the Txt2Img Real-time Demo

    main

    This demo provides a GUI for real-time text-to-image generation using StreamDiffusion. When you change the input prompt, it generates a 4x4 grid of images in real-time.

    To run the demo, follow these steps in order:

    1. Install Python dependencies.
    2. Build the frontend using pnpm.
    3. Start the Python backend server.
    pip install -r requirements.txt
    cd frontend
    pnpm i
    pnpm run build
    cd ..
    python main.py
  7. Run the Img2Img Real-time Demo

    main

    The Img2Img demo allows for real-time image-to-image generation using a webcam or screen capture. By changing the prompt, the effects are reflected in the generated image in real-time.

    Prerequisites:

    Execution Steps:

    1. Install frontend dependencies and build the frontend.
    2. Install Python requirements.
    3. Run the main script with TensorRT acceleration.
    4. Access the interface at http://0.0.0.0:7860 (or http://localhost:7860).
    cd frontend
    npm i
    npm run build
    cd ..
    pip install -r requirements.txt
    python main.py --acceleration tensorrt