Skip to content

Studio Images: an omitted loras keeps the load's LoRAs (Deploy to Create no longer drops it), HunyuanImage-2.1 LoRA gated off - #17993

Merged
danielhanchen merged 9 commits into
mainfrom
studio-images-lora-load-set
Nov 16, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio-images-lora-load-set

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

A LoRA deployed with "Deploy to Create" on an int8 / fp8 image load was silently dropped by any /images/generate call that left loras out. That includes direct API calls and every internal caller built from such a request: the chat generate_image tool, the queue and XY cells.

Three smaller gaps found by the same LoRA matrix are fixed too.

Change

  • /images/generate: an omitted loras now means the adapters the model was loaded with (the baked set, or the set a dense load named), at their load weights. A load that named none still renders with none. An empty list [] renders without any adapter.
    • This is a behaviour change for API callers that relied on "omitted = none" after a LoRA load; they now need to send [].
    • The field description in models/inference.py documents the new meaning.
    • Exception: a dense load that Speed compiled (it reports supports_lora: false) resolves an omitted list to none, so turning a LoRA off and letting Speed compile never brings it back as a refused request. The baked set of an int8 / fp8 load still resolves.
    • Resolving an omitted list pins the load it was read from (also when it resolved to none), so a model swapped in before the generation slot is retried with its own adapters.
  • Images page: sends [] instead of omitting the field when no adapter is active, so turning a LoRA off in the UI still turns it off.
  • Compare grid (frontend) and server XY grid: a cell whose LoRA weights are all 0 sends [] instead of omitting loras, so it stays adapter-free under the new meaning.
  • HunyuanImage-2.1: gated off for LoRA. Its diffusers pipeline has no load_lora_weights, so every LoRA generation and every int8 / fp8 LoRA load on it failed with an AttributeError. A new test checks that every diffusers image family either has a LoRA loader or is listed as gated off.

Results

Real GPU, Colab G4, Z-Image int8 through the REST API, compiled, same seed:

request main this PR
loras omitted after a Deploy-to-Create LoRA load renders without the LoRA (same as []; LoRA vs none LPIPS 0.147) renders with the LoRA (same as sending it)
loras: [] no LoRA no LoRA

HunyuanImage-2.1 on main, same G4: the bf16, INT8-attention and fp16 LoRA cells fail to render, and the int8 / fp8 LoRA loads fail at load. With this PR the family no longer offers LoRA.

The same G4 matrix checked LoRA application across 18 bf16 families plus GGUF, sd.cpp, nf4, fp16, INT8 attention and baked int8 / fp8 loads.

Tests

  • New tests/test_images_generate_load_loras.py: omitted loras renders with the baked set; a dense load keeps the adapters it named; the chat generate_image tool keeps the baked set; [] renders with none. 3 fail on main.
  • tests/test_diffusion_lora.py: HunyuanImage-2.1 is gated off, and every diffusers pipeline family has a LoRA loader or is gated off. Both fail on main.
  • Also in tests/test_images_generate_load_loras.py: a compiled dense load that omits loras renders without its named set, and a load swapped in before the slot retries with its own set. Both fail without their fix.
  • The loader test names every family it cannot check on the installed diffusers (FLUX.3 needs 0.42+, MOSS-Image has its own loader, MiniMax-H3-Image merges at load), and any other missing class fails.
  • tests/test_diffusion_xy.py: an all-zero LoRA cell drops the adapter. Fails on main.
  • studio/frontend/tests/images-compare-grid.test.ts: the all-zero cell assertion fails on main; the file passes (47).
  • Backend LoRA, XY, routes and /v1 baked LoRA suites: 914 passed.

Not covered

  • The HunyuanImage-2.1 refusal was not re-run on GPU after the gate.
  • Studio UI journeys were not driven in a browser; the UI change only affects the request body ([] instead of a missing field).

The engine reads a missing LoRA selection as none, which on an int8 / fp8
load that baked its adapters sets every baked adapter's weight to 0. The
native /images/generate route passed None for an omitted list, so API calls
and internal callers that build a request without loras (the chat
generate_image tool, the queue and XY cells built from such a request)
rendered a Deploy-to-Create load without its LoRA, silently.

Omitted now means the load's adapters at their load weights, as on
/v1/images/generations; an empty list renders without any. The Create page
sends [] instead of omitting the field when no adapter is active, so turning
a LoRA off there still turns it off.
…ad of omitting loras

/images/generate now reads an omitted loras list as the adapters the model was loaded with, so a
Compare grid cell that sets every LoRA weight to 0 must say none explicitly; otherwise it would
render with the load's adapters.
…pter-free

The cell used to drop its loras to None, which /images/generate now reads as the adapters the
model was loaded with; keep it as an explicit empty list instead.
… has no LoRA loader

The family passed the LoRA gate, so a selected adapter failed every generation with
"'HunyuanImagePipeline' object has no attribute 'load_lora_weights'" (and a LoRA load failed the
same way). List it as unsupported so the load and the picker refuse it up front, and add a guard
that every diffusers pipeline family either has a loader or is listed.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T16:57:58.897137Z 447e4b5 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 113c8385f5

ℹ️ 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".

Comment thread studio/backend/routes/inference.py Outdated
Comment on lines +51408 to +51411
if expected_load is None:
expected_load = load_identity(
status.get("repo_id"), status.get("base_repo"), status.get("family")
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pin the load even when its default adapter list is empty

For an unmanaged API request that supplies steps, guidance, width, and height but omits loras, an empty adapter list leaves expected_load unset. If a different model with load-time LoRAs finishes loading between this status read and acquisition of the generation slot, the backend accepts that replacement and receives loras=None, disabling its adapters instead of applying the newly documented defaults. Pin the status identity whenever resolving omitted LoRAs, including when no adapters or no loaded model were observed, so the existing replacement retry can resolve the new load's adapters.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed: an omitted loras now pins the load identity whenever it is resolved (nothing loaded pins the empty identity), as the steps / guidance defaults do, so a replacement load is retried and gets its own adapters. Fix and a fails-before test coming in the next push.

…r-free

Speed Auto compiles a dense load once a run goes adapter-free, after which the load reports supports_lora false.
The Images page then hides LoRA and omits the field, and the chat tool always omits it, so resolving the load's
named set made every later generation fail with the compiled-LoRA refusal. The baked set still resolves.
…o none

With no adapters resolved (or nothing loaded) the run stayed unpinned, so a load with LoRAs finishing before the
generation slot was admitted with loras=None and its adapters were dropped. Pin it like the omitted steps / guidance
do, so the replacement retry re-resolves against the new load.
A pipeline class missing from the installed diffusers was skipped silently. Only FLUX.3 (diffusers 0.42+, loader
asserted when it imports), in-tree MOSS-Image (its loader methods asserted) and MiniMax-H3-Image (adapters merged at
load) may be absent; any other missing class fails.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7dcce22e2f

ℹ️ 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".

Comment on lines +51412 to +51414
load_identity(
status.get("repo_id"), status.get("base_repo"), status.get("family")
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include adapter defaults in the omitted-LoRA load pin

If the same checkpoint is reloaded with different load-time LoRAs between this status read and acquisition of the generation slot, this pin still matches: load_identity() contains only repo, base repo, and family, and DiffusionBackend.generate() compares only those fields. The request therefore runs with the previous load's adapter selection instead of retrying with the replacement's defaults. For example, replacing an adapter-free load with the same model plus a baked LoRA still admits loras=None and disables that LoRA. Include a load revision or the adapter-default identity in the generation-slot check so same-model replacements also trigger resolution again.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The route now also records the adapter set it resolved an omitted loras from (load_lora_signature of the status's load_lora_specs), and DiffusionBackend.generate compares it inside the generation slot next to the load identity; a same-model reload with other adapters raises DiffusionModelReplacedError and the existing retry re-resolves. New test test_a_same_model_reload_with_other_adapters_retries_with_its_own_set fails without it (renders [None]).

…a same-model reload with other LoRAs retries

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 447e4b5adf

ℹ️ 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".

[skip ci]
@danielhanchen
danielhanchen merged commit 01d166c into main Nov 16, 2026
@danielhanchen
danielhanchen deleted the studio-images-lora-load-set branch November 16, 2026 17:39
danielhanchen added a commit that referenced this pull request Nov 16, 2026
…failing one (diffusion / g-l red since #17993) (#18000)

## Summary

#17993 (an omitted `loras` keeps the load's LoRAs) merged with three
backend tests red, and they are red on main now (`(Python 3.13,
diffusion)` and `(Python 3.13, g-l)` on every PR based on `01d166c63c`
or later):

```
test_diffusion_minimax_h3_image_default_size.py::test_an_omitted_text_to_image_size_survives_a_failing_status_read
    RuntimeError: status read failed
test_image_generate_model_defaults.py::test_explicit_values_equal_to_the_schema_defaults_stay_and_skip_the_status_read
    assert 2 == 1   (backend.status_calls)
test_diffusion_lora.py::test_lora_loader_check_exceptions_hold
    ModuleNotFoundError: No module named 'diffusers'
```

## Cause and fix

**A failing status read now fails the run (route).** The new
`request.loras is None` block in `_generate_diffusion_image_run` calls
`backend.status()` unguarded. The omitted-size path right below it
already treats a failed status read as "no status", and the test pins
that a run with named steps and guidance survives one. A status read
that raises now fails `/images/generate` before the engine is called.
The fix gives the omitted-loras block the same handling as the size
block:

- reuse the FLUX.3 upsampler probe's status read on the first attempt
(no second read, as the size path does);
- if a read is still needed and it raises, log it and leave `loras`
omitted, which is what the engine received before #17993.

**An extra status read on every run with explicit steps and guidance
(test).** The defaults test sends `steps` and `guidance` and asserts the
defaults add no status read. Since #17993 an omitted `loras` stands for
the load's adapters, which needs the status, so that request is no
longer fully explicit. The test now also names `loras: []`, which keeps
its claim (explicit values skip the read and do not pin the load). With
the probe reuse above, an omitted `loras` costs no extra read either,
and a new test pins that: one status read in total, and the run is
pinned to the load.

**The MOSS import runs before the diffusers skip (test).**
`test_lora_loader_check_exceptions_hold` imports
`core.inference.diffusion_moss_image` before
`pytest.importorskip("diffusers")`, but that module subclasses
diffusers' mixins at import time, so the diffusion shard (no diffusers
installed) errors instead of skipping. The import now comes after the
skip. The family-name check still runs everywhere.

## Verification

- On main: the first two fail, as in CI. The third needs diffusers
absent; with `sys.modules["diffusers"] = None` it skips with this change
instead of erroring.
- With this change: `test_image_generate_model_defaults.py`,
`test_diffusion_minimax_h3_image_default_size.py`,
`test_diffusion_lora.py` and `test_images_generate_load_loras.py`: 725
passed. The 32 backend test files that drive `/images/generate` or the
LoRA defaults: 2070 passed; the 5 failures there
(`test_diffusion_backend.py` MiniMax H3 download plan) fail the same way
on main in this environment (a local diffusers import error), so they
are not from this change.
- Restoring main's `routes/inference.py` fails the size test (`status
read failed`) and the new omitted-loras test (two status reads).
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 17, 2026
… mid-request (unslothai#18135)

## Summary

`/v1/images/generations` can render with a stale adapter set when the
model is reloaded mid-request. With `loras` omitted, the route resolves
the request to the load's adapters, but it pins only repo, base and
family. Reloading the same model with other adapters keeps that
identity, so a reload that lands between the status read and the
generation slot is let through. There are two outcomes:

- **Plain load rebaked with a LoRA:** the engine reads "no selection" as
no LoRA, so the new bake renders at weight 0.
- **One baked LoRA swapped for another:** the request gets a 400 for an
adapter it never named.

unslothai#17993 fixed the same race on the native route. `/v1` now passes the
same `expected_load_loras` pin, on both single and batched calls. It
does so only when `loras` is omitted and the engine reports its load's
adapters. Batches are keyed on it.

## Testing

- **New:** `tests/test_openai_images_load_swap.py`, 6 tests in which a
load thread commits a rebake between the status read and the slot. On
main 4 fail and 2 pass; on this branch all 6 pass.
- One test drives the real `DiffusionBackend.generate` slot check. On
main it reaches the render with `loras=None`, which would zero the new
bake.
- **Updated:** the fake engine in `test_openai_images_baked_loras.py`
takes `expected_load_loras`, as the real diffusers engine does.
- **Suites:** `/v1` and native route suites pass. Across 14 wider route
files, main and this branch fail the same test IDs; they need zstd,
sqlite_vec and the MiniMax download plan.

## Not covered

No GPU run drove a real reload into a live `/v1` request. The race is
route-level, and the test exercises the real engine's slot check.
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