Commit b43af40 for stable-diffusion.cpp
commit b43af40461cc64c89cac3b621019f8914f50dd9c
Author: DrMkdaddy <37319157+DrMkdaddy@users.noreply.github.com>
Date: Sun Nov 8 05:37:06 2026 -0800
fix: use patch token count for the Flux scheduler (#2293)
diff --git a/src/model/diffusion/flux.hpp b/src/model/diffusion/flux.hpp
index 843e70b..f8f8305 100644
--- a/src/model/diffusion/flux.hpp
+++ b/src/model/diffusion/flux.hpp
@@ -1437,6 +1437,10 @@ namespace Flux {
return "flux";
}
+ int get_patch_size() const override {
+ return config.patch_size;
+ }
+
void get_param_tensors(std::map<std::string, ggml_tensor*>& tensors, const std::string& prefix) override {
flux.get_param_tensors(tensors, prefix);
}
diff --git a/src/model/diffusion/model.hpp b/src/model/diffusion/model.hpp
index 4ff91c4..f25ca7b 100644
--- a/src/model/diffusion/model.hpp
+++ b/src/model/diffusion/model.hpp
@@ -237,6 +237,10 @@ public:
virtual sd::Tensor<float> compute(int n_threads,
const DiffusionParams& diffusion_params) = 0;
+ virtual int get_patch_size() const {
+ return 1;
+ }
+
void get_param_tensors(std::map<std::string, ggml_tensor*>& tensors) {
get_param_tensors(tensors, prefix);
}
diff --git a/src/pipeline/diffusion_engine.cpp b/src/pipeline/diffusion_engine.cpp
index a8eed8e..c820a8d 100644
--- a/src/pipeline/diffusion_engine.cpp
+++ b/src/pipeline/diffusion_engine.cpp
@@ -2930,7 +2930,12 @@ int StableDiffusionGGML::get_image_channels() const {
int StableDiffusionGGML::get_image_seq_len(int h, int w) {
int vae_scale_factor = get_vae_scale_factor();
- return (h / vae_scale_factor) * (w / vae_scale_factor);
+ int patch_size = diffusion_model != nullptr ? diffusion_model->get_patch_size() : 1;
+ int latent_h = h / vae_scale_factor;
+ int latent_w = w / vae_scale_factor;
+ int tokens_h = (latent_h + patch_size - 1) / patch_size;
+ int tokens_w = (latent_w + patch_size - 1) / patch_size;
+ return tokens_h * tokens_w;
}
sd::Tensor<float> StableDiffusionGGML::generate_init_latent(int width,