onediff

siliconflowApache-2.0更新放缓

开箱即用的扩散模型推理加速库,兼容 Diffusers 和 ComfyUI,通过编译优化和 LoRA 支持显著提升图像生成速度。

OneDiff: An out-of-the-box acceleration library for diffusion models.

1.2.0发布于 2024-07-29 14:57 UTC1,962star128fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
python3 -m pip install onediff
硬件要求按 README 说明

需要 Linux(Windows 需在 WSL2 下使用)和 NVIDIA GPU,README 列出的兼容型号包括 3090、4090、A100、A800、A10 等,Ascend 兼容仍在进行中;README 未说明显存要求。

支持 Apple Silicon需要 CUDA昇腾 / Ascend
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

一行代码加速扩散模型的即插即用库,兼容 HF diffusers、ComfyUI 和 SD web UI

开箱即用的扩散模型推理加速库,兼容 Diffusers 和 ComfyUI,通过编译优化和 LoRA 支持显著提升图像生成速度。

核心能力

  • 一行代码接入 HF diffusers、ComfyUI、SD web UI
  • 提供 PyTorch 代码编译工具与优化的 GPU Kernel
  • 支持动态分辨率输入且无额外开销
  • 可离线编译并保存计算图,线上加载省去编译时间
  • 覆盖 SD1.5~2.1、SDXL、SVD、LoRA、ControlNet 等模型

容易踩的坑

需先自行安装 torch 和 diffusers,并额外安装编译器后端(Nexfort 或 OneFlow);用 ComfyUI/SD web UI 插件时建议从源码安装,并手动复制或软链代码到扩展目录;README 未说明默认端口。

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

最近发版

5 个版本1.2.0
  1. 1.2.01.2.0(SD3, Latte and Kolors acceleratoin)最新正式版2024-07-29 · 2024-07-29 14:57 UTC

    Hightlight

    Reference: 1.2 milestone. https://github.com/siliconflow/onediff/milestone/5

    New Contributors

    What's Changed

  2. 1.1.01.1.0( DiT model Acceleration and nexfort compiler backend Beta Release)2024-06-07 · 2024-06-07 14:14 UTC
    查看更新说明

    Hightlight

    What's Changed

  3. 1.0.02024-04-13 · 2024-04-13 11:24 UTC
    查看更新说明

    OneDiff 1.0

    OneDiff 1.0 is for Stable Diffusion and Stable Video Diffusion models(UNet/VAE/CLIP based) acceleration. We have got a lot of support/feedback from the community: https://github.com/siliconflow/onediff/wiki , big thanks!

    The later version 2.0 will focus on DiT/Sora-like models.

    OneDiff 1.0 's updates are mainly the issues in milestone 0.13

    What's Changed

  4. 0.12.10.12.1(Stable acceleration of SD and SVD for production environment)2024-03-02 · 2024-03-02 06:33 UTC
    查看更新说明

    SOTA performance update for SDXL and SVD

    https://github.com/siliconflow/onediff/tree/main?tab=readme-ov-file#state-of-the-art-performance

    Fully support dynamic resolution run of SD and SVD

    https://github.com/siliconflow/onediff/blob/55627d50157d4a0c4b484ba76b088c90f39179ff/onediff_diffusers_extensions/examples/text_to_image_sdxl.py#L96

    Compile/Save/Load pipeline for HF diffusers

    https://github.com/siliconflow/onediff/tree/main/onediff_diffusers_extensions#compile-save-and-load-pipeline

    Fast LoRA loading and switching for HF diffusers

    https://github.com/siliconflow/onediff/tree/main/onediff_diffusers_extensions#fast-lora-loading-and-switching

    Accelerate InstantID

    https://github.com/siliconflow/onediff/blob/main/benchmarks/instant_id.py https://github.com/siliconflow/onediff/tree/main/onediff_comfy_nodes#instantid

    Accelerate SDXL lightning

    https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/text_to_image_sdxl_light.py

    Reuse compiled components between pipelines

    https://github.com/siliconflow/onediff/blob/main/onediff_diffusers_extensions/examples/reuse_compiled_pipeline_components.py

    Compatible with HF diffisers 0.26

    SD Webui support img2img

    Change log

  5. 0.12.00.12.0(Enable vm runtime as default)2024-01-12 · 2024-01-12 07:07 UTC
    查看更新说明

    onediff 0.12 (change image size will have no cost for most of the models now)

    • switch image size will not trigger re-compilation(i.e. no time cost);
    • faster to save and load a graph;
    • smaller static memory needed;
    • much easier to switch graphs;

    Note

    1. After updating onediff to 0.12, oneflow also needs to be updated to the latest with https://github.com/siliconflow/onediff?tab=readme-ov-file#1-install-oneflow
    2. If you are using save/load graph. Please use this new version to save the graph again.
    3. For SVD(Stable Video Diffusion) onediff users, please use os.environ["VM_REBUILD_DYNAMIC_SHAPE"] = "1" to support DYNAMIC SHAPE with SVD. There has some re-compile cost, when enabling VM_REBUILD_DYNAMIC_SHAPE, so loading graph is needed. We will do more work on this.

    OneDiff SDXL inference has been integrated into fal.ai playground

    SDXL inference at the speed of thought: https://www.fal.ai/models/onediff-sdxl

    And OneDiff ComfyUI nodes are in ComfyUI-Manager Now

    img_v3_0271_db8b580c-89e2-49a3-8041-26d34d02549g

用户点评

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

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

    README 原文

    未翻译

    onediff is an out-of-the-box acceleration library for diffusion models, it provides:

    • Out-of-the-box acceleration for popular UIs/libs(such as HF diffusers and ComfyUI)
    • PyTorch code compilation tools and strong optimized GPU Kernels for diffusion models

    News

    Hiring

    We're hiring! If you are interested in working on onediff at SiliconFlow, we have roles open for Interns and Engineers in Beijing (near Tsinghua University).

    If you have contributed significantly to open-source software and are interested in remote work, you can contact us at [email protected] with onediff in the email title.


    Documentation

    onediff is the abbreviation of "one line of code to accelerate diffusion models".

    Use with HF diffusers and ComfyUI

    Performance comparison

    SDXL E2E time
    • Model stabilityai/stable-diffusion-xl-base-1.0;
    • Image size 1024*1024, batch size 1, steps 30;
    • NVIDIA A100 80G SXM4;
    SVD E2E time
    • Model stabilityai/stable-video-diffusion-img2vid-xt;
    • Image size 576*1024, batch size 1, steps 25, decoder chunk size 5;
    • NVIDIA A100 80G SXM4;

    Note that we haven't got a way to run SVD with TensorRT on Feb 29 2024.

    Quality Evaluation

    We also maintain a repository for benchmarking the quality of generation after acceleration: odeval

    Community and Support

    Installation

    0. OS and GPU Compatibility
    1. Install torch and diffusers

    Note: You can choose the latest versions you want for diffusers or transformers.

    python3 -m pip install "torch" "transformers==4.27.1" "diffusers[torch]==0.19.3"
    
    2. Install a compiler backend

    When considering the choice between OneFlow and Nexfort, either one is optional, and only one is needed.

    • For DiT structural models or H100 devices, it is recommended to use Nexfort.

    • For all other cases, it is recommended to use OneFlow. Note that optimizations within OneFlow will gradually transition to Nexfort in the future.

    Nexfort

    Install Nexfort is Optional. The detailed introduction of Nexfort is here.

    python3 -m  pip install -U torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 torchao==0.1
    python3 -m  pip install -U nexfort
    
    OneFlow

    Install OneFlow is Optional.

    NOTE: We have updated OneFlow frequently for onediff, so please install OneFlow by the links below.

    • CUDA 11.8

      For NA/EU users

      python3 -m pip install -U --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/community_cu118
      

      For CN users

      python3 -m pip install -U --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu118
      
    • CUDA 12.1

      For NA/EU users

      python3 -m pip install -U --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/community_cu122
      

      For CN users

      python3 -m pip install -U --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu122
      
    • CUDA 12.2

      For NA/EU users

      python3 -m pip install -U --pre oneflow -f https://github.com/siliconflow/oneflow_releases/releases/expanded_assets/community_cu122
      

      For CN users

      python3 -m pip install -U --pre oneflow -f https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu122
      
    3. Install onediff
    • From PyPI
    python3 -m pip install --pre onediff
    
    • From source
    git clone https://github.com/siliconflow/onediff.git
    
    cd onediff && python3 -m pip install -e .
    

    Or install for development:

    # install for dev
    cd onediff && python3 -m pip install -e '.[dev]'
    
    # code formatting and linting
    pip3 install pre-commit
    pre-commit install
    pre-commit run --all-files
    

    NOTE: If you intend to utilize plugins for ComfyUI/StableDiffusion-WebUI, we highly recommend installing OneDiff from the source rather than PyPI. This is necessary as you'll need to manually copy (or create a soft link) for the relevant code into the extension folder of these UIs/Libs.

    More about onediff

    Architecture

    Features

    FunctionalityDetails
    Compiling TimeAbout 1 minute (SDXL)
    Deployment MethodsPlug and Play
    Dynamic Image Size SupportSupport with no overhead
    Model SupportSD1.5~2.1, SDXL, SDXL Turbo, etc.
    Algorithm SupportSD standard workflow, LoRA, ControlNet, SVD, InstantID, SDXL Lightning, etc.
    SD Framework SupportComfyUI, Diffusers, SD-webui
    Save & Load Accelerated ModelsYes
    Time of LoRA SwitchingHundreds of milliseconds
    LoRA OccupancyTens of MB to hundreds of MB.
    Device SupportNVIDIA GPU 3090 RTX/4090 RTX/A100/A800/A10 etc. (Compatibility with Ascend in progress)

    Acceleration for State-of-the-art models

    onediff supports the acceleration for SOTA models.

    • stable: release for public usage, and has long-term support;
    • beta: release for professional usage, and has long-term support;
    • alpha: early release for expert usage, and should be careful to use;
    AIGC TypeModelsHF diffusersComfyUISD web UI
    CommunityEnterpriseCommunityEnterpriseCommunityEnterprise
    ImageSD 1.5stablestablestablestablestablestable
    SD 2.1stablestablestablestablestablestable
    SDXLstablestablestablestablestablestable
    LoRAstablestablestable
    ControlNetstablestable
    SDXL Turbostablestable
    LCMstablestable
    SDXL DeepCachealphaalphaalphaalpha
    InstantIDbetabeta
    VideoSVD(stable Video Diffusion)stablestablestablestable
    SVD DeepCachealphaalphaalphaalpha

    Acceleration for production environment

    PyTorch Module compilation
    Avoid compilation time for new input shape
    Avoid compilation time for online serving

    Compile and save the compiled result offline, then load it online for serving

    Distributed Run

    If you want to do distributed inference, you can use onediff's compiler to do single-device acceleration in a distributed inference engine such as xDiT

    OneDiff Enterprise Solution

    If you need Enterprise-level Support for your system or business, you can email us at [email protected], or contact us through the website: https://siliconflow.cn/pricing

    Onediff Enterprise Solution
    More extreme compiler optimization for diffusion processUsually another 20%~30% or more performance gain
    End-to-end workflow speedup solutionsSometimes 200%~300% performance gain
    End-to-end workflow deployment solutionsWorkflow to online model API
    Technical support for deploymentHigh priority support

    Citation

    @misc{2022onediff,
      author={OneDiff Contributors},
      title = {OneDiff: An out-of-the-box acceleration library for diffusion models},
      year = {2022},
      publisher = {GitHub},
      journal = {GitHub repository},
      howpublished = {\url{https://github.com/siliconflow/onediff}}
    }