Commit f977add for stable-diffusion.cpp

commit f977addf06c1c18f3490bf5ed9b25d2196cd956c
Author: Wagner Bruna <wbruna@users.noreply.github.com>
Date:   Mon Nov 9 11:10:12 2026 -0300

    fix: disable batch_cfg for Metal when building with upstream ggml (#2311)

diff --git a/src/pipeline/diffusion_engine.cpp b/src/pipeline/diffusion_engine.cpp
index 1ec292c..e8afbd1 100644
--- a/src/pipeline/diffusion_engine.cpp
+++ b/src/pipeline/diffusion_engine.cpp
@@ -2440,6 +2440,15 @@ sd::Tensor<float> StableDiffusionGGML::sample(const std::shared_ptr<DiffusionMod
                                                         : sampling_init_latent;
     sd::Tensor<float> denoised                    = x_t;

+#ifdef SD_USE_UPSTREAM_GGML
+    // workaround for sd.cpp #2149
+    const auto diffusion_backends = backend_manager.runtime_backends(SDBackendModule::DIFFUSION);
+    const bool batch_cfg_backend_ok = std::none_of(diffusion_backends.begin(), diffusion_backends.end(),
+            [](ggml_backend_t backend) { return sd_backend_is(backend, "MTL"); });
+#else
+    const bool batch_cfg_backend_ok = true;
+#endif
+
     auto denoise = [&](const sd::Tensor<float>& x, float sigma, int step) -> sd::guidance::GuiderOutput {
         if (get_cancel_flag() == SD_CANCEL_ALL) {
             LOG_VERBOSE("cancelling generation");
@@ -2762,6 +2771,7 @@ sd::Tensor<float> StableDiffusionGGML::sample(const std::shared_ptr<DiffusionMod
         }

         const bool batch_cfg_ok = config_->params.batched_cfg &&
+                                  batch_cfg_backend_ok &&
                                   sd_version_is_unet(version) &&
                                   !uncond.empty() &&
                                   img_uncond.empty() &&