Repository navigation
feat: update stable-diffusion.cpp to master-982-0518b34 - #27
Merged
Merged
Conversation
Upstream 982 enables batched CFG by default, and ggml-metal GROUP_NORM writes only the first batch item (leejet/stable-diffusion.cpp#2149), so a batched step returns a wrong image as success. sd_dart_new_sd_ctx loads a copy with batched_cfg off when the library is built with Metal. Smoke-tests conversion under a non-ASCII UTF-8 path on every target, and records the Metal controls, local suite and remaining gates.
6 tasks
A null flash_attn_mode or conv_direct_mode with its legacy flag false selects upstream's auto probes, which change output and are not seed-reproducible on Metal. Record the explicit consumer mapping that keeps v0.2.0-4 behavior. build.py now fails after configure when stable-diffusion lacks the SD_DART_METAL or SD_DART_GPU_BACKEND value its target needs, and the CI build jobs run the runtime API test against the built runtime instead of skipping it.
leehack
marked this pull request as ready for review
October 22, 2026 14:36
This was referenced Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves stable-diffusion.cpp to
master-982-0518b34(ggmldc998771) and keeps Metal builds correct under upstream's newbatched_cfg=truedefault. Refs #20. Not a release; full record indocs/upstream_982_qualification.md.Consumer ABI delta
sizeof(sd_ctx_params_t)batched_cfg(bool)trueflash_attn_mode,conv_direct_mode(const char*)sd_ctx_params_tmemberssd_img_gen_params_t/sd_vid_gen_params_t/sd_sample_params_tconvert_with_componentsconst sd_lora_t* loras, int lora_countsd_get_preview_info,sd_ctx_supports_ref_image_conditioningsd_ctx_params_initwrites past an old 320-byte allocation: llamadart must regenerate bindings and mapbatched_cfgand both mode strings explicitly before loading this runtime.Attention/convolution modes. A null mode honors a legacy flag only when it is
true. With the flagsfalse(the init default and what llamadart writes today) upstream runs its auto probes: on CPU, auto enables flash attention, so the image changes from v0.2.0-4 (4ca7bc91→bf06aed2). On Metal, auto is not seed-reproducible: flash attention is picked by a timing probe at load (the auditor saw it on in 2 of 10 loads). To keep v0.2.0-4 behavior llamadart must always pass both modes:flash_attn_modeflash_attn"off,te=on,clip_vision=on,vae=on,diffusion=on"diffusion_flash_attn"off,diffusion=on""off"conv_direct_mode="off"+",diffusion=on,control_net=on"fordiffusion_conv_direct+",vae=on"forvae_conv_direct. Verified: candidate CPU"off"= v0.2.0-4 flags-false image and"off,diffusion=on"= v0.2.0-4diffusion_flash_attnimage. On MTL0, three loads of each explicit mode gave identical images and logged no auto probe.Metal batched CFG (leejet#2149)
ggml-metal GROUP_NORM still writes only batch item 0, so batched CFG returns a wrong image as success.
sd_dart_new_sd_ctxnow loads a copy withbatched_cfg=falsewhen built with Metal (SD_DART_METALfromSD_METAL); other builds pass the flag through. Rawnew_sd_ctxis unchanged.[8,8,64,2], sentinel 123456sd_dart_new_sd_ctx,batched_cfg=true, MTL0batched-cfgstand-in,-DSD_DART_METAL=1Carry inventory
No carry retired. Two carries the pin lacks: Metal unbatched CFG (wrapper, this PR) and
patches/pickle_line_span.patchfor #23 (merged in #26 and brought in by merging main). The patch applies to0518b34(pickle_io.cppis byte-identical to the baseline) andtest_pickle_spanpasses. Kept, with reasons in the doc: progress ring, log/error ring and spin abandonment, context registry and guarded calls, Apple hidden__cxa_atexit, bounded teardown waits, Linux owned-static retention and GCC 13 floor, static-registry device queries, GPU status mapping, free-memory clamp (ggml65c60b2overlaps but is unqualified on real Vulkan), Metal fail-loud (#21), Windows short build path +EP_PREFIX, export allowlist, MSVC generator, Android 16 KiB alignment and CPU-only, CPU desktop payload, build policy, Apple minimum OS and privacy manifest. The submodule itself stays unpatched.Upstream fixes adopted:
8c442fb(#2144) UTF-8 model paths on Windows, now smoke-tested on every smoke target (converts between files in a non-ASCII directory);60423ab(#2124) /b7a74e6(#2119) memory reclamation, unqualified (no Vulkan iGPU).Evidence (macOS arm64, guarded build with #26's patch, dylib
e4e1a2be, pinned Dart 3.47.1 SDK)validate_artifacts.py macos-arm64build.pywrapper-definitions check (new)SD_DART_METAL=1; mutation (definition removed from CMakeLists) stops the build after configuresmoke_test.py macos-arm64 --expect-device MTLunittest discover -s tests(SD_REQUIRE_DART/RUNTIME/METAL_GENERATION, 3 runs)test_exit_teardown_runtime.py, ASan, Metal generation7f798ea8); raw batched still defectiveThe real-model rows ran before the merge; the merged build differs only in the patched legacy pickle reader.
Evidence logs and probes:
llamadart-evidence/sd-982-pr/on the qualifying Mac (not committed).CI: every build job now fails if
stable-diffusionwas configured without theSD_DART_METAL/SD_DART_GPU_BACKENDvalue its target needs. The macOS and Linux smoke build jobs runtest_runtime_api.pyagainst the built runtime withSD_REQUIRE_RUNTIME=1, so a missing runtime fails instead of skipping.Coordination: SD PR#26 landed first (
aa1f6d6). This branch merges main (merge commit0a4d0ca), and the doc and README list both carries.Unqualified
Linux cooperative native/Dart teardown (CI covers CPU/lavapipe only), Windows (CI smoke only), real Vulkan memory/convolution/batched CFG, FP8 CPU, iOS devices and full XCFramework/signing audit, Android devices. CPU parity is not GPU evidence. SD#23 (legacy pickle >2 GiB) is out of scope.
High-risk QA
Native runtime and exit-teardown change: needs an exact-head independent review before ready. Draft until then.