Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[features]
default = ["burn/default", "std"]
std = ["burn/std"]
std = ["burn/std", "regex", "thiserror", "burn-store", "safetensors", "memmap2"]

# Backend
accelerate = ["burn/accelerate"]
Expand All @@ -17,11 +17,26 @@ wgpu = ["burn/wgpu"]

[dependencies]
burn = { version = "0.20.1", default-features = false }
burn-store = { version = "0.20.1", optional = true, features = ["safetensors"] }
num-traits = { version = "0.2.18", default-features = false }
regex = { version = "1.10", optional = true }
safetensors = { version = "0.4", optional = true }
memmap2 = { version = "0.9", optional = true }
serde = { version = "1.0.197", default-features = false, features = [
"derive",
"alloc",
] }
thiserror = { version = "1.0", optional = true }

[patch.crates-io]
#burn = { git = "https://github.com/tracel-ai/burn" }
[[example]]
name = "stable-diffusion"
required-features = ["std"]

[dev-dependencies]
anyhow = "1.0"
clap = { version = "4.4", features = ["derive", "env"] }
dirs = "5.0"
flate2 = "1.0"
hf-hub = "0.3"
image = "0.25"
ureq = "2.9"
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# diffusers-burn: A diffusers API in Rust/Burn
# diffusers-burn

> **⚠️ This is still in development - contributors welcome!**
Stable Diffusion in Rust using [Burn](https://github.com/burn-rs/burn). Supports SD 1.5 and 2.1.

The `diffusers-burn` crate is a conversion of [diffusers-rs](https://github.com/LaurentMazare/diffusers-rs) using [burn](https://github.com/burn-rs/burn) rather than libtorch. This implementation supports Stable Diffusion v1.5, v2.1, as well as Stable Diffusion XL 1.0.
Based on [diffusers-rs](https://github.com/LaurentMazare/diffusers-rs).

<div align="left" valign="middle">
<a href="https://runblaze.dev">
Expand All @@ -18,29 +18,39 @@ _[Blaze](https://runblaze.dev) supports this project by providing ultra-fast App

</div>

## Feature Flags
## Quick Start

This crate can be used without the standard library (`#![no_std]`) with `alloc` by disabling
the default `std` feature.
```bash
# Using wgpu backend (default, works on most GPUs)
cargo run --release --features wgpu --example stable-diffusion -- \
--prompt "A photo of a rusty robot on a beach"

* `std` - enables the standard library. Enabled by default.
* `wgpu` - uses ndarray as the backend. Enabled by default when none specified and `std`.
* `ndarray` - uses ndarray as the backend.
* `ndarray-no-std` - uses ndarray-no-std as the backend. Enabled by default when none and `#![no_std]`.
* `ndarray-blas-accelerate` - uses ndarray with Accelerate framework (macOS only).
* `torch` - uses torch as the backend.
# Using torch backend
cargo run --release --features torch --example stable-diffusion -- \
--prompt "A photo of a rusty robot on a beach"

## Community
# SD 2.1 at 768x768
cargo run --release --features torch --example stable-diffusion -- \
--sd-version v2-1 \
--prompt "A majestic lion on a cliff at sunset"
```

## Backends

| Feature | Backend | Notes |
|---------|---------|-------|
| `wgpu` | WebGPU | Cross-platform GPU support |
| `torch` | LibTorch | Requires libtorch |
| `ndarray` | ndarray | CPU only, pure Rust |

If you are excited about the project or want to contribute, don't hesitate to join our [Discord](https://discord.gg/UHtSgF6j5J)!
We try to be as welcoming as possible to everybody from any background. We're still building this out, but you can ask your questions there!
## no_std Support

## Status
This crate supports `#![no_std]` with `alloc` by disabling the default `std` feature.

## Community

diffusers-burn is currently in active development, and is not yet complete.
Join our [Discord](https://discord.gg/UHtSgF6j5J) if you want to contribute or have questions!

## License

diffusers-burn is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See [LICENSE-APACHE](./LICENSE-APACHE) and [LICENSE-MIT](./LICENSE-MIT) for details. Opening a pull
request is assumed to signal agreement with these licensing terms.
MIT or Apache-2.0, at your option.
25 changes: 25 additions & 0 deletions examples/stable-diffusion/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "stable-diffusion-example"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "stable-diffusion"
path = "main.rs"

[features]
default = ["wgpu"]
torch = ["diffusers-burn/torch", "burn/tch"]
ndarray = ["diffusers-burn/ndarray", "burn/ndarray"]
wgpu = ["diffusers-burn/wgpu", "burn/wgpu"]

[dependencies]
diffusers-burn = { path = "../..", features = ["std"], default-features = false }
burn = { version = "0.20.1", default-features = false }
clap = { version = "4", features = ["derive"] }
image = "0.25"
anyhow = "1.0"
hf-hub = "0.4"
ureq = "2"
flate2 = "1"
dirs = "6"
Loading
Loading