Skip to content

[staging] PR 11044 merged onto current main — CI probe - #36

Closed
Lyxot wants to merge 10 commits into
staging-base-11044from
staging-11044
Closed

Lyxot wants to merge 10 commits into
staging-base-11044from
staging-11044

Conversation

@Lyxot

@Lyxot Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Staging only — do not merge. Opened to get a CI signal on the post-merge state of unslothai#11044, and closed once the run reports.

staging-base-11044 is a snapshot of upstream main at the time this was opened; staging-11044 is unslothai#11044's head merged into it. So the diff here is exactly unslothai#11044's change, and CI exercises the merged result rather than the branch's stale base (it was 36 commits behind).

Local result on the same merged tree: 274 passed, 2 failed, both reproducing unchanged at the merge base on macOS and unrelated to this change (test_diffusion_dataset_upload_rejects_case_insensitive_stem_clash, test_route_start_refuses_a_dit_family_without_a_gpu_before_freeing).

NilayYadav and others added 10 commits September 16, 2026 00:20
…utdown docs

The shutdown save budget is capped by the training stop watchdog's own absolute timeout, UNSLOTH_STUDIO_TRAINING_STOP_TIMEOUT_S (default 600). Raising UNSLOTH_STUDIO_SHUTDOWN_STOP_TIMEOUT_S past it only waits longer for a worker that is force-terminated anyway, so a 700 second save is still lost at 600. Document the ceiling next to the budget and forward the watchdog variable through docker/run.sh, whose environment allowlist had dropped it, so the two can be raised together.

A host shutdown was claimed to be covered as well. It is not: the daemon stops every container under its own --shutdown-timeout (15 seconds by default), not the per-container stop timeout.

Tests: replace the source-text assertions in the Docker stop-grace tests with behavioural ones. The launcher's derived wait is read back by sourcing studio_launch.sh under an EXIT trap in check-only mode, and run.sh's environment forwarding is asserted against the stubbed docker argv in both directions. The SIGTERM handler installation is now checked on the parsed tree, so commenting out either call site fails; before, commenting out both left it green. The two shutdown-wait tests now assert the terminal condition each one names rather than only an upper time bound. Drops the ordering test that compared substring positions inside run.py: the same ordering is asserted behaviourally by test_graceful_shutdown_saves_training.
stop_for_shutdown returned as soon as the worker was gone, but the pump writes the run's terminal row afterwards and _complete_seen is set before that write lands. force_terminate joins the pump for 8 seconds, while the finalize is a metrics flush plus up to three finish_run attempts on connections with a 5 second busy timeout, so a contended SQLite can outlast it. The row is then left running, and the next startup's orphan sweep rewrites it to an error; the checkpoint and its output_dir survive, the stopped status and the final metrics do not.

The success paths now go through _await_run_record, which waits out the pump inside the remaining budget. Only a worker that has exited is waited on, because the pump keeps looping while one is alive; a run whose worker lingers past its save still falls back to the join, and the docstring records why closing that too belongs with terminal-state handling rather than here.
`_image_and_cmd` in the ROCm run.sh tests walks the `docker run` argv and skips two tokens for each option it knows carries a value, one for anything else starting with a dash. Adding `--stop-timeout` to run.sh left the flag in the first group by behaviour but the second by declaration, so the walk stopped on its value and reported `150` as the image name, failing five TestRunShRocm cases.
@Lyxot

Lyxot commented Sep 16, 2026

Copy link
Copy Markdown
Owner Author

CI reported: 71 passed / 1 failed, and that one failure (the pwsh shared-runner check) also fails on the control run of unmodified main. Staging done; closing.

@Lyxot Lyxot closed this Sep 16, 2026
@Lyxot
Lyxot deleted the staging-11044 branch September 16, 2026 10:02
Lyxot pushed a commit that referenced this pull request Nov 16, 2026
…t, the CPU-kept n-gram table makes the map look like two devices (unslothai#15633)

<img
src="https://raw.githubusercontent.com/LeoBorcherding/unsloth/3e9bad0671b803245f8bea0d6010cf0cb09d9537/block-swap-thick/unsloth-15633.png"
width="900">

Line numbers are at main `a595688`. Companions: unslothai#15632 (FP8 n-gram table
scale), unslothai/unsloth-zoo#2268 (table kept out of Block Swap's slot
pool). **Merge unslothai/unsloth-zoo#2268 first:** without it, the table
Block Swap now engages on lands in the GPU slot pool, which turns
Count's clean refusal into an out-of-memory error.

**What's broken**

Load `unsloth/Qwen3.8-Flash-Next-FP8` (transformers `qwen4_exp`) with
`offload_layers` set, either as a Count or as Auto. Block Swap never
turns on, so the 172.8 GiB checkpoint goes straight at the GPU.

The order is the problem.
[`vision.py:3913`](https://github.com/unslothai/unsloth/blob/a5956882f64caa31e49fbe6bd7c5e12c71823cc0/unsloth/models/vision.py#L3913)
runs `exclude_no_placement_params` first, which rewrites `{"": 0}` into
`{"": 0, <ngram_embedding>: "cpu"}`. That keeps the model's 48.9 GiB
n-gram table off the GPU. Every Block Swap decision after that sees two
devices:

- **Auto.** `resolve_auto_block_swap` only plans a bare `{"": N}`. It
logs "loads every layer onto the GPU", and the load runs out of GPU
memory. Measured on a Colab G4: RTX PRO 6000, 95 GiB VRAM, 177 GiB host
RAM.
- **Count.** The load doesn't refuse; it runs out of GPU memory instead.
Measured on the same G4 with core main + unslothai#15159 + unslothai#15632 (so only this
PR is missing), transformers 5.22.1, Count 32: transformers tries to put
the n-gram table on the card while concatenating its shards ("Tried to
allocate 47.69 GiB ... 41.67 GiB is free") and reports it as a
`CONVERSION` failure on `ngram_embedding.weight`. An earlier version of
this body called this a refusal ("needs every layer on one GPU") from a
code read; the run shows the load gets past that check.

**Fix**

Call `exclude_no_placement_params` after the Block Swap decisions, right
after the load collapses to the one-card map. The Block Swap checks see
`{"": N}`, and the table still lands on CPU. Nothing changes for models
without `_no_placement_params`.

`tests/test_block_swap_no_placement_order.py` pins the order. It's red
on main and green here.

**What it unlocks**

With this PR, unslothai#15632 and unslothai/unsloth-zoo#2268, Flash-Next trains
on one 95 GiB GPU. That run used Count 32 and an 8-bit paged AdamW: 10
steps, loss 1.19 to 0.75, 6.9 s/step, 82.8 GiB VRAM peak. The chart
shows where each run stopped before each fix:

<img
src="https://raw.githubusercontent.com/LeoBorcherding/unsloth/62007dc8f4a7f5db167b5711a83b406ad063e5c4/block-swap-flash-next/flash-next-stages.png"
width="900">

**Known gap: Auto now engages and can overrun host RAM**

Once this fix lets Auto plan, it plans for GPU memory only. On the G4 it
put 42 of 48 layers on the host, and with the 48.9 GiB table also there,
the cgroup killed it at about 170 GiB. Fixed Counts 24 to 34 peaked at
149 to 157 GiB. The host-RAM guard in unslothai/unsloth-zoo#1619 would
refuse that Auto plan up front.

<img
src="https://raw.githubusercontent.com/LeoBorcherding/unsloth/62007dc8f4a7f5db167b5711a83b406ad063e5c4/block-swap-flash-next/flash-next-host-ram.png"
width="900">

**Tested**

| Machine | What ran | Result |
|---|---|---|
| Colab G4, transformers 5.20.2, main + zoo unslothai#2268 (then fork #36) | Auto
| OOM at load, Block Swap never engaged |
| Colab G4, transformers 5.21.0, this PR + zoo unslothai#2268 (then fork #36) +
unslothai#15632 | Counts 24, 28, 32, 34, then Count 32 with paged AdamW | Block
Swap engages on every run; Count 32 + paged AdamW trains |
| Mac, CPU | `pytest tests/test_block_swap_no_placement_order.py` | 2
pass |
| Colab G4, transformers 5.22.1, core main + unslothai#15159 + unslothai#15632, zoo with
every open Block Swap PR | Count 32, Auto | without this PR: Count runs
the GPU out converting the table (47.69 GiB asked), Auto loads every
layer and OOMs |
| same, plus this PR (core `c730ae13`) | Count 32 + paged AdamW, Auto |
Count 32 trains 10 steps, loss 1.19 to 0.76, 6.8 s/step, 82.8 GiB VRAM;
Auto refused up front by the host-RAM guard (199.8 GiB asked, 142.5 GiB
free) |
| Colab T4, same stacks | `tests/test_block_swap_no_placement_order.py`
with the unslothai#15159 and unslothai#15632 tests | 18 failed against main, 19 passed on
the stack |

---------

Co-authored-by: Daniel Han <[email protected]>
Lyxot pushed a commit that referenced this pull request Nov 16, 2026
…nslothai#17459)

## Summary

Moves Studio's stable-diffusion.cpp prebuilt from
`master-982-0518b34-uba6ac30` to `master-982-0518b34-ueb0e729`, the
release built from fork master `eb0e729`. That is 36 fork commits on top
of the current pin. The tag keeps the `master-982` prefix because the
fork's release naming still counts from its last upstream release tag.

What the new build brings:

- Upstream resync to `master-1056` (unslothai/stable-diffusion.cpp#54):
packed INT4 convrot, MiniMax-H3 QKV chunking, RelayVSR, SDXL ControlNet
Union. Also Cosmos3-Nano-Sim-Transfer video-to-video (#53).
- x86 CPU: llamafile tinyBLAS GEMM for Q8_0 (#42), F16 / BF16 (#47) and
Q4_1 / Q5_0 / Q5_1 (#56) weights; an int8 tiled GEMM for Q8_0 / Q4_0 /
Q4_1 / Q5_0 / Q5_1 / IQ4_NL (#76); AVX512 kernels on Intel and a faster
direct convolution by default (#36, #70); Q4_K / Q2_K kept on the tiled
matmul on AMD (#57); Q5_0 / Q5_1 / Q4_1 through the Q8_0 GEMM at
diffusion batch sizes (#74); tiled flash attention and SIMD max fixes
(#66, #68, #62).
- aarch64 CPU: ik_llama.cpp GEMM kernels for K-quant and I-quant weights
(#48, #75), a NEON + i8mm variant for 128-bit SVE cores (#58), SVE flash
attention on the NEON path (#69), a 4x4 flash attention register tile
(#67).
- Metal: long graphs spread over more command buffers so the GPU
watchdog does not fire (#44), a coalesced im2col kernel (#45), flash
attention `auto` now means on without the timing probe (#46).
- Vulkan: RMS norm for short rows (#37), direct convolution chosen by an
output check instead of a timing race (#38), no host-buffer import on
AMD and MoltenVK (#60).
- HIP: bf16 WMMA operands for gfx11 / gfx12 (#59), FP32 accumulators in
the tile flash attention kernel (#61).
- CUDA: the Q8_1 block sum is computed from the quantized values, which
lowers matmul error for Q4_1 / Q5_1 / Q4_K / Q5_K / Q2_K weights (#63);
BF16 cuBLAS for large Q8_0 matmuls on A100, Hopper and datacenter
Blackwell (#39).
- Memory: the conditioning cache keeps entries across output sizes and
denoiser-only LoRA changes (#71); auto-fit charges unified-memory
devices against the RAM budget (#73, `SD_AUTOFIT_UMA=0` disables);
CPU-resident text-encoder weights are released when the next phase would
not fit (#72, `SD_TE_RELEASE=0` disables); `--mmap` repacks only what
the CPU repacks (#43); Qwen Image 2.1 prefix cache concatenated in F16
(#64).
- Packaging: bundles are smaller (#41; the Linux CPU bundle is 38.4 to
26.0 MiB, Linux CUDA 12 is 368.5 to 338.3 MiB, Linux Vulkan is 57.9 to
30.5 MiB), the Linux CPU bundles are run on emulated CPUs before
shipping (#49), and there is a new native Windows arm64 CPU bundle
(#55).

## Changes

- `studio/install_sd_cpp_prebuilt.py`: `DEFAULT_TAG` now names the new
release.
- Tests that pin the release name and its asset list now point at the
new tag. `test_sd_cpp_args.py` keeps the old pin in its list of builds
that support `--mmap`.
- The pinned asset lists gain `win-cpu-arm64`, with a test that a
Windows ARM64 host gets that bundle for `auto` / `cpu` while an x64 host
keeps `win-cpu-x64`, and that ARM64 with `cuda` or `vulkan` still gets
no match.

No Studio code changes. The existing selector already filters Windows
bundles by host architecture, so a Windows arm64 host, which today finds
no bundle in the pinned release and falls through to the upstream
fallback, now installs the native arm64 CPU build. An x64 Python running
under emulation on Windows arm64 reports `AMD64` and keeps the x64
bundle, as before. No option was removed from `sd-cli --help` or
`sd-server --help`; the new build only adds `--control-type`,
`--input-frames`, `--upscale-factor` and `--vsr-window-size`.

## Testing

- The sd.cpp, args, families, install, pin upgrade and download retry
tests pass (1406 passed). One test and one fixture error fail on main
and on this branch alike on this host, because its huggingface_hub is
older than the installed diffusers expects:
`test_create_causal_mask_patch_is_self_disabling_and_idempotent` and
`test_selection_installs_the_cuda_build`.
- Asset names: every bundle the selector can return was enumerated over
Linux x86_64 / aarch64, Windows AMD64 / ARM64 and macOS arm64 / x86_64,
with `auto`, `cpu`, `cuda` (no major, 12, 13), `vulkan` and `rocm`,
against the real asset list of the new release. Every returned name
exists in the release. The only change from the current pin is Windows
ARM64 `auto` / `cpu`, which goes from no match to `win-cpu-arm64`.
- SD1.5 (`v1-5-pruned-emaonly`), 512x512, 8 steps on CPU and 20 steps on
CUDA, euler, cfg 7, seed 42, both builds on the same machine. Each arm
repeated two or three times; every repeat was pixel-identical to the
first run of its arm. LPIPS is AlexNet.

Linux x86_64 CPU bundle, Xeon Platinum 8559C, 32 threads, wall time per
image:

| Weights | current pin | this branch | old vs new LPIPS | max pixel
diff |
| --- | --- | --- | --- | --- |
| f16 | 34.8 / 34.8 s | 16.4 / 17.2 s | 0.0001 | 13 |
| q8_0 | 31.3 / 32.4 s | 15.7 / 15.2 s | 0.007 | 118 |
| q4_K | 35.5 / 35.0 s | 18.7 / 19.0 s | 0.023 | 211 |

VAE decode alone went from 10 to 12 s down to 3.6 to 3.7 s. The
quantized CPU renders are not bit-identical to the current pin, but they
stay as close to the f16 render as before (q8_0 LPIPS to f16: 0.038 old,
0.046 new; q4_K: 0.163 old, 0.173 new).

Linux CUDA 12 bundle, Colab L4, wall time per image:

| Weights | current pin | this branch | old vs new LPIPS | max pixel
diff |
| --- | --- | --- | --- | --- |
| f16 | 4.70 / 4.70 / 4.71 s | 4.70 / 4.91 / 4.73 s | 0 | 0 |
| q8_0 | 7.42 / 4.92 / 4.90 s | 4.94 / 4.93 / 4.93 s | 0 | 0 |
| q4_1 | 18.13 / 17.97 / 17.94 s | 18.02 / 17.97 / 18.01 s | 0.025 | 198
|
| q4_K | 19.14 / 17.63 / 17.79 s | 17.74 / 17.63 / 17.61 s | 0.106 | 253
|

The current pin's first q8_0 run includes a cold start. f16 and q8_0 are
pixel-identical. q4_K moves, as the Q8_1 fix intends, and moves toward
the f16 render: LPIPS to f16 drops from 0.240 to 0.176 (q4_1: 0.327 to
0.322).

## Not covered

- macOS (Metal) and Windows were not run on hardware yet; the
cross-platform staging legs (Ubuntu, macOS 15, Windows) are still to
run.
- The new Windows arm64 bundle is covered only by the selector test and
the asset check. No Windows arm64 host ran it.
- No Vulkan, ROCm or HIP render with this build, no aarch64 Linux
render, and no Studio HTTP flow run (only `sd-cli` directly).
- No MiniMax-H3, MOSS-Image, Qwen-Image or FLUX.2 render with this
build; only SD1.5.
- CPU timings are from a shared host (both arms ran back to back with
the same thread count), and the CUDA timings come from one L4 VM, three
runs per arm. No T4 run.
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.

2 participants