Skip to content

Optimize Krea2 Vulkan (target: Strix Halo) - #1891

Open
pwilkin wants to merge 2 commits into
leejet:masterfrom
pwilkin:optimize-krea-vulkan
Open

pwilkin wants to merge 2 commits into
leejet:masterfrom
pwilkin:optimize-krea-vulkan

Conversation

@pwilkin

@pwilkin pwilkin commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

People in the Lemonade community have been complaining that sd.cpp is very slow compared to native PyTorch inference and a new backend (TheNoise) has been created to obtain fast generation, so I decided to try to match parity.

Related Issue / Discussion

Lots of kernel (see linked GGML fork/PR) and Krea changes that in total bring the generation time for a 1024x768 image in 8 steps on Krea2 Turbo Q8_0 on a Strix Halo from 77 seconds to 29 seconds.

Additional Information

Images are not bit-identical, but coherence/detail has been preserved at a similar level.

Note: this is probably NOT a one-time effort, I chose Krea2 first because that was chosen for TheNoise as one of the first supported models, but I want to do a sweep across a couple of the new supported image models to bring performance up to par and hopefully people with different hardware can use this to tune optimizations for their own hardware as well.

Checklist

Use native multi-axis RoPE and fusion-friendly graph layouts for Krea2, retain reusable Vulkan graph allocations, streamline model uploads, and route the single-frame VAE through the optimized 2D paths. Pin the companion ggml-vulkan implementation that provides the tuned cooperative kernels and fused dispatches.
Default server-side PNG encoding to the measured level 4 setting, expose a validated command-line override, and reserve the exact base64 output capacity. File and CLI encoding behavior outside the server remains unchanged.
@stduhpf

stduhpf commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

That's way too many barely related changes for a single PR. If you want these changes to get approved, It would be better to split this into multiple separate PRs that can be reviewed independantly, as per the contribution guidelines. You could use PR stacking maybe.

@pwilkin

pwilkin commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@stduhpf I've already opened three split PRs for the GGML changes in the llama.cpp repo, I don't think I can reasonably split the sd.cpp changes themselves.

@stduhpf

stduhpf commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

I mean some changes to sd.cpp don't seem related to the rest, like the PNG compression level stuff for example, it doesn't look like it absolutely needs to be bundled with the ggml graph optimizations

@pwilkin

pwilkin commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Yeah, fair enough. I can cut out the less obvious ones.

rodrigomatta added a commit to romara-labs/stable-diffusion.cpp that referenced this pull request Oct 6, 2026
Piotr Wilkin's PR adapted to the post-split tree (upstream leejet#1945 split
ggml_extend.hpp; the pipeline refactor moved StableDiffusionGGML into
src/pipeline/):

- krea2: native MROPE path (gen_krea2_rope_data + ggml_rope_multi)
  replaces the precomputed cos/sin pe matrix; swiglu_split in the MLP
- param transforms: load-time +1 fold of RMSNorm scales, keyed by
  ModelComponent instead of the removed desc string; registered from
  build_diffusion_runners; writable mmap also enabled for krea2
- ggml_ext_attention_ext: keep strided v cast on Vulkan
- model_loader: per-backend-buffer mutexes for parallel tensor upload
- server: --png-compression-level option, base64 reserve
- runner context: graph + param_transform_registered fields
  (ctx->gf from the PR maps to the existing ctx->graph)

ggml submodule kept at 89c4413 (upstream master, hip INT8 tensor
matmul/convrot) instead of the PR's 76f89d6 branch: the two set_prec
APIs the PR needs already exist there and the PR's extra commits are
Vulkan-RDNA3 kernels, irrelevant on HIP. The PR's compute-buffer
retention flag is obsolete: the split runner already keeps the
workspace across steps and frees it at runner_end.
@Enlightnd

Copy link
Copy Markdown

Would ya'll mind unclogging this PR?
I use Krea 2 extensively and from my own testing with various platforms and hardware, we really have a lot of performance to win for this model. Heck, with just general development progress I've seen it go on A770 from 5s/it as low as 1.8s/it (now stuck around 2.9s/it) over time and testing with some other platforms (like direct torch and the like) I got it as fast as 1.4it/s for the same generation dimensions. Similarly, with a 9070XT, it's fluxed from 1.2s/it to currently around 1.4it/s and I've seen it near 1.7it's in the past on that card. And on the B60, it swaps places with the A770 depending on the pull of the day too. Sometimes A770 pulling 2.9s/it and B60 at 2.3s/it, to then a week later have the B60 at 4s/it and the A770 still at the same speed.

There's a lot of performance to gain on various hardware, with some focus. And this model is great for 12-16GB setups as it's 13B size makes it extremely forgiving to Q4 quanting of the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants