Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio Images: Compare grid counts Hires CFG when sending the negative prompt and records Hires settings (#14875)

Daniel Han63ac1224a75a
diff --git a/studio/frontend/src/features/images/compare/compare-axes.ts b/studio/frontend/src/features/images/compare/compare-axes.ts
index da82da422c6..c024c796a47 100644
--- a/studio/frontend/src/features/images/compare/compare-axes.ts
+++ b/studio/frontend/src/features/images/compare/compare-axes.ts
@@ -46,6 +46,8 @@ export interface CompareContext {
loras: ReadonlyArray<{ id: string; weight: number; label: string }>;
sdControls?: CompareSdControls | null;
controlnetEngaged: boolean;
+ // Hires CFG makes the refine pass read the negative prompt at any base CFG; no axis varies Hires, so it is grid-wide.
+ hiresEngagesNegative?: boolean;
}
type Value = number | string;
@@ -361,7 +363,7 @@ export function planCompare(
}
/** Combinations no cell may run: a Prompt S/R term a cell's text lacks once the earlier axes' substitutions ran
- * (A1111 apply_prompt raises per cell; a negative prompt counts only where that cell's CFG engages it), or a
+ * (A1111 apply_prompt raises per cell; a negative prompt counts only where that cell's CFG, or Hires CFG, engages it), or a
* Schedule type, from an axis or the form, the cell's sampler does not take (the backend would run Automatic under a
* Karras label). */
function cellProblem(plan: CompareGridPlan, ctx: CompareContext): string | null {
@@ -396,7 +398,10 @@ function cellProblem(plan: CompareGridPlan, ctx: CompareContext): string | null
}
function negativeEngaged(ctx: CompareContext, guidance: number): boolean {
- return ctx.negativeCapable && (ctx.negativeMinGuidance === null || guidance > ctx.negativeMinGuidance);
+ return (
+ ctx.negativeCapable &&
+ (ctx.negativeMinGuidance === null || guidance > ctx.negativeMinGuidance || ctx.hiresEngagesNegative === true)
+ );
}
/** The negative prompt the grid's recipe records: the form's text when any cell runs with it engaged. */
@@ -447,9 +452,7 @@ export function buildCellRequest(
if (cell.steps !== undefined) req.steps = cell.steps;
if (cell.guidance !== undefined) {
req.guidance = cell.guidance;
- const engaged =
- ctx.negativeCapable && (ctx.negativeMinGuidance === null || cell.guidance > ctx.negativeMinGuidance);
- req.negative_prompt = engaged ? ctx.negativePrompt.trim() || undefined : undefined;
+ req.negative_prompt = negativeEngaged(ctx, cell.guidance) ? ctx.negativePrompt.trim() || undefined : undefined;
}
if (cell.sampler !== undefined || cell.schedule !== undefined) {
const sampler = cell.sampler ?? ctx.samplerChoice.sampler;
diff --git a/studio/frontend/src/features/images/compare/compare-run.ts b/studio/frontend/src/features/images/compare/compare-run.ts
index 30394367c22..019517e7f35 100644
--- a/studio/frontend/src/features/images/compare/compare-run.ts
+++ b/studio/frontend/src/features/images/compare/compare-run.ts
@@ -5,6 +5,7 @@
* back. The page keeps owning progress polling, Stop, the gallery merge and error toasts. */
import type { ControlNetSpecInput, DiffusionGenerateRequest, GalleryImage } from "../api.ts";
+import { HIRES_UPSCALER_LABELS, type HiresRequest } from "../lib/hires-choice.ts";
import { SAMPLER_LABELS, SCHEDULE_LABELS } from "../lib/sampler-choice.ts";
import { gridInfotext } from "./compose-grid.ts";
import { joinAxisList } from "./compare-values.ts";
@@ -143,6 +144,21 @@ function controlNetUnit(value: unknown): string | undefined {
return parts.join(", ");
}
+const sameHires = (a: unknown, b: unknown): boolean => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
+
+/** Hires fields in A1111 names (diffusion_hires.infotext_fields); Size stays the base pass. */
+function hiresFields(hires: HiresRequest | undefined): Array<[string, string | number | undefined]> {
+ if (!hires) return [];
+ const upscaler = hires.upscaler ? (HIRES_UPSCALER_LABELS[hires.upscaler] ?? hires.upscaler.replace(/^local:/, "")) : undefined;
+ return [
+ ["Denoising strength", hires.denoise],
+ ["Hires upscale", hires.scale],
+ ["Hires steps", hires.steps ? hires.steps : undefined],
+ ["Hires upscaler", upscaler],
+ ["Hires CFG Scale", hires.guidance ?? undefined],
+ ];
+}
+
/** The grid's shared recipe for its `parameters` chunk, from the requests the cells were sent with: a field is
* written only when every cell ran the same value, so the PNG never claims one cell's setting for the grid. */
export function gridRecipeFields(
@@ -181,6 +197,7 @@ export function gridRecipeFields(
["ControlNet 0", controlNetUnit(sharedValue(sent, varied, "controlnet", "controlnet", sameControlNet)?.value)],
// Every cell runs with the prompt enhancer off (compare/ forces it), so a restore must not rewrite the prompt.
["Prompt enhancement", sharedValue(sent, varied, "enhance_prompt")?.value === false ? "off" : undefined],
+ ...hiresFields(sharedValue(sent, varied, "hires", "hires", sameHires)?.value as HiresRequest | undefined),
];
return fields.filter(([, value]) => value !== undefined);
}
diff --git a/studio/frontend/src/features/images/images-page.tsx b/studio/frontend/src/features/images/images-page.tsx
index 2425e4226a5..c0298cb0cfd 100644
--- a/studio/frontend/src/features/images/images-page.tsx
+++ b/studio/frontend/src/features/images/images-page.tsx
@@ -5652,12 +5652,13 @@ export function ImagesPage({
label: availableLoras.find((a) => a.id === l.id)?.display_name ?? l.id.split(/[\\/]/).pop() ?? l.id,
})),
sdControls: compareSdControls,
+ hiresEngagesNegative: hiresEngagesNegative(hires, hiresCapability, workflow, negativeMinGuidance),
// The predicate the request uses (strength 0 runs plain text-to-image, where CFG rescale applies).
controlnetEngaged,
}),
// samplerChoice is rebuilt every render; its two fields are what matter.
// eslint-disable-next-line react-hooks/exhaustive-deps
- [prompt, negativePrompt, negativeCapable, negativeMinGuidance, guidanceFixed, effectiveGuidance, samplerOptions, samplerChoice.sampler, samplerChoice.scheduleType, shiftControl, loraCapable, loras, availableLoras, compareSdControls, controlnetEngaged],
+ [prompt, negativePrompt, negativeCapable, negativeMinGuidance, guidanceFixed, effectiveGuidance, samplerOptions, samplerChoice.sampler, samplerChoice.scheduleType, shiftControl, loraCapable, loras, availableLoras, compareSdControls, controlnetEngaged, hires, hiresCapability, workflow],
);
const handleGenerateWithRecall = useCallback(async () => {
diff --git a/studio/frontend/tests/images-compare-grid.test.ts b/studio/frontend/tests/images-compare-grid.test.ts
index 893b552677a..33d2ac1da13 100644
--- a/studio/frontend/tests/images-compare-grid.test.ts
+++ b/studio/frontend/tests/images-compare-grid.test.ts
@@ -10,6 +10,7 @@ import {
buildCellRequest,
cellCoords,
executionOrder,
+ gridNegativePrompt,
MAX_COMPARE_CELLS,
planCompare,
type CompareContext,
@@ -915,6 +916,7 @@ test("sampler x schedule table: every cell must take its effective schedule, the
test("compare wiring: the request's ControlNet predicate gates CFG rescale; a failed save is reported", () => {
const page = readSrc("features/images/images-page.tsx");
assert.match(page, /\n\s+controlnetEngaged,\n\s+\}\),/);
+ assert.match(page, /hiresEngagesNegative: hiresEngagesNegative\(hires, hiresCapability, workflow, negativeMinGuidance\),/);
assert.doesNotMatch(page, /controlnetEngaged: Boolean\(controlnetCapable && controlnetId && controlImage\)/);
// A strength-0 ControlNet is not engaged, so the axis stays (the axes only read the flag).
const sdControls = { clip_skip: null, cfg_rescale: { min: 0, max: 1 }, variation_seed: false } as never;
@@ -944,3 +946,39 @@ test("an invalid typed Variation seed is refused for a compare run at any form s
const page = readSrc("features/images/images-page.tsx");
assert.match(page, /const checkVariation = varying \|\| \(compareOnce\.current !== null && Boolean\(sdCaps\?\.variation_seed\)\);\n\s+if \(checkVariation && runChoice\.variationSeed\.trim\(\) && parseVariationSeed\(runChoice\.variationSeed\) === null\) \{\n\s+toast\.error/);
});
+
+test("Hires CFG keeps the negative prompt on a CFG cell whose base guidance leaves it off, as Generate does", () => {
+ const hires = { scale: 1.5, denoise: 0.5, steps: null, upscaler: "latent", guidance: 7 };
+ const g = plan([{ axisId: "guidance", text: "1, 7" }]);
+ const seeds = { base: 1, keepRandom: false, seedFieldEmpty: false };
+ const ctx = sdxl({ hiresEngagesNegative: true });
+ assert.equal(buildCellRequest(g, 0, base({ hires }), ctx, seeds).negative_prompt, "blurry");
+ assert.equal(buildCellRequest(g, 1, base({ hires }), ctx, seeds).negative_prompt, "blurry");
+ assert.equal(buildCellRequest(g, 0, base(), sdxl(), seeds).negative_prompt, undefined);
+ // A negative-only S/R term at base CFG 1 is read by the refine pass, so not refused.
+ const sr = sdxl({ prompt: "a fox", negativePrompt: "red eyes", guidance: 1 });
+ assert.equal(planCompare([{ axisId: "prompt_sr", text: "red, blue" }], sr).ok, false);
+ assert.ok(planCompare([{ axisId: "prompt_sr", text: "red, blue" }], { ...sr, hiresEngagesNegative: true }).ok);
+ const off = plan([{ axisId: "steps", text: "10, 20" }], { ...sr, negativePrompt: "blurry" });
+ assert.equal(gridNegativePrompt(off, { ...sr, negativePrompt: "blurry" }), undefined);
+ assert.equal(gridNegativePrompt(off, { ...sr, negativePrompt: "blurry", hiresEngagesNegative: true }), "blurry");
+});
+
+test("grid metadata records the Hires fix every cell ran, in A1111 names, and drops it when cells differ", () => {
+ const steps = plan([{ axisId: "steps", text: "10, 20" }]);
+ const form = { steps: 25, guidance: 6, width: 1024, height: 1024, model: "m" };
+ const hires = { scale: 1.5, denoise: 0.5, steps: 12, upscaler: "latent", guidance: 7 };
+ const fields = Object.fromEntries(gridRecipeFields(steps, [base({ hires }), base({ hires: { ...hires } })], form));
+ assert.equal(fields.Size, "1024x1024");
+ assert.equal(fields["Denoising strength"], 0.5);
+ assert.equal(fields["Hires upscale"], 1.5);
+ assert.equal(fields["Hires steps"], 12);
+ assert.equal(fields["Hires upscaler"], "Latent (nearest-exact)");
+ assert.equal(fields["Hires CFG Scale"], 7);
+ const parsed = parseA1111Parameters(gridParameters(steps, sdxl(), [base({ hires })], { ...form, keepRandomSeeds: false }));
+ assert.equal(parsed?.hires_scale, 1.5);
+ assert.equal(parsed?.hires_guidance, 7);
+ const mixed = Object.fromEntries(gridRecipeFields(steps, [base({ hires }), base()], form));
+ assert.equal("Hires upscale" in mixed, false);
+ assert.equal("Hires upscale" in Object.fromEntries(gridRecipeFields(steps, [base()], form)), false);
+});