GitHub - cconthekeyboard/sana.cpp: SANA (text-to-image model) implemented in CPP · GitHub
/" data-turbo-transient="true" />
Skip to content
Search/
Sign in<br>Sign upAppearance settings
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
cconthekeyboard
sana.cpp
Public
Notifications<br>You must be signed in to change notification settings
Fork
Star
main
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>2 Commits<br>2 Commits
assets
assets
src
src
tests
tests
tools
tools
CMakeLists.txt
CMakeLists.txt
LICENSE
LICENSE
README.md
README.md
download_weights.sh
download_weights.sh
View all files
Repository files navigation
sana.cpp
A minimalistic C++ implementation of Sana's (0.6B) text-to-image<br>inference pipeline optimized for Apple Silicon<br>CPU — ~4.8x faster than the PyTorch pipeline on Apple Silicon CPU
Contents
Contents
Getting started
What's here
Benchmarking: Python vs C++
Tests
Project layout
License
Getting started
Requirements: CMake >= 3.16, a C++17 compiler, and macOS on Apple Silicon<br>(the primary target — it links against the Accelerate framework and builds<br>with -mcpu=native; a non-Apple -march=native path exists but is less<br>exercised). llama.cpp/ggml aren't vendored as source — they're pulled<br>automatically at configure time via CMake FetchContent, pinned to a fixed<br>tag, so a plain cmake invocation is enough to fetch them.
Build:
cmake -S . -B build<br>cmake --build build -j
This produces sana_infer, bench_full_pipeline, and the unit-test<br>binaries, all under build/.
Get the model weights. sana_infer reads weights from a directory of<br>.gguf files (default ../weights relative to the build directory). Pre-converted files<br>are hosted at<br>doobluhc/sana-cpp-weights<br>— fetch them with plain curl, no Python required:
./download_weights.sh weights
Run inference:
cd build<br>./sana_infer --prompt "a house by the lake" --output out.png
Run ./sana_infer --help for the full option list (--negative-prompt,<br>--steps, --seed, --guidance, --weights-dir, --gemma-gguf, ...).
Python 3 with torch and diffusers is only needed if you also want to<br>run the PyTorch reference benchmarks below — not for any of the steps<br>above.
What's here
Gemma-2 text encoder (src/gemma_encoder.*) — runs on the vendored<br>llama.cpp/ggml inference engine.
Transformer denoiser (src/transformer*.*) and DPM-Solver++ scheduler<br>(src/scheduler.*) — the diffusion denoising loop.
VAE decoder (src/vae*.*) — turns final latents into an image.
sana_infer (src/infer_main.cpp) — the CLI that chains all three<br>stages end to end and writes a PNG/PPM.
bench_full_pipeline (tests/bench_full_pipeline.cpp), paired with<br>tools/bench_reference_full_pipeline.py, so the whole pipeline's inference<br>speed can be timed and compared directly against the PyTorch reference.
Benchmarking: Python vs C++
The whole pipeline (encode + denoise + decode) can be timed on both<br>implementations, on the same inputs, and compared directly:
Stage<br>C++<br>Python reference
Full pipeline (encode + denoise + decode)<br>./bench_full_pipeline<br>python3 tools/bench_reference_full_pipeline.py
Tests
ctest --test-dir build --output-on-failure
Runs the self-contained unit tests (tensor ops, transformer block, scheduler,<br>Gemma-2 encoder) — none of them need model weights or any external fixture<br>data.
Project layout
src/ C++ library + sana_infer CLI<br>tests/ self-contained unit tests + the full-pipeline benchmark<br>tools/ the PyTorch full-pipeline benchmark<br>download_weights.sh fetches pre-converted .gguf weights from Hugging Face
License
MIT — see LICENSE.
This covers the code in this repo only. The Sana model weights themselves<br>are published separately by NVIDIA/Efficient-Large-Model under their own<br>terms — check<br>the upstream model's license<br>before using them.
About<br>SANA (text-to-image model) implemented in CPP<br>Resources<br>Readme<br>MIT license<br>Activity<br>Stars<br>0 stars<br>Watchers<br>0 watching<br>Forks<br>0 forks<br>Report repository
Releases
Packages
Contributors
Languages
You can’t perform that action at this time.