AsyncDiff

czg1225Apache-2.0长期未更新

把扩散模型的去噪步骤拆到多张卡上异步并行执行,无需重新训练就能显著加速 Stable Diffusion 等文生图、文生视频模型的推理。

[NeurIPS 2024] AsyncDiff: Parallelizing Diffusion Models by Asynchronous Denoising

暂无版本216star13fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
conda create -n asyncdiff python=3.10
conda activate asyncdiff
pip install -r requirements.txt
硬件要求按 README 说明

需要 NVIDIA GPU,CUDA >= 12.0 及对应 CuDNN;多卡并行,示例中按 2 卡或 4 卡启动;README 未给出具体显存数值。

需要 CUDA
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把扩散模型拆成多段放到多卡上异步去噪,用来降低推理延迟的即插即用加速方案

把扩散模型的去噪步骤拆到多张卡上异步并行执行,无需重新训练就能显著加速 Stable Diffusion 等文生图、文生视频模型的推理。

核心能力

  • 将噪声预测模型切分为 2/3/4 个组件分派到不同设备
  • 利用相邻去噪步隐状态高相似性打破组件间依赖链
  • 以 warm-up 阶段换取与原输出接近的像素级一致性
  • 两行代码接入 diffusers 的 Stable Diffusion 系列管线
  • 提供 SDXL、SD3、ControlNet、AnimateDiff、SVD 等示例脚本

容易踩的坑

需 PyTorch >= v2.0.1 且 CUDA 不低于 12.0,环境不匹配会装不上或跑不起来;模型权重需从 Hugging Face 另行下载,首次运行会拉取;多卡示例依赖 torch.distributed 启动,单卡直接跑脚本无法复现加速效果。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    AsyncDiff: Parallelizing Diffusion Models by Asynchronous Denoising
    Zigeng Chen, Xinyin Ma, Gongfan Fang, Zhenxiong Tan, Xinchao Wang
    xML Lab, National University of Singapore
    🥯[Paper]🎄[Project Page]
    Code Contributors: Zigeng Chen, Zhenxiong Tan

    Updates

    • :tada: September 26, 2024: Our AsyncDiff is accepted by NeurIPS 2024!
    • 🚀 August 14, 2024: Now supporting Stable Diffusion XL Inpainting! The inference sample of accelerating SDXL Inpainting can be found at run_sdxl_inpaint.py.
    • 🚀 July 18, 2024: Now supporting Stable Diffusion 3 Medium! The inference sample of accelerating SD 3 can be found at run_sd3.py.
    • 🚀 June 18, 2024: Now supporting ControlNet! The inference sample of accelerating controlnet+SDXL can be found at run_sdxl_controlnet.py.
    • 🚀 June 17, 2024: Now supporting Stable Diffusion x4 Upscaler! The inference sample can be found at run_sd_upscaler.py.
    • 🚀 June 12, 2024: Code of AsyncDiff is released.

    Supported Diffusion Models:

    Introduction

    We introduce AsyncDiff, a universal and plug-and-play diffusion acceleration scheme that enables model parallelism across multiple devices. Our approach divides the cumbersome noise prediction model into multiple components, assigning each to a different device. To break the dependency chain between these components, it transforms the conventional sequential denoising into an asynchronous process by exploiting the high similarity between hidden states in consecutive diffusion steps. Consequently, each component is facilitated to compute in parallel on separate devices. The proposed strategy significantly reduces inference latency while minimally impacting the generative quality.

    AsyncDiff Overview Above is the overview of the asynchronous denoising process. The denoising model εθ is divided into four components for clarity. Following the warm-up stage, each component’s input is prepared in advance, breaking the dependency chain and facilitating parallel processing.

    🔧 Quick Start

    Installation

    • Prerequisites

      NVIDIA GPU + CUDA >= 12.0 and corresponding CuDNN

    • Create environment:

      conda create -n asyncdiff python=3.10
      conda activate asyncdiff
      pip install -r requirements.txt
      

    Usage Example

    Simply add two lines of code to enable asynchronous parallel inference for the diffusion model.

    import torch
    from diffusers import StableDiffusionPipeline
    from asyncdiff.async_sd import AsyncDiff
    
    pipeline = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", 
    torch_dtype=torch.float16, use_safetensors=True, low_cpu_mem_usage=True)
    
    async_diff = AsyncDiff(pipeline, model_n=2, stride=1, time_shift=False)
    
    async_diff.reset_state(warm_up=1)
    image = pipeline(<prompts>).images[0]
    if dist.get_rank() == 0:
      image.save(f"output.jpg")
    

    Here, we use the Stable Diffusion pipeline as an example. You can replace pipeline with any variant of the Stable Diffusion pipeline, such as SD 2.1, SD 1.5, SDXL, or SVD. We also provide the implementation of AsyncDiff for AnimateDiff in asyncdiff.async_animate.

    • model_n: Number of components into which the denoising model is divided. Options: 2, 3, or 4.
    • stride: Denoising stride of each parallel computing batch. Options: 1 or 2.
    • warm_up: Number of steps for the warm-up stage. More warm-up steps can achieve pixel-level consistency with the original output while slightly reducing processing speed.
    • time_shift: Enables time shifting. Setting time_shift to True can enhance the denoising capability of the diffusion model. However, it should generally remain False. Only enable time_shift when the accelerated model produces images or videos with significant noise.

    Inference

    We offer detailed scripts in examples/ for accelerating inference of SD 2.1, SD 1.5, SDXL, SD 3, ControNet, SD_Upscaler, AnimateDiff, and SVD using our AsyncDiff framework.

    🚀 Accelerate Stable Diffusion XL:

    CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.run --nproc_per_node=4 --run-path examples/run_sdxl.py
    

    🚀 Accelerate Stable Diffusion 2.1 or 1.5:

    CUDA_VISIBLE_DEVICES=0,1,2,3 python -m torch.distributed.run --nproc_per_node=4 --run-path examples/run_sd.py
    

    🚀 Accelerate Stable Diffusion 3 Medium:

    CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --run-path examples/run_sd3.py
    

    🚀 Accelerate Stable Diffusion x4 Upscaler:

    CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --run-path examples/run_sd_upscaler.py
    

    🚀 Accelerate SDXL Inpainting:

    CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --run-path examples/run_sdxl_inpaint.py
    

    🚀 Accelerate ControlNet+SDXL :

    CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --run-path examples/run_sdxl_controlnet.py
    

    🚀 Accelerate Animate Diffusion:

    CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --run-path examples/run_animatediff.py
    

    🚀 Accelerate Stable Video Diffusion:

    CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.run --nproc_per_node=2 --run-path examples/run_svd.py
    

    Qualitative Results

    Qualitative Results on SDXL and SD 2.1. More qualitative results can be found in our paper. Qualitative Results

    Qualitative Results

    Quantitative Results

    Quantitative evaluations of AsyncDiff on three text-to-image diffusion models, showcasing various configurations. More quantitative results can be found in our paper. Quantitative Results

    Bibtex

    @article{chen2024asyncdiff,
      title={Asyncdiff: Parallelizing diffusion models by asynchronous denoising},
      author={Chen, Zigeng and Ma, Xinyin and Fang, Gongfan and Tan, Zhenxiong and Wang, Xinchao},
      journal={Advances in Neural Information Processing Systems},
      volume={37},
      pages={95170--95197},
      year={2024}
    }