Skip to content

Studio: MOSS-Image negative-branch layer skip follows the reference workflows per checkpoint - #16127

Merged
danielhanchen merged 5 commits into
mainfrom
studio-moss-skip-layer-reference
Oct 30, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
studio-moss-skip-layer-reference

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Studio skips transformer block 22 in the MOSS-Image negative (unconditional) branch on every step, for both checkpoints. The reference workflows do this per checkpoint instead:

checkpoint reference workflow Studio before Studio after
MOSS-Image-SFT negative-branch skip switched off block 22, every step no skip
MOSS-Image-Base block 22 for sigma-percent 0 to 0.5, then off block 22, every step block 22 while sigma >= sigma(0.5), then off

It is the same mechanism Studio already has: the reference node only changes the negative pass (it drops block 22 there), it adds no third forward. Its window is in sigma-percent of the shift-5 schedule, so the skip is active while sigma >= 5 * 0.5 / (1 + 4 * 0.5) = 0.833. At 25 steps that is steps 0 to 12 (13 of 25) on both Studio schedules (sgm_uniform and training_grid), the same 13 steps the reference sampler gets.

The official model cards recommend block 22 on every step at 50 steps / CFG 3. The reference workflows instead use 25 steps / CFG 2.5 with the per-checkpoint skip above. Studio follows the reference workflows, so this goes with the 25 / 2.5 defaults change.

Changes

  • MOSSImagePipeline.__call__: new uncond_skip_start / uncond_skip_end (sigma-percent, as above). When uncond_skip_layers is not passed, the pipeline uses the checkpoint the loader recorded (reference_uncond_skip). A pipeline built without the loader keeps the official default (block 22 on every step), so the bit-for-bit parity tests against the official pipeline are unchanged.
  • load_moss_image_pipeline(..., checkpoint=...) records the upstream repo id. diffusion.py passes base from both load paths. Any id that spells MOSS-Image-Base (separators ignored, so mirrors and hub cache folders match too) gets the Base policy. Everything else gets the SFT policy.
  • Kill switch: UNSLOTH_MOSS_REFERENCE_SKIP=0 restores block 22 on every step for both checkpoints. It is read on each render.
  • Explicit uncond_skip_layers / uncond_skip_end arguments still take precedence.

Quality and speed (A100 40GB, real weights, same VM for every arm)

Setup: 1024x1024, 25 steps, CFG 2.5, empty negative, 4 prompts x 2 seeds. Arms are interleaved per (prompt, seed). "old" is the kill switch and "new" is this PR. I counted the skipped negative-branch steps on every render: SFT old 25 / new 0, Base old 25 / new 13. Two reference recipes per image:

  • official: model card recipe, 50 steps, CFG 3, block 22 always, training-grid sigmas
  • new50: this PR's guidance at 50 steps, CFG 2.5
SFT old SFT new Base old Base new
s/image (median of 8) 19.05 19.32 (+1.4%) 19.09 19.21 (+0.6%)
LPIPS vs official 0.189 0.223 0.202 0.207
LPIPS vs new50 0.184 0.133 0.154 0.144
LPIPS old vs new 0.136 0.025
CLIP-L prompt score 32.06 32.44 30.67 30.86

Peak VRAM is 27.3 GiB in every arm.

How to read this:

  • LPIPS only measures distance to a recipe. Each arm sits closer to the reference that uses its own guidance, so LPIPS by itself does not show which arm is better.
  • Base: the two arms differ only in the last 12 low-noise steps. LPIPS old vs new is 0.025 and the contact sheet looks the same, so this is a tie.
  • SFT: the change is visible (LPIPS 0.136 old vs new). In the contact sheet, new matches or beats old on all 8 images. The clearest case is the marquee prompt (seed 1234): old renders the sign as "MO SS" and new renders "MOSS". CLIP is 0.4 higher, but that gap is small and inside what 8 images can resolve, so overall it is a tie or slightly better.
  • Speed: one fewer skipped block per negative pass costs 1.4% on SFT and 0.6% on Base.

Tests

  • tests/test_diffusion_moss_image.py: 18 new cases, all of which fail on main:
    • the per-checkpoint policy and the id spellings it accepts
    • the kill switch
    • the sigma-percent formula
    • the Base window is exactly 13 of 25 steps on both schedules
    • SFT never skips, and a pipeline built without the loader keeps block 22 on every step
    • explicit arguments take precedence
    • both load paths pass the checkpoint
  • tests/test_diffusion_moss_image_quant.py: the loader stub now keeps attributes and checks the recorded checkpoint.
  • 60 / 60 MOSS pipeline tests pass, 934 pass across the diffusion family / defaults / CUDA graph / CFG suites, and 700 pass across the MOSS quant / fused / LoRA / autoopt suites (CPU).

Not covered

  • The GGUF path (stable-diffusion.cpp) hardcodes block 22 for MOSS in its own sampler and is unchanged here. It needs a separate change in the sd.cpp fork.
  • The reference workflows also use the er_sde sampler, the simple schedule and a default negative prompt. Studio keeps Euler, sgm_uniform and an empty negative, so the renders are not pixel-comparable to the reference workflow output.
  • No CUDA graph or compiled-path render was measured. Base now has a negative-branch call with and without the skip in one render. That is one extra graph key, within the per-module limit.

…orkflows per checkpoint

SFT renders without the block-22 skip in the negative branch; Base skips block 22
while sigma is in the first half of the shifted schedule (sigma-percent 0 to 0.5).
UNSLOTH_MOSS_REFERENCE_SKIP=0 restores block 22 on every step for both. A pipeline
built without the loader keeps the official default, so reference parity holds.
@danielhanchen danielhanchen self-assigned this Oct 30, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T14:23:52.984531Z 58b1f50 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 58b1f5015e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

Heads up on the red checks here:

@danielhanchen
danielhanchen merged commit b1e0b00 into main Oct 30, 2026
17 of 23 checks passed
@danielhanchen
danielhanchen deleted the studio-moss-skip-layer-reference branch October 30, 2026 16:45
meefs pushed a commit to meefs/unsloth that referenced this pull request Oct 31, 2026
…ch skip (unslothai#16255)

## Summary

unslothai#16127 made the diffusers MOSS-Image path skip transformer block 22 on
the negative pass per checkpoint, as the reference workflows do: never
for MOSS-Image-SFT, and only while sigma-percent is in [0, 0.5] for
MOSS-Image-Base. The GGUF path runs stable-diffusion.cpp, which still
skips block 22 on every step for both checkpoints.

unslothai/stable-diffusion.cpp#40 added sample args that express the
per-checkpoint rule. This sends them from Studio and pins the prebuilt
that reads them.

The pinned release, `master-982-0518b34-uaba3a1c`, is published on
unslothai/stable-diffusion.cpp; the 7 asset names
`test_sd_cpp_vulkan_cpu_torch.py` lists are all in it.

## Change

- `sd_cpp_args.moss_uncond_skip_sample_args`: `moss_uncond_skip=false`
for SFT, `moss_uncond_skip_start=0,moss_uncond_skip_end=0.5` for Base.
Base is detected from the repo id, folder or GGUF filename (separators
folded). `UNSLOTH_MOSS_REFERENCE_SKIP=0` sends nothing, which is the
binary's every-step default.
- `sd_cpp_backend`: MOSS-Image requests carry it, as
`sample_params.extra_sample_args` on the server path and
`--extra-sample-args` on the CLI path. Other families send nothing.
- `install_sd_cpp_prebuilt.DEFAULT_TAG`: `master-982-0518b34-ud331c66`
-> `master-982-0518b34-uaba3a1c`. Same upstream base (master-982); the
new build adds only unslothai#40. The tests that name the pin are updated.

A build without the keys ignores them, so an older install keeps today's
behaviour until it updates.

## Results

`MOSS-Image-Base-Q4_K_M.gguf`, Linux x86_64 CPU, 256x256, 25 steps,
`euler`, the release's own `sd-cli`:

| case | negative passes that skip block 22 |
|---|---|
| new pin, no keys | 25 of 25; PNG byte-identical to the current pin |
| new pin, SFT (`moss_uncond_skip=false`) | 0 of 25 |
| new pin, Base (window `0..0.5`) | 13 of 25 (steps 1-13) |
| current pin given the keys | keys ignored; identical to the same
binary without them |

The server path, driven through this branch's `build_img_gen_request`
and `SdCppServer`, gives the same counts: 25, 0 and 13 of 25.

## Tests

- `test_sd_cpp_moss_uncond_skip.py` (new): Base / SFT detection across
repo ids, folders and GGUF names, the env kill switch, the server
request field, the CLI flag, and that other families send nothing.
- `test_sd_cpp_moss_uncond_skip.py`, `test_sd_cpp_args.py`,
`test_sd_cpp_install_verify.py`, `test_sd_cpp_vulkan_cpu_torch.py`,
`test_diffusion_more_families.py`: 310 passed.

## Not proven

- Only the Linux x86_64 CPU bundle was run. The CUDA, Vulkan, Metal,
Windows and aarch64 bundles were built by the release job but not
rendered.
- The MOSS-Image-SFT GGUF was not rendered on the GGUF path; its 0-of-25
count comes from the Base GGUF given the SFT keys.
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.

1 participant