Skip to content

Unsloth Studio / Desktop: the Images page Compare grid, for API callers (server-rendered X/Y grid, no UI change) - #15169

Merged
danielhanchen merged 15 commits into
unslothai:mainfrom
LeoBorcherding:studio/images-xy-grid
Nov 7, 2026
Merged

danielhanchen merged 15 commits into
unslothai:mainfrom
LeoBorcherding:studio/images-xy-grid

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #10695.

This is the API version of a feature the Images page already has. In the app, Images > Create > Compare grid (#14624) already varies two settings and lays the results out as a grid; this PR adds no button and changes nothing in the UI. What it adds is the same grid for anything that is not the browser: POST /api/inference/images/generate takes an optional xy spec and the server renders the cells and composes the labelled grid. Leave xy out and the request runs exactly as on main; the response only gains two empty fields, grid: null and, on each gallery record, xy_grid: null.

Why it is worth having next to Compare: Compare renders in the browser, so scripts and other API clients can't use it, and its grid PNG is download-only. Here the grid and every cell land in the gallery with their own recipes.

Changes in this PR

  • xy is optional: up to two axes, each a field and a list of values. Axis fields are an allowlist: seed, steps, guidance, sampler, schedule_type, shift, base_shift, max_shift, strength, clip_skip, cfg_rescale, variation_seed, variation_strength, a LoRA weight by index, and Prompt S/R. 64-cell cap, same as Compare.
  • Every cell is validated as a full generate request before anything renders (a bad value is a 400 naming the cell), rendered on one shared seed unless seed is an axis, and saved to the gallery as a normal image with its own recipe.
  • One extra labelled grid PNG (A1111 layout) is saved to the gallery and returned as grid, on top of the cells, not instead of them.
  • A frontend test keeps the TS field list, the Compare axes and the server allowlist in sync.
  • A Stop pressed while the grid is between two cells (a cell saving, the next not started yet) ends the grid with the usual cancelled 409; the cells already rendered stay in the gallery. POST /images/generate/cancel reports cancelled: true for it.
  • The grid record keeps its real pixel size in width / height and adds xy_grid.cell_width / cell_height; reusing the grid's settings on the Images page restores the cell size instead of the grid's.
  • Robustness from review: a LoRA sent without a weight keeps its default 1.0; a variation-strength sweep shares one variation seed; cells keeping any active adapter render before adapter-free ones (a deferred Speed Auto compile then cannot refuse a later LoRA cell); a Stop also reaches a cell still queued for the engine and one landing after the last cell; the canvas, label bands included, stays under the 32 MP budget and each cell is held at its share of it while later cells render; layered models (one call, several layers) are refused with a 400 up front.

Test matrix

where what ran result
Colab T4 high-RAM, Linux, 3879b43 Z-Image-Turbo Q4_K_M, steps 4/8/12 x guidance 0/1.5/3, seed 42, 768px, over the API 200 in 303.8 s, 9 cells plus a 2880x2441 labelled grid, all in the gallery
Colab L4, Linux, main 5a04ef7 same request 200, xy ignored, one image (byte-identical to the steps 8 / guidance 0 cell)
Apple M5 Mac, 3879b43 test_diffusion_xy.py, frontend parity test, typecheck pass

Screenshots
The existing in-app way, unchanged by this PR: the Compare grid switch at the bottom of the Create panel.

The API request and the grid it returned:

That grid saved to the gallery, with the 9 cells beside it as normal images:

Not tested

  • Sampler as an axis on a real GPU: Z-Image-Turbo offers no sampler choices on this base.
  • The Compare grid's own PNG still isn't saved to the gallery; out of scope here.

Branch merged with main at b6fc821; tests and typecheck rerun after the merge. The test_diffusion_routes.py failures (6, cancel_generate() ... expected_account) fail identically on main b6fc821.

Restore these settings on a grid image (before / after)
A grid image seeded into the gallery as /images/generate saves it (2880x2441 grid of 768x768 cells), then Recipe > Restore these settings. Before, the size controls take a size scaled from the grid; after, the cell size.

… gallery, labelled grid image)

POST /images/generate takes an optional xy spec: up to two axes over an
allowlist of request fields (seed, steps, guidance, sampler, schedule_type,
shift, base/max shift, strength, clip_skip, cfg_rescale, variation seed and
strength, a LoRA weight by index, Prompt S/R). The server expands the cells,
validates each as a full generate request, renders them on one shared seed,
saves each to the gallery with its own recipe and saves one labelled grid
PNG, returned as grid. 64 cells max, the Images page Compare grid's cap.
# Conflicts:
#	studio/backend/models/inference.py
#	studio/backend/routes/inference.py
@danielhanchen

Copy link
Copy Markdown
Member

The (Python 3.13, g-r) red is from this PR, not main: studio/backend/tests/test_liveness_reports_inference_active.py::test_both_image_routes_publish_the_persist_marker reports

'_generate_xy_grid: moves the persist marker outside the image routes'

The check reads routes/inference.py and only accepts _diffusion_persist_active changes inside the two known image routes (_PERSIST_ROUTES). The new _generate_xy_grid raises and drops the marker itself, so it shows up as an unexpected mutator. If the X/Y grid really does persist gallery records and should count for liveness, add it to _PERSIST_ROUTES in that test, and make sure every exit path drops what it raised (the same balance the test checks for the other two). If it does not persist, it should not touch the marker.

# Conflicts:
#	studio/frontend/src/features/images/api.ts
@LeoBorcherding LeoBorcherding changed the title Unsloth Studio / Desktop: X/Y grid over the generate API, with every cell and a labelled grid image in the gallery Unsloth Studio / Desktop: the Images page Compare grid, for API callers (server-rendered X/Y grid, no UI change) Oct 27, 2026
@danielhanchen danielhanchen self-assigned this Nov 7, 2026
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-07T18:01:19.340474Z
We couldn’t complete this review. Comment @codex review to try again.
343159c Draft marked ready
ℹ️ 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[bot]

This comment was marked as resolved.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 49ac16a2f3

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 7, 2026
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 7, 2026
@danielhanchen
danielhanchen marked this pull request as ready for review November 7, 2026 18:01
@danielhanchen
danielhanchen self-requested a review as a code owner November 7, 2026 18:01
@danielhanchen
danielhanchen merged commit 5f1d555 into unslothai:main Nov 7, 2026
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.

2 participants