Repository navigation
Studio: keep a load's baked LoRAs on /v1/images/generations - #17899
Conversation
The OpenAI images route built its generate call without loras, so on an int8/fp8 load with adapters baked in (Deploy to Create) every render set the baked adapters to scale 0 and the gallery recorded loras: []. Record the load request's (id, weight) pairs behind a bake, report them in status as baked_lora_specs, and have the route default to that set when the request omits loras. An x-unsloth loras field selects adapters explicitly ([] renders without any), and the gallery recipe records the set used.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91aec9d6c6
ℹ️ 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".
| expected_load = load_identity( | ||
| status.get("repo_id"), status.get("base_repo"), status.get("family") | ||
| ) | ||
| loras = _openai_image_loras(body, status) |
There was a problem hiding this comment.
Authorize requested LoRAs before passing them to the engine
For managed accounts, the new explicit loras selection bypasses the adapter authorization enforced by /images/generate through account_access.require_media_adapters. The existing require_media_generation_access check only authorizes the resident model and its load-time components, not newly requested adapters. On a dense load, _apply_loras resolves Hub adapters using the resident state's hf_token, and diffusion_lora.resolve_one does not perform account authorization for Hub entries. A managed user can therefore request a private or disallowed Hub adapter using the loading account's credentials or shared cache. Apply the adapter-access check before either generation path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 092659f: for managed accounts the route now runs account_access.require_media_adapters on an explicit loras selection before either generation path, as /images/generate does. The baked set used when loras is omitted was authorized by its load. Test: a denied adapter returns 403 and never reaches generate.
| batch_size = body.n, | ||
| expected_load = expected_load, | ||
| # Only when set, so engines without the parameter keep their call shape. | ||
| **({"loras": loras} if loras else {}), |
There was a problem hiding this comment.
Translate LoRA selection refusals into client errors
When an explicit selection names an unknown adapter or adds an adapter that was not baked into a quantized load, resolve_specs or _adjust_baked_loras raises ValueError. Forwarding the new field into this handler sends those expected validation failures through its generic exception boundary, which returns HTTP 500 and hides the actionable reload/selection message. Unlike /images/generate, API callers cannot distinguish an invalid selection from a server failure and may automatically retry an unrecoverable request. Map recognized LoRA selection failures to a sanitized HTTP 400 response on both the single and batched paths.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 092659f: LoRA selection refusals now raise a typed LoraSelectionError (a ValueError subclass, so /images/generate is unchanged): unknown or wrong-family adapter, Hub not found or gated, and the quantized / streamed-graph reload refusals. The OpenAI route maps it to a 400 with param loras on both the single and batched paths; any other ValueError stays a sanitized 500. Tests cover both.
…fusals as 400 [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ed Context field (#17902) ## Summary Two intended Studio UI changes merged without their Playwright drivers and contract tests being updated, so these gates are red on main and on every PR: 1. **#17839 collapses the model picker on load.** With a model loaded, opening the picker shows only that model's row (aria-label `<model>: show all models`); the source tabs, the search field and the rows render only after that row is clicked. - `Chat UI` / `Chat UI, API, Update and GGUF inference` (`playwright_chat_ui.py`): `model picker search input not found` (seen on #17839, #17900 and the staging run of #17899). - On the Windows lane the chat driver instead found an attached but hidden `Search ... models` field and timed out after 60 s in `Locator.fill` (staging run of #17899). - Model config gate (`playwright_model_config.py`): `picker shows no rows at all, so the hidden-model check below proves nothing`, then `could not open run-settings`. 2. **#17840 renames the run settings "Context Length" field to "Context".** - `Repo tests (CPU, studio)`: `test_model_picker_contracts.py::test_an_mlx_target_is_offered_a_context_length_not_a_sequence_length` and `::test_run_settings_page_keeps_its_identifying_controls` still assert the old label. - Model config gate: `Context Length input has no numeric default`. `playwright_memory_estimate.py` finds the field the same way. Both product changes are deliberate, so the fix is on the test side. No product code changes. ## Change - `tests/studio/_playwright_robust.py`: new `expand_collapsed_model_picker(scope)` waits for either the expanded picker (the `Model sources` tablist) or the collapsed row, and clicks the row only when the picker opened collapsed. It is a no-op on an already expanded picker, and it only counts controls that are on screen, so a hidden mounted copy is neither clicked nor taken as proof that the picker expanded. The collapsed row suffix, the tablist selector and the run settings context field name (`RUN_SETTINGS_CONTEXT_LABEL = "Context"`) live here once. - `playwright_chat_ui.py`: the search step expands the picker before waiting for the search field, and waits for a visible one. The rest of the step (two queries must show different picker text) is unchanged. - `playwright_model_config.py`, `playwright_memory_estimate.py`: `open_picker()` expands after clicking the trigger; `context_input()` looks the field up by `RUN_SETTINGS_CONTEXT_LABEL` with an exact match, since `Context` is a prefix of other run settings names. - `test_model_picker_contracts.py`: the two run settings assertions read `Context`. - New `tests/studio/test_chat_ui_picker_collapsed_row.py` (CPU) pins the coupling between the drivers and the frontend: - the collapsed row suffix and the `Model sources` tablist are still what `composer-model-picker.tsx` renders, - a settled load still collapses the picker (so the expand click is not dead code), - all three drivers use the helper, the chat search step expands before it waits, and `open_picker()` expands after the trigger click, - `model-config-page.tsx` still names the context field `RUN_SETTINGS_CONTEXT_LABEL`, and both drivers look it up by that name. ## Testing - New test plus `test_model_picker_contracts.py`: 213 passed. - Sabotage: with the three drivers reverted to main, 4 of the new checks fail; without the on-screen filter in the helper, 1 fails; with the field renamed back to `Context Length`, 2 fail. - Every test that reads these drivers or `_playwright_robust.py` (17 files): 345 passed. `tests/studio/test_*.py` on CPU: the only failures are 5 host-specific tests (AMD DRM detection, credential homes, version compat sweep) that do not touch these files. - The helper against a scripted page in real Chromium (Playwright 1.64): a collapsed picker with hidden copies of the tablist and search is expanded and its visible search filled; an expanded picker and a page with neither are left alone; the old attached-only lookup on the collapsed page times out in `fill()`, as on the Windows lane. - The Chat UI and model config Playwright jobs on this PR exercise the drivers end to end.
… /v1 (#17909) ## Summary #17899 made `/v1/images/generations` answer a LoRA selection the loaded model cannot take with a 400 (`param: loras`) instead of a sanitized 500, by typing those refusals as `LoraSelectionError` (a `ValueError` subclass, so `/images/generate` is unchanged). A few generation-time refusals still raised a plain `ValueError` and so still reached API callers as "Image generation failed." with a 500. This types them too: - MiniMax-H3-Image: the LoRA set and weights are fixed for a load (`_check_h3_image_loras`). - A weight change on adapters merged into weights that are now offloaded (`_remerge_quant_loras`). - A GGUF LoRA file on the diffusers engine (`_resolve_lora_set`). - LoRAs blocked on this load (compiled model, unsupported quant or family) (`_apply_loras`). - The native sd.cpp engine refusing LoRAs for a family. Internal failures that wrap another exception ("Failed to apply LoRA: ...", "Could not apply the new LoRA weights ...") stay plain `ValueError`, so `/v1` keeps returning a sanitized 500 for them. Load-time refusals are untouched (they go through the load route). ## Tests - New `tests/test_lora_selection_refusals_typed.py`: parses each refusing function and fails if a LoRA selection refusal still raises a plain `ValueError` (5 of 8 cases fail before, all pass after), and checks the class stays a `ValueError`. - The OpenAI image route tests (including the baked-LoRA tests from #17899) pass; the diffusion LoRA, quant-merge and remerge suites pass with no failures on either side.
…age and dense builds (#17961) ## Summary Follow-up to #17899. After Train > Deploy to Create, two loads still rendered through `/v1/images/generations` without the deployed LoRA (found running train, deploy and render for 13 families on Colab A100 / G4): - **MiniMax-H3-Image:** it merges load LoRAs into the DiT but never recorded which adapters were behind the merge, so the route sent an empty selection and the backend refused it ("MiniMax-H3-Image merges LoRA adapters into its weights when the model loads ..."). - **Dense builds** (bf16 / nf4 / bnb pipelines: SDXL, Z-Image and others): they apply load LoRAs per generation, so an omitted `loras` field rendered the base model. On SDXL and Z-Image the render without the field was the base image. ## Change - MiniMax-H3-Image records the specs behind its load-time merge, as the int8 / fp8 bakes already do. - Every committed load records the adapters it was asked for (`load_lora_specs` in the status). - An omitted `loras` on `/v1/images/generations` now means the adapters the load named: the baked set when there is one, else the load's requested set. `[]` still renders without any; an explicit list is used as given. The field description is updated. `/images/generate` (Studio's own route, which always sends its selection) is unchanged. The native sd.cpp and MLX engines do not record load adapters, so an omitted field there still renders without them, as before. Two cases now get a clear 400 instead of a silent plain-model image: a deployed LoRA on a dense load that Speed has since compiled ("Speed compiled this model, so LoRAs are off ..."), and a deployed adapter whose file was deleted after the load ("Unknown LoRA"). ## Tests - `tests/test_openai_images_baked_loras.py`: 4 new tests (an omitted field keeps a dense deploy's adapters, the status reports the load request, every bake including MiniMax-H3-Image records the specs `/v1` reads back, dense loads record their requested adapters). They fail on main and pass here; the 9 existing tests pass. - Related route, batching and gallery suites pass with no failures on either side. ## GPU runs (Studio from main + this change, REST API) | family, load | main: `/v1` without `loras` | this PR | |---|---|---| | MiniMax-H3-Image int8, LoRA merged (G4) | refused | renders with the LoRA, bit-identical to the Studio render | | Z-Image bnb-4bit (A100) | base image | bit-identical to the Studio render with the LoRA | | SDXL base dense (A100) | base image | with the LoRA | | FLUX.1, FLUX.2, Qwen-Image-2.1, Krea-2, FLUX.3 int8 bakes | with the LoRA | unchanged |
…ate no longer drops it), HunyuanImage-2.1 LoRA gated off (#17993) ## 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. - The engine reads a missing LoRA selection as "none". On a load that baked its adapters into the quantized weights, "none" sets every baked adapter's weight to 0. - The image then renders without the LoRA, with no error. - `/v1/images/generations` already resolves an omitted list to the load's adapters (#17899, #17961); the native route did not. 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).
Summary
After Deploy to Create (or any load that bakes LoRAs in), a render through the OpenAI-compatible
/v1/images/generationscame out without the LoRA, and the gallery recordedloras: []. Studio's own/images/generaterendered with it.Cause:
ImageGenerationRequesthad nolorasfield, so the route passed none. On an int8 / fp8 load whose adapters were baked in at load time, an empty selection sets every baked adapter's scale to 0, silently. The "load again" 400 only fires when a request adds adapters that were not baked, so nothing told the API user.Changes
ImageGenerationRequestgains an optional x-unslothlorasfield (discovery id + weight, as on/images/generate, duplicate ids refused):[]: render without any;status()reports them asbaked_lora_specs.lorasasid:weightlike the native route.Tests
tests/test_openai_images_baked_loras.py(7): omittedlorasrenders with the baked set and the gallery records it,[]renders without, an explicit list overrides, duplicate ids are refused, a load without baked adapters keeps the old call, status reports the specs behind a bake, and passing the baked set back through_apply_loraskeeps it on. 6 of 7 fail before the change.Not covered
_apply_lorastest.baked_lora_specs; on them the route is unchanged unlesslorasis sent.