Yaribar/Candle-diffusion

Rust

0

3 commits

updated Apr 2, 2026

See the code

README

Candle Stable Diffusion

Generate images from text prompts using Stable Diffusion, powered by Candle — Hugging Face's pure-Rust ML framework.

Why Candle instead of tch/libtorch?

tch (libtorch)Candle
C++ dependency~2-3 GB libtorch downloadNone — pure Rust
Apple Silicon GPUNot supportedNative Metal via --features metal
Build timeLong (C++ linking)Normal Rust build
Weight downloadManual scriptsAutomatic via hf-hub on first run

Quick Start (Native)

# CPU (any platform)
cargo run --release -- --prompt "A rusty robot on a beach"

# Apple Silicon with Metal GPU
cargo run --release --features metal -- --prompt "A rusty robot on a beach"

Or use the Makefile:

make run                   # CPU
make run-metal             # Metal GPU (Mac)

CLI Options

FlagDefaultDescription
--prompt"A very realistic photo..."Text prompt
--sd-versionv1-5Model: v1-5, xl, turbo
--n-steps30 (1 for turbo)Diffusion steps
--cpuoffForce CPU
--use-f16offHalf-precision weights
--seedrandomReproducible generation
--guidance-scale7.5 (0 for turbo)Classifier-free guidance
--final-imagesd_final.pngOutput file path
--height / --widthvaries by modelImage dimensions (divisible by 8)
--num-samples1Number of images to generate

Docker (CPU only)

Docker Desktop on macOS cannot pass through Metal GPU, so the container runs on CPU.

# Build
docker build -t candle-diffusion .

# Run (mount a volume so model weights persist across runs)
docker run --rm -v hf-cache:/root/.cache/huggingface \
  candle-diffusion --prompt "A rusty robot on a beach"

GPU Availability

EnvironmentGPU BackendHow
Mac nativeMetalcargo build --features metal
Linux native (NVIDIA)CUDAcargo build --features cuda
Docker on MacNone (CPU)Metal not available in containers
GitHub Codespace (default)None (CPU)No GPU attached
GPU Codespace (NVIDIA)CUDAcargo build --features cuda

Disk Space

No libtorch download needed. Model weights (~5 GB for SD v1.5) are automatically downloaded on first run to ~/.cache/huggingface/ via hf-hub.

Contributors

Yaribar

3 commits

Yaribar/Candle-diffusion

Rust

0

3 commits

updated Apr 2, 2026

See the code

README

Candle Stable Diffusion

Generate images from text prompts using Stable Diffusion, powered by Candle — Hugging Face's pure-Rust ML framework.

Why Candle instead of tch/libtorch?

tch (libtorch)Candle
C++ dependency~2-3 GB libtorch downloadNone — pure Rust
Apple Silicon GPUNot supportedNative Metal via --features metal
Build timeLong (C++ linking)Normal Rust build
Weight downloadManual scriptsAutomatic via hf-hub on first run

Quick Start (Native)

# CPU (any platform)
cargo run --release -- --prompt "A rusty robot on a beach"

# Apple Silicon with Metal GPU
cargo run --release --features metal -- --prompt "A rusty robot on a beach"

Or use the Makefile:

make run                   # CPU
make run-metal             # Metal GPU (Mac)

CLI Options

FlagDefaultDescription
--prompt"A very realistic photo..."Text prompt
--sd-versionv1-5Model: v1-5, xl, turbo
--n-steps30 (1 for turbo)Diffusion steps
--cpuoffForce CPU
--use-f16offHalf-precision weights
--seedrandomReproducible generation
--guidance-scale7.5 (0 for turbo)Classifier-free guidance
--final-imagesd_final.pngOutput file path
--height / --widthvaries by modelImage dimensions (divisible by 8)
--num-samples1Number of images to generate

Docker (CPU only)

Docker Desktop on macOS cannot pass through Metal GPU, so the container runs on CPU.

# Build
docker build -t candle-diffusion .

# Run (mount a volume so model weights persist across runs)
docker run --rm -v hf-cache:/root/.cache/huggingface \
  candle-diffusion --prompt "A rusty robot on a beach"

GPU Availability

EnvironmentGPU BackendHow
Mac nativeMetalcargo build --features metal
Linux native (NVIDIA)CUDAcargo build --features cuda
Docker on MacNone (CPU)Metal not available in containers
GitHub Codespace (default)None (CPU)No GPU attached
GPU Codespace (NVIDIA)CUDAcargo build --features cuda

Disk Space

No libtorch download needed. Model weights (~5 GB for SD v1.5) are automatically downloaded on first run to ~/.cache/huggingface/ via hf-hub.

Contributors

Yaribar

3 commits

Languages

Rust

91.1%

Dockerfile

4.9%

Makefile

4.0%