Skip to content

Studio: fix FLUX.3 workflows, controls, LoRAs and download progress - #14312

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
oobabooga:fix/flux3-studio-gaps
Oct 20, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
oobabooga:fix/flux3-studio-gaps

Conversation

@oobabooga

@oobabooga oobabooga commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Live testing of FLUX.3 Image Klein in Studio found six problems in the Images page and the shared download progress. Generation itself worked on every path tested; the problems are in the workflow handoff, the controls and the download accounting around it.

What changes

1. Edit image opens Reference

applyEditSource only looked for an Edit or Transform workflow. FLUX.3 and FLUX.2 klein have neither: they edit through Reference. So "Edit image" from the Images strip or the Library left the page on Create, hid the source and said "The loaded model cannot edit images". Reference is now the fallback after Edit and Transform, so models that have those keep their current destination.

2. No Run settings gear in the Images and Video pickers

The gear opened the chat (llama.cpp) load form, with Load in 4-bit and Max Seq Length, and neither page reads what it returns. Pickers scoped to image or video tasks no longer show it; those pages keep their load options under Advanced. The chat picker is unchanged.

3. Bounding-box layouts survive Enhance prompt

FLUX.3 reads a box table after the caption: <caption> [{"id", "bbox": [y_min, x_min, y_max, x_max], "desc"}, ...] on a 0-1000 canvas. Studio sent such a prompt through the plain t2i / i2i upsampler prompts, which forbid ids and coordinates, so Enhance rewrote it to prose and the boxes were lost. This now follows BFL's reference code (flux3/bbox.py and generate.py in black-forest-labs/flux-3-image-klein):

  • A finished caption, where every row is cited as <id>, skips the upsampler and runs as typed.
  • A request ending in a box table uses the t2i_bbox / i2i_bbox prompts with the rows locked, and the locked boxes are put back into the answer.

The two new system prompts are byte-identical to system_prompts.json in black-forest-labs/flux-3-image-klein-pup. The ported helpers return the same results as BFL's functions on 3,000 generated cases.

4. Live preview, Guidance and Negative prompt follow the engine

  • FLUX.3 uses the FLUX.2 VAE and the same packed latent layout, so it now uses the FLUX.2 preview map. Before, the switch was on but no frame ever arrived. A new status field, supports_live_preview, disables the switch where nothing streams (the native engine, and families without a map). The saved preference is kept.
  • Distilled FLUX.3 on diffusers has no guider, and Flux2KleinPipeline turns guidance off for distilled FLUX.2 klein checkpoints, so Guidance did nothing there while recipes recorded whatever was set. supports_guidance is false for those loads; the control is disabled at the model's default, and that value is sent and recorded. The native engine runs real CFG above 1, so its control stays enabled.
  • The negative prompt hint said it is used above guidance 0, but Studio only passes it above 1 for most models (above 0 for Z-Image and Krea 2). negative_prompt_min_guidance reports that threshold, and it drives both the hint and whether Generate sends the negative prompt.

5. The staged download toast no longer reaches 100% early

After a Cancel, the next download of the same files counts its whole file set, cached files included, because downloads.py only subtracts the cached baseline when there is no resume state. use-staged-download divided that by the plan's missing bytes. Cancelling FLUX.3 Base FP8 and picking it again made the toast show "6.4 GB of 6.4 GB, 100%" for two minutes while the Downloads panel still had 5.5 GB to go. The toast now takes the cached part (the job's total minus the missing bytes) off the count. A fresh download reads as before. The hook is shared by Images, Video and the Hub queue.

6. One of several baked LoRAs can be turned off

INT8 and FP8 loads bake their LoRAs at load time, and weight changes do not need a reload. Setting one of two adapters to 0 was rejected with "Reload the model", because requests drop zero-weight rows and _adjust_baked_loras compared the rest with the full baked set by name. It now matches adapters by file and runs the omitted ones at 0. Adding an adapter that was not baked still requires a reload.

When the transformer is streamed through GPU memory (Balanced, or Auto when it picks that placement), a LoRA weight change breaks the CUDA-graph recapture; on main a weight tweak there already returned 500 and every later image failed until a reload. On such a load, any LoRA weight change now returns the existing 400 asking for a reload, and the model keeps working.

Not changed

  • /v1/images/generations still sends prompts as typed. Enhancing them by default would change results for existing clients.
  • Inpaint, Transform, Extend and Upscale stay disabled for FLUX.3, whose editing workflow is Reference.
  • Guidance stays enabled for distilled FLUX.3 on the native engine, which does apply it, although BFL's reference sampler keeps distilled guidance at 1.
  • Reference renders at the page's size, not the source's: Edit image on a 16:9 picture with the page at 1:1 gives a square result with the scene extended.

Before / after

Fresh Studio installs at the merge base and at this branch, fresh en-US browser profile, same steps on both. Boxes and labels are added afterwards.

Edit image with FLUX.3 loaded (from the image strip; the Library entry does the same)

01_edit_handoff

Image model picker (on main, hovering a row shows a gear that opens the chat load form)

00_picker

Guidance on distilled FLUX.3 (diffusers)

02_guidance

Live preview mid-generation

03_live_preview

Enhance prompt Preview of a request with two locked boxes (the caption box is expanded to show the whole caption)

04_enhance_boxes

Picking FLUX.3 Base FP8 again after cancelling its download

05_download_toast

Validation

Live A/B on an RTX 6000 Ada, main against this branch. Beyond the screenshots:

Check main This PR
Box request with Enhance on, generated at 768x768 Both balloons spill out of their boxes Both balloons sit inside them
Guidance 1 vs 4, same seed Identical pixels on distilled FLUX.3 and distilled FLUX.2 klein 4B (diffusers); different on the native engine Control disabled on the first two, enabled on native
Negative prompt at guidance 1, Base on diffusers and distilled on native Hint says above 0; the unused prompt is sent Hint says above 1; not sent
Base INT8, two baked LoRAs, transformer resident: turn either one off 400 "Reload the model" 200; both back on reproduces the first image exactly
The same on Balanced: any weight change 500, then every image fails until a reload 400 asking for a reload; the model keeps working

The live preview matched the final image in layout, with per-channel correlation 0.93 to 0.97, and the final pixels are identical with the preview on and off.

Tests:

  • New backend tests cover box-table detection, the layout prompts, finished-caption passthrough, LoRA subsets and the streamed-load refusal, and per-family guidance, negative-prompt and preview capabilities. They fail on main (58 failures) and pass here. A new frontend test covers the staged progress arithmetic.
  • Backend diffusion, FLUX.3, native-engine, LoRA and image suites: 14,268 passed, 4 failed. The same 4 (video trainer rotation and Z-Image fused unload) fail on main.
  • Frontend typecheck passed. Frontend suite: every failure also fails on main, except one streaming timing test that passes when rerun alone.

Not exercised: AMD, Apple and Windows hosts, and FLUX.2 klein Base.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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 ✅ Completed 2026-10-20T07:26:34.834126Z 0ac1bbe 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.

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#396.

@danielhanchen

Copy link
Copy Markdown
Member

@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: 7210de75a3

ℹ️ 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 +19 to +20
const cached = Math.max(0, progress.expectedBytes - missing);
return Math.min(missing, Math.max(0, progress.downloadedBytes - cached));

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 Ignore held byte readings when totals change

When a download switches transport or retries and its first new poll reports zero bytes, resolveProgressUpdate intentionally retains the previous downloadedBytes while adopting the new, possibly smaller expectedBytes total (the measuredTransfer === false case in progress-reconcile.ts). This helper cannot see that flag, so a stale 3 GB reading paired with a new 0.5 GB entry/total makes cached zero and returns the full 0.5 GB, putting the staged toast at 100% before the retry transfers anything—the same premature-completion symptom this change is meant to fix. Propagate the measured flag or avoid this arithmetic for held samples.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in 0ac1bbe. DownloadJobProgress now carries measuredTransfer from the job, and stagedEntryTransferredBytes takes the entry's last measured reading: a held sample (measuredTransfer: false) returns that reading, capped at the entry, instead of pricing the previous run's bytes against the new total. useStagedDownload keeps the last measured value per entry in state. Test: a held sample keeps the last measured reading instead of pricing it against the new total.

A transport switch or retry can report its first poll as zero bytes
against a smaller total; the download manager then holds the previous
downloadedBytes (measuredTransfer false). Pairing that held figure with
the new total made the cached-bytes arithmetic read the whole entry as
transferred. DownloadJobProgress now carries measuredTransfer, and a
held sample keeps the entry's last measured reading.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0ac1bbede6

ℹ️ 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
danielhanchen merged commit b32d544 into unslothai:main Oct 20, 2026
danielhanchen added a commit that referenced this pull request Oct 20, 2026
)

## Problem

`Frontend build + bundle sanity` is red for every PR based on current
main. Main itself builds over the startup budget:

```
eager startup JS: 6684.2 KB raw, 2012.7 KB transfer, 96 chunks
over the startup budget: raw 6684.2 KB > 6683.8 KB
```

## Measurement

Exact totals, one machine and build, Node 24, 96 chunks throughout:

| Commit | Raw (B) | Transfer (B) |
|---|---|---|
| 22a0bea (last in-budget main) | 6,844,101 | 2,060,889 |
| 6a19cb2 (before #14312) | 6,844,101 | 2,060,887 |
| b32d544 (#14312, FLUX.3 workflows, controls and LoRAs) | 6,844,527
| 2,061,025 |
| d3a8257 (main, after #14228) | 6,844,622 | 2,061,040 |

#14312 adds 426 B raw / 138 B transfer, and #14228 adds 95 B raw / 15 B
transfer. Both are ordinary feature growth on chunks the startup set
already loads; the chunk count is unchanged.

## Change

`BUDGET` in `studio/frontend/scripts/check-bundle-budget.ts` is raised
to the main build plus the same 160 B raw / 189 B transfer margin as
earlier raises: `rawBytes` 6,844,782 and `transferBytes` 2,061,229. A
comment entry records the numbers above.

## Testing

- `npm ci && npm run build && npx tsx scripts/check-bundle-budget.ts` on
this branch: `within budget (0.2 KB transfer, 0.2 KB raw to spare)`. On
main, the over-budget output above.
- #14316 (catalog `fetchedFrom`) builds to the identical byte count on
top of main, so it fits under this budget as well.
danielhanchen added a commit that referenced this pull request Oct 22, 2026
…piling or recapturing (#14692)

## Summary

A torchao int8/fp8 load in Studio bakes its LoRA adapters before
quantize and compile. Since #14312, a later prompt can drop one of the
baked adapters (it runs at weight 0) or change a weight without a
reload. That change only moves the PEFT scale, but the scale is a Python
float read inside the LoRA forward:

- `torch.compile` guards on it (`self.scaling['lora_b'] == 1.0`), so
each new weight vector compiles the denoiser again.
- A CUDA graph records it as a kernel argument, so `_adjust_baked_loras`
calls `cuda_graph.reset_all` and the next prompt captures every graph
again. This also happens when you go back to a selection that was
already compiled.

The adapters and their shapes never change on a baked load, so neither
cost is needed.

## Change

- `_pin_baked_lora_scales`: once the denoiser is placed, and before
anything compiles or captures, each baked `scaling[adapter]` is stored
as a 0-d float32 tensor on the device of its LoRA weights. Compiled code
takes that tensor as a graph input, not as a guarded constant, and a
captured graph reads it from memory when it replays.
- `_adjust_baked_loras` writes the new weights into those tensors in
place (`fill_`) for a subset change, a weight change or turning
everything off. It skips `set_adapters` and the graph reset.
- In these cases the old `set_adapters` + `reset_all` path is still
used:
- an offloaded denoiser (hooks move the LoRA weights off the scale's
device)
  - LoRA weights that are not on the target device type
  - a scale that something has written back as a float
- CFG-parallel replica: `build_replica` copies the pinned tensors to the
replica's card. `weights_fingerprint` now reads their identity and
version counter rather than `repr`, so a write still rebuilds the
replica, and there is no device read on each call.

## Evidence

Tiny FLUX.2 klein (`Flux2Transformer2DModel`, random weights) loaded
through `DiffusionBackend.begin_load` with `transformer_quant="int8"`,
`speed_mode="max"` (compiled + CUDA graph), and two random rank-4 LoRAs
baked on every attention / FF Linear. 256x256, 4 steps, same seed.
Counts are per prompt.

| Prompt | main: new Dynamo graphs | main: graph captures | this PR: new
Dynamo graphs | this PR: graph captures |
|---|---|---|---|---|
| P1 A+B (first) | 2 | 1 | 2 | 1 |
| P2 A+B (repeat) | 0 | 0 | 0 | 0 |
| P3 A only (subset) | 2 (recompile) | 1 | 0 | 0 |
| P4 A+B (back) | 0 | 1 | 0 | 0 |
| P5 A only (again) | 0 | 1 | 0 | 0 |
| P6 A=0.5, B=1 | 2 (recompile) | 1 | 0 | 0 |
| P7 A+B (back) | 0 | 1 | 0 | 0 |
| P8 all off | 0 | 1 | 0 | 0 |
| P9 A+B (back) | 0 | 1 | 0 | 0 |

On main, the recompile reason is the guard on `result = result +
lora_B(lora_A(dropout(x))) * scaling`. Every changed prompt captures the
graph again, even for a selection that was already compiled. With this
change, nothing recompiles or recaptures after the first prompt. On both
arms the images match: P2, P4 and P9 equal P1, P5 equals P3, and P3 and
P6 differ from P1.

Unit test
`test_baked_lora_subset_and_weight_changes_keep_compiled_graphs` uses a
real PEFT `lora.Linear` with two adapters under `torch.compile` and goes
through the real `_apply_loras`. It fails on main (`frame_count` 3,
expected 1) and passes with this change. On CPU with the change,
`tests/test_diffusion_lora.py` plus the multi-GPU wiring suites give 147
passed, 4 skipped.

## Not covered

- Offloaded (model / group / sequential) loads keep the previous
behaviour by design.
- CFG-parallel on two cards and layer-split were not run on GPUs, only
the replica fingerprint unit test.
- If diffusers' `scale_lora_layers` is called with a non-1
`attention_kwargs["scale"]`, it would scale the pinned tensor in place
and then unscale it. Studio does not pass that kwarg.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 25, 2026
)

Fixes unslothai#15241

## Problem

With FLUX.3 Image Klein loaded, Images > Edit is greyed out. Black
Forest Labs ship the model for editing: the model card describes it as
"text-to-image generation and image editing", and BFL's own ComfyUI
templates (`black-forest-labs/flux-3-image-klein-comfy`) include `i2i`
and `mi2i` edit workflows next to `t2i`. Studio only offered that call
under Reference. Reference also renders at the page's size, not the
source's, so editing a 16:9 photo with the page at 1:1 gave a square
result with the scene extended (noted as a known limit in unslothai#14312).

## What changes

FLUX.3 Klein (distilled and base) now lists Edit, which runs the same
reference call as before: Image 1 is the source, extra images follow in
order, and the output size defaults to "Match Image 1".

- **Backend.** A new family flag, `reference_edit`, is set on both
FLUX.3 families. The diffusers engine and the native sd.cpp engine add
`edit` to the workflows for those families and accept `workflow =
"edit"`, which takes the reference path. The status reports
`unified_edit: true`, so the page shows its existing Edit form (Image 1,
Add image 2, Output size). `localized_edit_modes` stays empty, and
`localized_edit` is still refused for anything but Qwen-Image-2.1.
- **Frontend.** The "Ask for a transparent background" button now
depends on localized edit modes being available, so it stays on
Qwen-Image-2.1 and does not appear for FLUX.3 (RGB VAE). A Localize mode
picked on Qwen-Image-2.1 is ignored once a model without that mode is
loaded, so it cannot reach a request the backend refuses. "Edit image"
from the gallery or Library now opens Edit for FLUX.3 instead of
Reference.

## Not changed

- Reference for FLUX.3 runs exactly as before, and so does the Enhance
prompt step: the upsampler already picks its `i2i` prompt whenever
images are attached.
- FLUX.2 klein, Qwen-Image-2.1, Qwen-Image-Edit, Kontext and every other
family keep their workflow lists and conditioning fields. The native
transparency notes are now gated on `unified_edit` directly, which
matches what they did before.
- Inpaint, Transform, Extend and Upscale stay disabled for FLUX.3.

## Tests

- `test_sd_cpp_flux3.py`: the native status lists `txt2img, reference,
edit`, a native edit passes both images to sd.cpp, and `localized_edit`
is refused.
- `test_diffusion_unified_edit.py`: `_family_workflows` and the
conditioning fields for both FLUX.3 families, FLUX.2 klein unchanged,
and an edit on the diffusers engine hands the pipeline the same images
and size as Reference.
- `test_diffusion_flux3.py`: both family records carry `reference_edit`.

## Before / after

Fresh Studio installs at the merge base (`2c81e9f`) and at this branch
(`50cc980`, code-identical to the current head), each with
`unsloth/flux-3-image-klein-GGUF` UD-Q4_K_XL loaded. This host has no
GPU, so both loads ran on the native sd.cpp engine.

| | Before | After |
|---|---|---|
| Workflows in the status | `txt2img, reference` | `txt2img, reference,
edit` |
| Sidebar Images > Edit | disabled | enabled, opens the Edit form (Image
1, Output size "Match Image 1"; no Localize, no transparent-background
button) |
| `POST /api/inference/images/generate` with `workflow = "edit"` | 400:
"Image editing is not available for 'flux.3-klein' on the native sd.cpp
engine with this build and its assets." | 200, one 384x256 image,
`workflow: edit` |

<img
src="https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/15263/pr15263_before_after-435acced3101.png"
alt="Images page with FLUX.3 Klein loaded, before and after"
width="100%">

The edit from the last row ("make the yellow circle red", 4 steps,
Enhance off):

<img
src="https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/15263/pr15263_edit_result-e1abb26ecaf5.png"
alt="Source image and the FLUX.3 Klein edit result" width="70%">
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