MCPcopy Index your code
hub / github.com/EricLBuehler/diffusion-rs

github.com/EricLBuehler/diffusion-rs @v0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.0 ↗ · + Follow
2,377 symbols 8,451 edges 155 files 412 documented · 17%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

diffusion-rs

Blazingly fast inference of diffusion models.

| Rust Documentation | Python Documentation | Discord |

Features

  • Quantization
  • bitsandbytes format (fp4, nf4, and int8)
  • GGUF (2-8 bit quantization)
  • Easy: Strong support for running 🤗 DDUF models.
  • Strong Apple Silicon support: support for the Metal, Accelerate, and ARM NEON frameworks
  • Support for NVIDIA GPUs with CUDA
  • AVX support for x86 CPUs
  • Allow acceleration of models larger than the total VRAM size with offloading

Please do not hesitate to contact us with feature requests via Github issues!

Upcoming features

  • 🚧 LoRA support
  • 🚧 CPU + GPU inference with automatic offloading to allow partial acceleration of models larger than the total VRAM

Installation

Check out the installation guide for details about installation.

Examples

After installing, you can try out these examples!

Download the DDUF file here: wget https://huggingface.co/DDUF/FLUX.1-dev-DDUF/resolve/main/FLUX.1-dev-Q4-bnb.dduf

CLI:

diffusion_rs_cli --scale 3.5 --num-steps 50 dduf -f FLUX.1-dev-Q4-bnb.dduf

More CLI examples here.

Python:

More Python examples here.

from diffusion_rs import DiffusionGenerationParams, ModelSource, Pipeline
from PIL import Image
import io

pipeline = Pipeline(source=ModelSource.DdufFile("FLUX.1-dev-Q4-bnb.dduf"))

image_bytes = pipeline.forward(
    prompts=["Draw a picture of a sunrise."],
    params=DiffusionGenerationParams(
        height=720, width=1280, num_steps=50, guidance_scale=3.5
    ),
)

image = Image.open(io.BytesIO(image_bytes[0]))
image.show()

Rust crate:

Examples with the Rust crate: here.

use std::time::Instant;

use diffusion_rs_core::{DiffusionGenerationParams, ModelSource, Offloading, Pipeline, TokenSource};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;

let filter = EnvFilter::builder()
    .with_default_directive(LevelFilter::INFO.into())
    .from_env_lossy();
tracing_subscriber::fmt().with_env_filter(filter).init();

let pipeline = Pipeline::load(
    ModelSource::dduf("FLUX.1-dev-Q4-bnb.dduf")?,
    false,
    TokenSource::CacheToken,
    None,
    None,
)?;

let start = Instant::now();

let images = pipeline.forward(
    vec!["Draw a picture of a sunrise.".to_string()],
    DiffusionGenerationParams {
        height: 720,
        width: 1280,
        num_steps: 50,
        guidance_scale: 3.5,
    },
)?;

let end = Instant::now();
println!("Took: {:.2}s", end.duration_since(start).as_secs_f32());

images[0].save("image.png")?;

Support matrix

Model Supports DDUF Supports quantized DDUF
FLUX.1 Dev/Schnell

Contributing

  • Anyone is welcome to contribute by opening PRs
  • See good first issues for a starting point!
  • Collaborators will be invited based on past contributions

Extension points exported contracts — how you extend this code

EncoderParam (Interface)
Helper functions to create the various objects on the compute command encoder on a single line. Prevents getting wrong s [7 …
diffusion_rs_backend/src/metal_kernels/utils.rs
EncoderParam (Interface)
Helper functions to create the various objects on the compute command encoder on a single line. Prevents getting wrong s [7 …
diffusion_rs_common/src/metal_kernels/utils.rs
QuantizedModel (Interface)
(no doc) [2 implementers]
diffusion_rs_core/src/models/mod.rs
Matmul (Interface)
Matrix matrix multiplication with elements of type `T`. [4 implementers]
diffusion_rs_backend/src/cublaslt/matmul.rs
Module (Interface)
A simple trait defining a module with forward method using a single argument. [36 implementers]
diffusion_rs_common/src/core/mod.rs
Loader (Interface)
(no doc) [1 implementers]
diffusion_rs_core/src/pipelines/mod.rs
QuantMethod (Interface)
Quantized method for a quantized matmul. [3 implementers]
diffusion_rs_backend/src/lib.rs
CustomOp1 (Interface)
Unary ops that can be defined in user-land. [7 implementers]
diffusion_rs_common/src/core/custom_op.rs

Core symbols most depended-on inside this repo

len
called by 462
diffusion_rs_common/src/nn/sequential.rs
clone
called by 415
diffusion_rs_common/src/nn/var_builder.rs
map
called by 357
diffusion_rs_common/src/core/cpu_backend/utils.rs
w
called by 304
diffusion_rs_common/src/core/cuda_backend/error.rs
add
called by 264
diffusion_rs_common/src/core/tensor.rs
shape
called by 252
diffusion_rs_common/src/core/tensor.rs
dims
called by 235
diffusion_rs_common/src/core/shape.rs
as_ptr
called by 230
diffusion_rs_common/src/core/quantized/mod.rs

Shape

Method 1,295
Function 631
Class 302
Enum 76
Interface 73

Languages

Rust100%

Modules by API surface

diffusion_rs_common/src/core/tensor.rs154 symbols
diffusion_rs_common/src/core/cpu_backend/mod.rs81 symbols
diffusion_rs_common/src/metal_kernels/tests.rs80 symbols
diffusion_rs_common/src/core/cuda_backend/mod.rs77 symbols
diffusion_rs_common/src/metal_kernels/mod.rs73 symbols
diffusion_rs_common/src/core/op.rs70 symbols
diffusion_rs_common/src/core/dummy_cuda_backend.rs52 symbols
diffusion_rs_common/src/core/metal_backend/mod.rs51 symbols
diffusion_rs_common/src/core/dummy_metal_backend.rs47 symbols
diffusion_rs_common/src/nn/var_builder.rs43 symbols
diffusion_rs_common/src/nn/ops.rs43 symbols
diffusion_rs_common/src/core/quantized/mod.rs42 symbols

For agents

$ claude mcp add diffusion-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact