Skip to content

Studio: install the pinned Diffusers build on startup when an old installer skipped it - #11579

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
oobabooga:diffusers-startup-repair
Sep 22, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
oobabooga:diffusers-startup-repair

Conversation

@oobabooga

Copy link
Copy Markdown
Member

An install updated from 2026.9.7 or older still needs two updates before Qwen-Image-2.1 loads. The first update runs the 2026.9.7 installer, which has no Diffusers main step, so Diffusers stays at 0.40.0 and the model refuses with "needs diffusers >= 0.41.0 (QwenImage21Pipeline)". #11566 fixes this for updates that start from 2026.9.9 or later, and its fast-path probe fixes the second update, but nothing that runs during the first update is new code.

Cause

unsloth studio update runs the installed setup.sh and install_python_stack.py, so an update from 2026.9.7 runs the 2026.9.7 installer end to end. The first new code such a host runs is the backend that starts after the update.

Fix

The backend repairs the install on startup, the same way utils/mlx_repair.py already repairs a dropped MLX stack:

  • utils/diffusers_repair.py reads the diffusers direct_url.json at startup. The pinned build is a git or zip direct reference, so a healthy install spawns nothing. When diffusers is an index release and diffusers-main.txt exists, it starts one background thread per process that runs install_python_stack.py --repair-diffusers-main.
  • --repair-diffusers-main runs step 11c by itself, behind the existing gates (_diffusers_main_needs_dependency_pass: opt-out, Python 3.10, git or the zip route from Studio: install the pinned Diffusers commit from a zip when there is no git #11565, no recorded failed build) and under the pass lock, so a running update is left to install the build itself. Exit 0 means installed, 1 nothing to do, 2 failed.
  • The installer runs with an allowlisted environment, as the MLX repair does: secrets and index redirects stay out. uv's directory is prepended to PATH for GUI launches, and the Windows variables Python, git and uv need are kept.
  • The diffusers prewarm is skipped while the repair runs, and a diffusion load during the repair is refused with "installing the pinned diffusers build in the background ... Try again shortly". Importing diffusers mid-install would read half-replaced files and keep 0.40.0 loaded for the whole session.
  • If diffusers was already imported before the repair finished, the refusal says to restart Studio instead of pointing at git.

Opt out with UNSLOTH_DISABLE_DIFFUSERS_AUTOREPAIR=1. UNSLOTH_DIFFUSERS_MAIN=0 also disables it.

Before and after

A copy of a real Studio venv (CUDA, Linux) in the state a 2026.9.7 to 2026.9.9 update leaves: unsloth 2026.9.9, Diffusers 0.40.0 from PyPI, and a manifest with no Diffusers main step. The backend was started from each wheel and asked for a Qwen-Image-2.1 plan (POST /api/inference/images/download-plan, Qwen/Qwen-Image-2.1), with uv's cached Diffusers build cleared first.

main this PR
First plan request after startup 400, "needs diffusers >= 0.41.0 ... has diffusers 0.40.0" 200, plan returned
Diffusers after startup 0.40.0 (unchanged after 183 s) 0.41.0.dev0 @ 80c7ed26, installed 4.8 s after startup
verify_install(deep=True) afterwards ok

On this host the repair finished before the first request arrived, so the refusal shown during a running repair was exercised only by the unit test.

Tests

  • New studio/backend/tests/test_diffusers_repair.py: 14 cases covering candidate detection (PyPI, git and zip installs), one repair per process, exit-code handling, both opt-outs, the environment allowlist, the load refusal while the repair runs, and the restart message.
  • Two new cases in tests/studio/install/test_diffusers_pin.py for _repair_diffusers_main: installed, failed, nothing to do, and an update holding the pass lock.
  • tests/studio/install: 7531 passed, 1631 skipped.
  • Backend diffusion, prewarm, startup and MLX repair suites: 1065 passed, 1 failed. The failure is test_qwen_image_21_gguf_reaches_sd_cpp_with_its_own_vae_and_a_qwen3vl_encoder, a GGUF filename expectation that is already red on main.

Scope

  • This takes effect only once it is in a PyPI release: updates install unsloth from PyPI.
  • One attempt per backend process. A host whose attempt fails retries on the next start, and no failure is recorded between starts.
  • The Windows and macOS paths were not run. The subprocess launch uses CREATE_NO_WINDOW on Windows and the same uv discovery as the MLX repair.

@danielhanchen
danielhanchen merged commit 55b6b07 into unslothai:main Sep 22, 2026
12 of 77 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…taller skipped it (unslothai#11579)

* Studio: install the pinned Diffusers build on startup when an old installer skipped it

* Stop the installer's children when the diffusers repair times out

* Start the diffusers repair before the socket binds and gate MiniMax Music 3 on it

* Wait out a peer holding the pass and keep UV_OFFLINE in the repair

* Leave local diffusers checkouts alone, record a failed repair, and hold the gate for a peer after a timeout

* Let an explicit update retry a failed repair, and wait out a peer's pass at startup

* Decide the startup repair only once no peer holds the pass

* List the diffusers repair among the adopters left outside the shutdown gate
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