Skip to content

Resync with upstream master-1050 and port the ggml patches - #52

Draft
danielhanchen wants to merge 72 commits into
masterfrom
resync/upstream-master-1050
Draft

danielhanchen wants to merge 72 commits into
masterfrom
resync/upstream-master-1050

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

This merges upstream master-1050-58bb3c1 into the fork and ports the carried ggml patches onto the new ggml submodule commit (135ce1e0). The current Studio pin, master-982-0518b34-uaba3a1c, is 68 upstream commits behind. Among them are leejet#2183 (the model manager reads free memory again before it gives up, also vendored on its own in #50) and leejet#2273 (faster MOSS normalization and staging).

Why now

MOSS-Image-SFT Q8_0 with Qwen3.5-9B Q8_0 through sd-server, 1024x1024, 25 steps. One Colab L4 job, both arms on the same card, with VRAM held down to 7.5 GiB free at load. Each cell ran twice, and repeats agree within 1.7 s.

Free VRAM during the render current pin (master-982-0518b34-uaba3a1c) this branch (7c062d2, patches applied)
7.5 GiB, nothing taken after load 95.5 s / 93.9 s (sampling 82.4 s / 80.9 s) 73.2 s / 73.2 s (sampling 59.9 s / 59.7 s)
2.0 GiB, VRAM taken after load 148.7 s / 150.4 s 87.4 s / 87.8 s (sampling 72.9 s / 72.9 s)

So this branch is about 1.3x faster on the normal path and about 1.7x faster under memory pressure. Both renders are correct images.

In a separate job, a plain upstream build of the same base (58bb3c1, no fork patches) next to this branch took 89.5 s vs 101.7 s with nothing taken, and 89.9 s vs 89.5 s at 2 GiB. Sampling took 76.1 s vs 68.2 s and 75.3 s vs 74.7 s, so the ported patches cost MOSS nothing. At 1.5 GiB free, the pin, plain upstream and this branch all fail the same way (the text encoder segment needs 1543 MB, 1534 MB is free). That case is a real shortfall, not something an engine update fixes. unslothai/unsloth#16815 makes Studio report it as out of memory.

Changes

  • 64fb9d4: merge of master-1050-58bb3c1. Conflicts were resolved keeping both sides (fork-only server and workflow pieces plus upstream's new code).
  • d4ed8d3: upstream moves ROPE_APPLY, SAGE_ATTN, SOL_ATTN and QUANTIZE_I8_CONVROT out of ggml and into stable-diffusion.cpp backend extensions, so several patches in scripts/unsloth/ggml-patches no longer applied:
    • 0002 (long sequence flash attention): reuses upstream's new 128x128 tile for head size 128 and keeps only the head size 64 instance.
    • 0003, 0004: context and op enum position only.
    • 0006 (cuDNN attention): the SAGE_ATTN half is dropped together with the op. cuDNN now serves FLASH_ATTN_EXT only.
    • 0007 (rope_apply PDL race fix): dropped together with the op. The extension kernel that replaces it launches without PDL.
    • 0010 (Metal ROPE_APPLY kernel): dropped. The op no longer exists and ggml's extension registry has no Metal hook, so Metal runs the unfused rope graph again.
    • 0001, 0005, 0008, 0009 and 0011 to 0013 apply unchanged.
  • 7c062d2: the prebuilt workflow now also fetches thirdparty/cutlass. Upstream's CUDA build includes cmake/cutlass.cmake, which stops at configure time without the CUTLASS headers. The source stamp only fetched ggml, so every CUDA leg would have failed. The step keeps only include/ and the license, which keeps the source tarball small.
  • 6f12cd9: the macOS arm64 leg moves from macos-14 to macos-15. GitHub retired the macos-14 image, so that leg was cancelled before it started (The configuration 'macos-14-arm64-us-default' is not supported). master has the same runner label. CMAKE_OSX_DEPLOYMENT_TARGET=14.0 stays, so the binaries still run on macOS 14.

Testing

  • Every patch applies on 135ce1e0. The CPU and CUDA builds of ggml (with test-backend-ops) and of sd-server succeed with the patches applied.
  • CUDA source build of this branch on Colab (sm_89, CUTLASS headers from the submodule): the MOSS renders in the table above.
  • CPU sd-cli render of MOSS-Image-SFT Q8_0 renders with the patches applied (18.2 s) and without them (66.8 s), image saved both times.

Not verified yet

  • Artifact-only prebuilt run of 7c062d2 (https://github.com/unslothai/stable-diffusion.cpp/actions/runs/42157974628): every leg built except macOS arm64. That covers Linux CPU, Vulkan, aarch64, CUDA 12 and CUDA 13; Windows CPU, Vulkan, CUDA 12 and CUDA 13; and macOS x86_64. The CUDA legs were cold builds (new ggml commit plus the CUTLASS kernels, no ccache hits) and took 1 h 18 min to about 2 h 50 min, inside the job limits. macOS arm64 was cancelled because its runner image is retired; https://github.com/unslothai/stable-diffusion.cpp/actions/runs/42178497743 rebuilds it with 6f12cd9.
  • MiniMax-H3 was not rendered on this tree.
  • Metal: because 0010 was dropped, MiniMax-H3 on Apple Silicon may be slower until the kernel is ported to the new extension path.
  • sm100: losing the cuDNN Sage path (0006) may cost MiniMax-H3 speed on Blackwell.

Please do not merge before the prebuilt run is green. Once it is merged and the nightly publishes, Studio's DEFAULT_TAG can move to the new tag, and #50 becomes redundant.

losewayy and others added 30 commits October 21, 2026 23:11
leejet and others added 21 commits November 1, 2026 22:08
Conflicts resolved keeping both sides:
- build.yml: ours (the mirror's customised upstream CI).
- compute_workspace: upstream now always allocates through the scheduler (gallocr path and
  needs_scheduler removed); the CPU BLAS backend, its thread count, residency accounting and
  scratch release are carried on top of that.
- ggml_extend_backend.cpp: upstream moved sd_backend_dev_buffer_from_host_ptr to ggml_compat.cpp;
  the CPU weight repack helpers and sd_backend_blas_init stay.
- ggml_runner.cpp: upstream's scheduler-only execute_segment (eval callback always set, pre-compute
  hook) plus the BLAS thread count; runner_end also drops the BLAS scratch.
- minimax_h3.hpp: upstream's project_qkv/attend/project_output, INT8-aware MLP scales and chunked
  native-GLU MLP, with the mirror's head-major fused attention, folded MLP and fused segment block
  as fast paths in front; the old segment helpers upstream deleted are dropped.
- minimax_h3_vae.hpp: upstream's native GLU (leejet#2250) for the decoder feed-forward.
- model_manager.cpp: both includes.
- diffusion_engine.cpp: P-H3-Image squeeze plus the temporal tiling retry bookkeeping.
- cmake/ggml.cmake: upstream now resolves the ggml private include dir only for
  SD_USE_UPSTREAM_GGML, which left the fused-op probe reading a non-existent ggml.h and
  silently building MiniMax-H3 unfused; the probe now finds ggml.h from the ggml target.
…submodule)

Upstream master-1050 moves the ggml submodule from dc99877 to 135ce1e (57 commits), which
moves ROPE_APPLY, SAGE_ATTN, SOL_ATTN and QUANTIZE_I8_CONVROT out of ggml into
stable-diffusion.cpp backend extensions. 0002-0004, 0006 and 0007 no longer applied and were
ported by cherry-picking each patch onto the new submodule commit:

- 0002: upstream 0d84d52a added its own 128x128 wide tile for head size 128 (config row,
  instance file, shared-memory helper); the port reuses it, keeps only the head size 64
  instance, and gives the helper an nstages override for the long-sequence variant.
- 0003: context only.
- 0004: the fused ops now follow GLU directly in the op enum (GGML_OP_COUNT 104).
- 0006: the SAGE_ATTN half (sage-attn.cu hook, GGML_CUDA_CUDNN_SAGE) is dropped with the op;
  cuDNN now serves FLASH_ATTN_EXT only.
- 0007: the rope_apply PDL race fix is dropped with the op; the extension kernel that
  replaces it launches without PDL.

0010 (Metal ROPE_APPLY kernel) is dropped: GGML_OP_ROPE_APPLY no longer exists in ggml and
ggml's extension registry has no Metal hook, so Metal runs the unfused rope graph again.
0001, 0005, 0008, 0009 and 0011-0013 apply unchanged.
Upstream's CUDA build includes cmake/cutlass.cmake, which stops at configure time when
thirdparty/cutlass is empty. The source stamp only fetched ggml, so every CUDA leg would fail.
Fetch the submodule shallowly and keep only include/ and the license in the tarball.
GitHub retired the macos-14 image, so the Darwin-macOS-arm64 leg is cancelled before it starts
("The configuration 'macos-14-arm64-us-default' is not supported"). macos-15 is Apple Silicon too,
and CMAKE_OSX_DEPLOYMENT_TARGET=14.0 keeps the binaries running on macOS 14.

This branch is being deployed

1 queued deployment
release-signing — 6f12cd92 Deployed Nov 6, 2026 by danielhanchen via win-cpu-x64 #153
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.