Skip to content

Unsloth Studio / Desktop: remember the text encoder and VAE files per image model - #14845

Merged
danielhanchen merged 21 commits into
unslothai:mainfrom
LeoBorcherding:studio/image-component-recall
Oct 23, 2026
Merged

danielhanchen merged 21 commits into
unslothai:mainfrom
LeoBorcherding:studio/image-component-recall

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Reported in the Discord help thread. Related to #10695.

On the Images page, the Advanced "Text encoder file(s)" and "VAE file" fields start empty on every page load, and a model pick never clears or refills them, so anyone using separate ComfyUI-style files has to retype the paths each time (and one model's files ride along to the next). The fields were plain useState("") in images-page.tsx, and the only saved copy of the paths was the single last-model slot, which never fills them back in.

Fix

  • A successful load saves the text encoder and VAE paths it was given, per model (repo, kind and file), keeping the 50 most recent.
  • Picking that model again, or opening the page with it as the remembered model, fills the fields back in.
  • Picking a model with nothing saved clears the fields, so one model's files don't carry over to another.
  • Paths you've typed since the fields were last filled are left alone; each field is owned on its own, so editing only the VAE doesn't carry the encoder along.
  • Loading with the fields cleared forgets that model's entry.

Follow-ups in this PR keep the saved paths honest when the resident build changes underneath the page:

  • Reapply uses the resident model's own files, and a Load-mode footprint is planned with the shown model's files.
  • Saved files survive native-engine loads, retries and a load resumed mid-reload.
  • The first loaded status reconciles the saved entry: if another client reloaded that model without the files, the stale entry and the last-model slot's copy are dropped, so a re-pick or Reapply doesn't load old paths.
  • First run after upgrading seeds the per-model entry from the old last-model slot.

Frontend only.

Tested

Colab T4 high-RAM (Tesla T4, 15 GB), Linux, unsloth/Z-Image-Turbo-GGUF with the Comfy-Org Z-Image-Turbo qwen_3_4b.safetensors encoder and ae.safetensors VAE typed as absolute paths. Before = main at 505bbc2 (this PR's base), after = 8212984 (current head). Same VM, frontend rebuilt and server restarted between the two, fresh browser profile each.

step main 505bbc2 this PR 8212984
1. type both paths, load Q4_K_M filled filled
2. pick Q2_K still Q4_K_M's paths, and Q2_K loads with them cleared; Q2_K loads the base repo's own encoder
3. pick Q4_K_M again still filled (never cleared) filled back in
4. reload the page empty filled
main 505bbc2 this PR 8212984
2. pick Q2_K
3. pick Q4_K_M again
4. reload

Server log for the same three loads (serve.log, UTC). A diffusion.comfy_components line means the load used the supplied files:

# this PR (8212984)
10:46:01 diffusion.comfy_components: qwen_3_4b.safetensors -> Qwen3Model (rule strip_model_prefix, 0 int8 ConvRot linears kept, 0 dead tensors skipped)
10:46:03 diffusion.comfy_components: ae.safetensors -> AutoencoderKL (ldm_kl layout)
10:46:15 diffusion.loaded: repo=unsloth/Z-Image-Turbo-GGUF base=Tongyi-MAI/Z-Image-Turbo device=cuda offload=group      # Q4_K_M, typed files
10:47:10 diffusion.loaded: repo=unsloth/Z-Image-Turbo-GGUF base=Tongyi-MAI/Z-Image-Turbo device=cuda offload=model      # Q2_K, no supplied files
10:47:56 diffusion.comfy_components: qwen_3_4b.safetensors -> Qwen3Model (...)
10:47:57 diffusion.comfy_components: ae.safetensors -> AutoencoderKL (ldm_kl layout)
10:48:08 diffusion.loaded: repo=unsloth/Z-Image-Turbo-GGUF base=Tongyi-MAI/Z-Image-Turbo device=cuda offload=group      # Q4_K_M, recalled files

# main (505bbc2)
10:52:40 diffusion.comfy_components: qwen_3_4b.safetensors -> Qwen3Model (...)
10:52:42 diffusion.comfy_components: ae.safetensors -> AutoencoderKL (ldm_kl layout)
10:52:54 diffusion.loaded: repo=unsloth/Z-Image-Turbo-GGUF base=Tongyi-MAI/Z-Image-Turbo device=cuda offload=group      # Q4_K_M, typed files
10:53:38 diffusion.comfy_components: qwen_3_4b.safetensors -> Qwen3Model (...)
10:53:39 diffusion.comfy_components: ae.safetensors -> AutoencoderKL (ldm_kl layout)
10:53:57 diffusion.loaded: repo=unsloth/Z-Image-Turbo-GGUF base=Tongyi-MAI/Z-Image-Turbo device=cuda offload=streaming  # Q2_K, still Q4_K_M's files

A render with the recalled files works (default test prompt, 1024x1024, 8 steps, 73 s):

Apple M5 Mac, at 8212984: tests/image-component-recall.test.ts and tests/image-model-recall.test.ts (storage, the 50 cap, forgetting, fill / clear / keep-edits on a pick, per-field ownership, the stale-entry reconcile) 24 passed, typecheck clean.

Not tested

  • Unsloth Desktop, Windows, AMD, MPS: the change is frontend only, but the click-through above is the web app on Linux.
  • A second client reloading the model underneath the page (the reconcile path) was not driven by hand; it is covered by the follow-up commits' tests only.

A successful load stores the encoder / VAE paths it was asked for, keyed by repo,
kind and file. Picking that model again refills the Advanced fields, a model with
nothing saved clears them, and paths the user edited since are left alone. A load
with empty fields forgets the entry. Capped at the 50 most recent models.
danielhanchen added a commit that referenced this pull request Oct 23, 2026
… in #14822 (#14852)

pre-commit.ci fails `ruff-format-with-kwargs` again on PRs queued after
00:36 UTC (#14834, #14835, #14836, #14842, #14845):
`studio/backend/tests/test_video_stream_encode.py` was merged in #14822
without the formatter, so every PR's all-files run rewrites it.

Same class as #14817. `python scripts/run_ruff_format.py` (the hook's
entry point, `ruff==0.6.9`) applied to that one file. The AST is
identical before and after, `ruff check` passes, and a full run of the
hook over every tracked Python file on this branch changes nothing else.
@danielhanchen danielhanchen self-assigned this Oct 23, 2026
…iles

After a restart the Advanced fields start on the remembered model's files.
Reapply of a different resident model read those fields directly and sent
another model's text encoder / VAE with it. Route Reapply through the same
per-model rule a pick uses: untouched fields are replaced by the target's
saved files (or cleared), typed paths are still sent as typed.

[skip ci]
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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 ⚠️ Failed 2026-10-23T20:06:48.887865Z
We couldn’t complete this review. Comment @codex review to try again.
4a03454 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.

@Lyxot Lyxot self-assigned this Oct 23, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 23, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 23, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 23, 2026
…files

The picker's download footprint planned a GGUF with the live Advanced
fields, which may still hold another model's encoder / VAE files, while the
Load it fires sends the model's own saved files (or none). Share the
per-model rule as componentFilesForModel and apply it, without touching the
fields, when resolving Load-mode footprints. Download-only picks keep
sending the fields as they are.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ied and direct loads

- A recalled generation pinned the last-model slot's files, which a native
  (sd_cpp) load leaves empty, so its success erased the per-model entry.
  Recall now reads the entry first (recalledComponentFiles), slot as fallback.
- A Load anyway retry re-sent the request a native load had stripped, so the
  retry's success forgot the files. Retry the same pick instead; the native
  engine strips the same fields again.
- A finished load took ownership of the fields even when it never touched
  them (an adapter deploy loads a pipeline), so the next pick sent the old
  model's paths on as a user edit. A load owns the fields only while they
  show its files.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…m when the resident build differs

- First run after an upgrade: the fields start on the last-model slot's
  paths while the map is empty, so re-picking that model cleared them and
  its load could overwrite the only copy. Page open now copies the slot into
  the map when the model has no entry (seedImageComponents).
- A resident build of the same model with other components (another client
  reloaded it without the overrides) rewrote the slot but left the map, so
  the next recall brought the stale paths back. Generate now forgets an entry
  the resident diffusers build does not use (forgetStaleImageComponents); a
  native build never takes supplied files, so its entry stays.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…engages

Re-entering the page mid-reload seeds lastLoad from the resident descriptor,
which carries no requested files, so the finished load stored that as the
request and erased the model's entry. Only a load the page started (one
with fieldFiles) stores its request now; a resumed one keeps the entry when
the build engages it (or runs native) and forgets it otherwise
(rememberLoadedImageComponents).

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…aved files on the first status

- Editing only the VAE (or only the encoder) made both fields count as the
  user's, so the untouched one rode along to the next model and could be
  saved under it. componentFilesForModel and componentFieldsOwnerAfterLoad
  now decide each field on its own; an edited field keeps its old owner, so
  it stays an edit until a load takes it.
- The fields start on the remembered model's saved files before status is
  known. On the first loaded status, a resident build of that same model
  that does not use them (another client reloaded it) now forgets the entry
  and clears the untouched fields (reconcileRememberedComponents), so
  Reapply or a re-pick does not load stale files. Native builds keep it.

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… slot too; a pipeline load keeps a cleared field an edit

[skip ci]
…esident cleanup runs once per status

A local component file's status name is the basename the caller supplied rather than its resolved target, so an HF cache snapshot symlink no longer reports its blob hash and gets its saved paths erased. The resident cleanup now runs once per status response, so a field edit against a cached status cannot erase another tab's newer saved files.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ontext save, and persist a pending load's paths

A reload that changed only one override now keeps the other's saved path instead of
dropping both. The page open probe treats saving_chat_context as an in-flight load. The
requested encoder / VAE paths are kept in localStorage while a load runs, so a load
resumed after a page reload records them; any failed, cancelled or refused load clears it.

[skip ci]
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

An unknown error occurred
ℹ️ 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".

… and keep the saving phase through the GPU acquire

On page open a load-progress of ready now reconciles the pending load descriptor with the
resident build before it is cleared, so typed encoder and VAE paths are remembered.

The chat context save marker is now held by the SwapSave handle until the acquire thread is
done, so a page resumed during saving_chat_context does not read the eviction and VRAM wait
before begin_load as a cancelled load.
The first status read on mount can be the build a reload replaced. The ready
branch recorded the new component paths but left that old status on the page,
so releasing the probe gate reconciled the saved paths against it and deleted
them. Publish the fresh status under a status ticket before releasing the gate.

[skip ci]
…s not use

A pending descriptor left by a closed page matched the resident model by repo,
kind and filename only, so a reload of the same checkpoint on other component
files by another client replaced the saved entry with the stale request.
Require its files to match the status component_files (basenames, sd_cpp
exempt) before resuming it.

[skip ci]
…ill untouched fields from a recovered load

The load POST holds a preparing marker until it returns, so load-progress reads as starting
while evidence, checks and the acquire run instead of the previous model's ready or null, and a
page reopened then keeps the pending descriptor and polls. A pending load recovered on reopen
fills each Advanced field the user has not touched since with its paths and owns it.

[skip ci]
The preflight marker is now a token that /images/unload cancels, within the
same account scope as the engine unload. The load POST checks it before the
engine switch, after the chat KV save, before the acquire, and under the
token lock around begin_load, so a Cancel from a reopened page stops the load
with the engine's 409 instead of evicting chat and loading anyway.
@danielhanchen
danielhanchen merged commit 711332a into unslothai:main Oct 23, 2026
66 of 67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants