Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(webv2): add conditioning rebalance core module

joshistoastcc37b79989b6
diff --git a/invokeai/frontend/webv2/src/features/generation/core/conditioningRebalance.test.ts b/invokeai/frontend/webv2/src/features/generation/core/conditioningRebalance.test.ts
new file mode 100644
index 0000000000..7c4b035494
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/conditioningRebalance.test.ts
@@ -0,0 +1,192 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ adjustRebalanceWeight,
+ barFillFraction,
+ BUILTIN_REBALANCE_PRESETS,
+ DEFAULT_KREA2_REBALANCE_MULTIPLIER,
+ DEFAULT_KREA2_REBALANCE_WEIGHTS,
+ getRebalanceBarScale,
+ getRebalanceSparklinePath,
+ isValidKrea2RebalanceWeights,
+ KREA2_REBALANCE_WEIGHT_COUNT,
+ KREA2_TAP_LAYERS,
+ matchRebalancePreset,
+ NEUTRAL_KREA2_REBALANCE_WEIGHTS,
+ normalizeRebalancePresets,
+ parseRebalanceWeights,
+ REBALANCE_WEIGHT_STEP,
+ REBALANCE_WEIGHT_TRACK_MAX,
+ serializeRebalanceWeights,
+ weightFromTrackFraction,
+} from './conditioningRebalance';
+
+describe('KREA2_TAP_LAYERS', () => {
+ it('matches the encoder layers the backend taps', () => {
+ // KREA2_SELECT_LAYERS in invokeai/backend/krea2/sampling_utils.py.
+ expect([...KREA2_TAP_LAYERS]).toEqual([2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35]);
+ });
+
+ it('has one entry per weight', () => {
+ expect(KREA2_TAP_LAYERS).toHaveLength(KREA2_REBALANCE_WEIGHT_COUNT);
+ });
+});
+
+describe('parseRebalanceWeights', () => {
+ it('parses the backend default vector', () => {
+ expect(parseRebalanceWeights(DEFAULT_KREA2_REBALANCE_WEIGHTS)).toEqual([1, 1, 1, 1, 1, 1, 1, 2.5, 5, 1.1, 4, 1]);
+ });
+
+ it('accepts the decimal forms Python float() accepts', () => {
+ expect(parseRebalanceWeights('1,.5,+2.5,1e-3,2.,0,1,1,1,1,1,1')).toEqual([
+ 1, 0.5, 2.5, 0.001, 2, 0, 1, 1, 1, 1, 1, 1,
+ ]);
+ });
+
+ it('tolerates surrounding whitespace', () => {
+ expect(parseRebalanceWeights(' 1.0 , 1.0 ,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0 ')).toHaveLength(12);
+ });
+
+ it('rejects hex, which Number() accepts but Python float() does not', () => {
+ // The string is forwarded verbatim to the node, so accepting it here would only
+ // move the failure to mid-generation.
+ expect(parseRebalanceWeights('0x10,1,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ expect(parseRebalanceWeights('0b11,1,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ expect(parseRebalanceWeights('0o17,1,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ });
+
+ it('rejects non-finite values', () => {
+ expect(parseRebalanceWeights('1e999,1,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ expect(parseRebalanceWeights('NaN,1,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ expect(parseRebalanceWeights('Infinity,1,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ });
+
+ it('rejects empty entries and the wrong count', () => {
+ expect(parseRebalanceWeights('1,,1,1,1,1,1,1,1,1,1,1')).toBeNull();
+ expect(parseRebalanceWeights('1,1,1')).toBeNull();
+ expect(parseRebalanceWeights(`${DEFAULT_KREA2_REBALANCE_WEIGHTS},1.0`)).toBeNull();
+ expect(parseRebalanceWeights('')).toBeNull();
+ });
+
+ it('backs isValidKrea2RebalanceWeights', () => {
+ expect(isValidKrea2RebalanceWeights(DEFAULT_KREA2_REBALANCE_WEIGHTS)).toBe(true);
+ expect(isValidKrea2RebalanceWeights('0x10,1,1,1,1,1,1,1,1,1,1,1')).toBe(false);
+ });
+});
+
+describe('serializeRebalanceWeights', () => {
+ it('round-trips the backend default string exactly', () => {
+ const parsed = parseRebalanceWeights(DEFAULT_KREA2_REBALANCE_WEIGHTS);
+
+ expect(parsed).not.toBeNull();
+ expect(serializeRebalanceWeights(parsed ?? [])).toBe(DEFAULT_KREA2_REBALANCE_WEIGHTS);
+ });
+
+ it('keeps drag output free of float dust', () => {
+ expect(serializeRebalanceWeights([0.1 + 0.2])).toBe('0.3');
+ expect(serializeRebalanceWeights([2])).toBe('2.0');
+ });
+
+ it('produces a neutral vector that parses back to all ones', () => {
+ expect(parseRebalanceWeights(NEUTRAL_KREA2_REBALANCE_WEIGHTS)).toEqual(Array.from({ length: 12 }, () => 1));
+ });
+});
+
+describe('bar geometry', () => {
+ it('uses the nominal ceiling until a weight overshoots it', () => {
+ expect(getRebalanceBarScale([1, 2, 5])).toBe(REBALANCE_WEIGHT_TRACK_MAX);
+ expect(getRebalanceBarScale([1, 12.5, 5])).toBe(12.5);
+ });
+
+ it('maps the track top to full scale and the bottom to zero', () => {
+ expect(weightFromTrackFraction(0, 8)).toBe(8);
+ expect(weightFromTrackFraction(1, 8)).toBe(0);
+ expect(weightFromTrackFraction(0.5, 8)).toBe(4);
+ });
+
+ it('clamps pointer positions that leave the track', () => {
+ expect(weightFromTrackFraction(-0.5, 8)).toBe(8);
+ expect(weightFromTrackFraction(1.5, 8)).toBe(0);
+ });
+
+ it('inverts barFillFraction on the step grid', () => {
+ const scale = REBALANCE_WEIGHT_TRACK_MAX;
+
+ for (let step = 0; step <= scale / REBALANCE_WEIGHT_STEP; step += 1) {
+ const weight = Math.round(step * REBALANCE_WEIGHT_STEP * 10) / 10;
+
+ expect(weightFromTrackFraction(1 - barFillFraction(weight, scale), scale)).toBe(weight);
+ }
+ });
+
+ it('snaps adjustments back onto the step grid', () => {
+ expect(adjustRebalanceWeight(1.1, REBALANCE_WEIGHT_STEP, 8)).toBe(1.2);
+ expect(adjustRebalanceWeight(2.5, -REBALANCE_WEIGHT_STEP * 2, 8)).toBe(2.3);
+ expect(adjustRebalanceWeight(0, -1, 8)).toBe(0);
+ expect(adjustRebalanceWeight(8, 1, 8)).toBe(8);
+ });
+});
+
+describe('getRebalanceSparklinePath', () => {
+ it('emits one point per weight, taller weights higher up', () => {
+ const path = getRebalanceSparklinePath([0, 8], 100, 14);
+ const [start, end] = path.split(' L');
+
+ expect(start).toBe('M0 13');
+ expect(end).toBe('100 1');
+ });
+
+ it('returns an empty path for an empty vector', () => {
+ expect(getRebalanceSparklinePath([], 100, 14)).toBe('');
+ });
+});
+
+describe('presets', () => {
+ it('ships the backend defaults and a neutral pass', () => {
+ expect(BUILTIN_REBALANCE_PRESETS.map((preset) => preset.id)).toEqual(['default', 'neutral']);
+ expect(BUILTIN_REBALANCE_PRESETS[0]?.weights).toBe(DEFAULT_KREA2_REBALANCE_WEIGHTS);
+ expect(BUILTIN_REBALANCE_PRESETS[0]?.multiplier).toBe(DEFAULT_KREA2_REBALANCE_MULTIPLIER);
+ expect(BUILTIN_REBALANCE_PRESETS[1]?.multiplier).toBe(1);
+ });
+
+ it('matches on the parsed vector, not the string spelling', () => {
+ expect(matchRebalancePreset(BUILTIN_REBALANCE_PRESETS, DEFAULT_KREA2_REBALANCE_WEIGHTS, 4)).toBe('default');
+ expect(matchRebalancePreset(BUILTIN_REBALANCE_PRESETS, '1,1,1,1,1,1,1,2.5,5,1.1,4,1', 4)).toBe('default');
+ });
+
+ it('reports no match once the gain or a weight is edited', () => {
+ expect(matchRebalancePreset(BUILTIN_REBALANCE_PRESETS, DEFAULT_KREA2_REBALANCE_WEIGHTS, 4.5)).toBeNull();
+ expect(
+ matchRebalancePreset(BUILTIN_REBALANCE_PRESETS, '1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.5,5.0,1.1,4.0,1.5', 4)
+ ).toBeNull();
+ expect(matchRebalancePreset(BUILTIN_REBALANCE_PRESETS, 'not weights', 4)).toBeNull();
+ });
+
+ it('drops persisted entries that no longer parse', () => {
+ const presets = normalizeRebalancePresets([
+ { id: 'a', label: 'Keep', multiplier: 2, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS },
+ { id: 'b', label: 'Bad weights', multiplier: 2, weights: '1,2,3' },
+ { id: 'c', label: ' ', multiplier: 2, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS },
+ { id: 'd', label: 'Bad gain', multiplier: Number.NaN, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS },
+ null,
+ 'nope',
+ ]);
+
+ expect(presets.map((preset) => preset.id)).toEqual(['a']);
+ });
+
+ it('drops duplicate ids and ids that shadow a built-in', () => {
+ const presets = normalizeRebalancePresets([
+ { id: 'a', label: 'First', multiplier: 1, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS },
+ { id: 'a', label: 'Duplicate', multiplier: 1, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS },
+ { id: 'default', label: 'Shadow', multiplier: 1, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS },
+ ]);
+
+ expect(presets).toEqual([{ id: 'a', label: 'First', multiplier: 1, weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS }]);
+ });
+
+ it('returns an empty list for a non-array blob', () => {
+ expect(normalizeRebalancePresets(undefined)).toEqual([]);
+ expect(normalizeRebalancePresets({ id: 'a' })).toEqual([]);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/generation/core/conditioningRebalance.ts b/invokeai/frontend/webv2/src/features/generation/core/conditioningRebalance.ts
new file mode 100644
index 0000000000..94dcae8552
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/generation/core/conditioningRebalance.ts
@@ -0,0 +1,252 @@
+/**
+ * Krea-2 conditioning rebalance: the per-tap weight vector, its presets, and the
+ * geometry the bar editor drags against.
+ *
+ * Krea-2 stacks twelve Qwen3-VL hidden-state layers per token into
+ * `prompt_embeds (B, seq, 12, hidden)`, and the backend node applies
+ * `embeds * gains * multiplier` — a flat elementwise gain, not a frequency
+ * decomposition. Weighting the shallow taps favours the prompt's literal wording;
+ * weighting the deep taps favours its meaning and composition.
+ *
+ * Pure module: no React, no Chakra, no transport (see `src/architecture/dependencyPolicy.ts`).
+ */
+
+/**
+ * The encoder layers tapped into the conditioning, shallow to deep.
+ * Source of truth: `KREA2_SELECT_LAYERS` in `invokeai/backend/krea2/sampling_utils.py`.
+ */
+export const KREA2_TAP_LAYERS: readonly number[] = [2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35];
+
+export const KREA2_REBALANCE_WEIGHT_COUNT: number = KREA2_TAP_LAYERS.length;
+
+/** Backend defaults from `Krea2ConditioningRebalanceInvocation`. */
+export const DEFAULT_KREA2_REBALANCE_WEIGHTS = '1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.5,5.0,1.1,4.0,1.0';
+export const DEFAULT_KREA2_REBALANCE_MULTIPLIER = 4;
+
+export const REBALANCE_WEIGHT_MIN = 0;
+/**
+ * The drag track's nominal ceiling. Values above it are still legal — the track
+ * rescales to fit them (`getRebalanceBarScale`) rather than clipping the bars.
+ */
+export const REBALANCE_WEIGHT_TRACK_MAX = 8;
+/** Weights read as "no change" here; the editor draws a rule at this level. */
+export const REBALANCE_NEUTRAL_WEIGHT = 1;
+
+/** Dragged weights quantize to one decimal, which keeps float dust out of the serialized string. */
+const WEIGHT_QUANTUM = 10;
+export const REBALANCE_WEIGHT_STEP = 1 / WEIGHT_QUANTUM;
+
+/**
+ * Accepts exactly what Python's `float()` accepts. `Number()` additionally parses
+ * hex/binary/octal literals, so `0x10` would pass a `Number.isFinite` check here and
+ * then fail inside the node's `_parse_weights()` mid-generation.
+ */
+const DECIMAL_NUMBER_RE = /^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/;
+
+/** Parses the stored comma string, or null when the backend would reject it. */
+export const parseRebalanceWeights = (value: string): number[] | null => {
+ const parts = value.split(',');
+
+ if (parts.length !== KREA2_REBALANCE_WEIGHT_COUNT) {
+ return null;
+ }
+
+ const weights: number[] = [];
+
+ for (const part of parts) {
+ const trimmed = part.trim();
+
+ if (!DECIMAL_NUMBER_RE.test(trimmed)) {
+ return null;
+ }
+
+ const weight = Number(trimmed);
+
+ // `1e999` parses to Infinity here and to `inf` in Python; the node rejects both.
+ if (!Number.isFinite(weight)) {
+ return null;
+ }
+
+ weights.push(weight);
+ }
+
+ return weights;
+};
+
+const formatWeight = (weight: number): string => {
+ const rounded = Math.round(weight * 100) / 100;
+
+ // Integers keep a trailing `.0` so a round trip reproduces the backend's default string.
+ return Number.isInteger(rounded) ? rounded.toFixed(1) : String(rounded);
+};
+
+export const serializeRebalanceWeights = (weights: readonly number[]): string => weights.map(formatWeight).join(',');
+
+/**
+ * Krea-2 rebalance weights are free text forwarded straight to the backend's
+ * `_parse_weights()`. Validating here keeps an unparseable string from reaching a node
+ * that would fail mid-generation.
+ */
+export const isValidKrea2RebalanceWeights = (value: string): boolean => parseRebalanceWeights(value) !== null;
+
+const snapWeight = (weight: number): number => Math.round(weight * WEIGHT_QUANTUM) / WEIGHT_QUANTUM;
+
+const clampWeight = (weight: number, scale: number): number => Math.min(scale, Math.max(REBALANCE_WEIGHT_MIN, weight));
+
+/**
+ * The track's full-scale value: the nominal ceiling, or the tallest weight when a preset
+ * or typed value overshoots it. Rescaling beats clipping — a clipped bar reads as a
+ * different value than it holds.
+ */
+export const getRebalanceBarScale = (weights: readonly number[]): number =>
+ weights.reduce((scale, weight) => Math.max(scale, weight), REBALANCE_WEIGHT_TRACK_MAX);
+
+/** Puts an arbitrary weight onto the step grid and inside the track. */
+export const snapRebalanceWeight = (weight: number, scale: number): number => snapWeight(clampWeight(weight, scale));
+
+/** Pointer position to weight. `fractionFromTop` is 0 at the track's top edge, 1 at its bottom. */
+export const weightFromTrackFraction = (fractionFromTop: number, scale: number): number =>
+ snapRebalanceWeight((1 - fractionFromTop) * scale, scale);
+
+/** Weight to the proportion of the track a bar fills, 0..1. */
+export const barFillFraction = (weight: number, scale: number): number =>
+ scale <= 0 ? 0 : clampWeight(weight, scale) / scale;
+
+/** Applies a keyboard delta, staying on the step grid and inside the track. */
+export const adjustRebalanceWeight = (weight: number, delta: number, scale: number): number =>
+ snapRebalanceWeight(snapWeight(weight) + delta, scale);
+
+const SPARKLINE_INSET = 1;
+
+/**
+ * An SVG path for the collapsed row's preview of the current curve. Rendered into a
+ * `preserveAspectRatio="none"` viewBox, so the inset only keeps the stroke off the edges.
+ */
+export const getRebalanceSparklinePath = (weights: readonly number[], width: number, height: number): string => {
+ if (weights.length === 0) {
+ return '';
+ }
+
+ const scale = getRebalanceBarScale(weights);
+ const usableHeight = Math.max(0, height - SPARKLINE_INSET * 2);
+ const stepX = weights.length === 1 ? 0 : width / (weights.length - 1);
+
+ return weights
+ .map((weight, index) => {
+ const x = Math.round(index * stepX * 100) / 100;
+ const y = Math.round((SPARKLINE_INSET + (1 - barFillFraction(weight, scale)) * usableHeight) * 100) / 100;
+
+ return `${index === 0 ? 'M' : 'L'}${x} ${y}`;
+ })
+ .join(' ');
+};
+
+export interface RebalancePreset {
+ id: string;
+ label: string;
+ weights: string;
+ multiplier: number;
+}
+
+export const REBALANCE_PRESET_DEFAULT_ID = 'default';
+export const REBALANCE_PRESET_NEUTRAL_ID = 'neutral';
+
+/** All taps at 1.0 with unit gain — the rebalance pass as a no-op, for A/B-ing it. */
+export const NEUTRAL_KREA2_REBALANCE_WEIGHTS = Array.from({ length: KREA2_REBALANCE_WEIGHT_COUNT }, () => '1.0').join(
+ ','
+);
+
+/**
+ * Only curves with a basis in the backend ship as built-ins: the node's own defaults and
+ * a neutral pass. A named curve like "Detail" is a tuning claim, and nothing in this repo
+ * measures one — users save their own instead.
+ */
+export const BUILTIN_REBALANCE_PRESETS: readonly RebalancePreset[] = [
+ {
+ id: REBALANCE_PRESET_DEFAULT_ID,
+ label: 'Default',
+ multiplier: DEFAULT_KREA2_REBALANCE_MULTIPLIER,
+ weights: DEFAULT_KREA2_REBALANCE_WEIGHTS,
+ },
+ {
+ id: REBALANCE_PRESET_NEUTRAL_ID,
+ label: 'Neutral',
+ multiplier: 1,
+ weights: NEUTRAL_KREA2_REBALANCE_WEIGHTS,
+ },
+];
+
+const BUILTIN_REBALANCE_PRESET_IDS = new Set(BUILTIN_REBALANCE_PRESETS.map((preset) => preset.id));
+
+export const isRebalancePreset = (value: unknown): value is RebalancePreset => {
+ if (typeof value !== 'object' || value === null) {
+ return false;
+ }
+
+ const preset = value as Partial<RebalancePreset>;
+
+ return (
+ typeof preset.id === 'string' &&
+ preset.id.trim() !== '' &&
+ typeof preset.label === 'string' &&
+ preset.label.trim() !== '' &&
+ typeof preset.multiplier === 'number' &&
+ Number.isFinite(preset.multiplier) &&
+ typeof preset.weights === 'string' &&
+ isValidKrea2RebalanceWeights(preset.weights)
+ );
+};
+
+/**
+ * Coerces the persisted array back into shape. Entries that no longer parse — or that
+ * collide with a built-in id — are dropped rather than surfaced as broken pickers.
+ */
+export const normalizeRebalancePresets = (value: unknown): RebalancePreset[] => {
+ if (!Array.isArray(value)) {
+ return [];
+ }
+
+ const seen = new Set<string>();
+ const presets: RebalancePreset[] = [];
+
+ for (const entry of value) {
+ if (!isRebalancePreset(entry) || seen.has(entry.id) || BUILTIN_REBALANCE_PRESET_IDS.has(entry.id)) {
+ continue;
+ }
+
+ seen.add(entry.id);
+ presets.push({
+ id: entry.id,
+ label: entry.label.trim(),
+ multiplier: entry.multiplier,
+ weights: entry.weights,
+ });
+ }
+
+ return presets;
+};
+
+/** The preset the current values match exactly, or null when they have been edited away from one. */
+export const matchRebalancePreset = (
+ presets: readonly RebalancePreset[],
+ weights: string,
+ multiplier: number
+): string | null => {
+ const current = parseRebalanceWeights(weights);
+
+ if (!current) {
+ return null;
+ }
+
+ const match = presets.find((preset) => {
+ if (preset.multiplier !== multiplier) {
+ return false;
+ }
+
+ const presetWeights = parseRebalanceWeights(preset.weights);
+
+ return presetWeights !== null && presetWeights.every((weight, index) => weight === current[index]);
+ });
+
+ return match?.id ?? null;
+};
diff --git a/invokeai/frontend/webv2/src/features/generation/core/settings.ts b/invokeai/frontend/webv2/src/features/generation/core/settings.ts
index 6f6bb3b7cb..928f2d69ff 100644
--- a/invokeai/frontend/webv2/src/features/generation/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/core/settings.ts
@@ -17,6 +17,12 @@ import type {
import { sanitizeBatchCount } from './batch';
import { isVaeCompatibleWithGenerateModel } from './componentCompatibility';
+import {
+ DEFAULT_KREA2_REBALANCE_MULTIPLIER,
+ DEFAULT_KREA2_REBALANCE_WEIGHTS,
+ isValidKrea2RebalanceWeights,
+ KREA2_REBALANCE_WEIGHT_COUNT,
+} from './conditioningRebalance';
import { isDynamicPromptsSeedBehaviour, sanitizeMaxPrompts, sanitizeSampleSeed } from './dynamicPrompts';
import { clampPidSteps, DEFAULT_PID_STEPS, isPidMode } from './pid';
import { isCanonicalPromptTemplateSnapshot, sanitizePromptTemplateSnapshot } from './promptTemplates';
@@ -169,9 +175,6 @@ const isVaePrecision = (value: unknown): value is VaePrecision => value === 'fp1
/** Backend defaults from `Ideogram4DenoiseInvocation` / `Krea2*Invocation`. */
export const IDEOGRAM4_SAMPLER_PRESETS: Ideogram4SamplerPreset[] = ['V4_QUALITY_48', 'V4_DEFAULT_20', 'V4_TURBO_12'];
export const DEFAULT_IDEOGRAM4_SAMPLER_PRESET: Ideogram4SamplerPreset = 'V4_QUALITY_48';
-export const DEFAULT_KREA2_REBALANCE_MULTIPLIER = 4;
-export const DEFAULT_KREA2_REBALANCE_WEIGHTS = '1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.5,5.0,1.1,4.0,1.0';
-export const KREA2_REBALANCE_WEIGHT_COUNT = 12;
export const DEFAULT_KREA2_SEED_VARIANCE_STRENGTH = 0.1;
export const MAX_KREA2_SEED_VARIANCE_STRENGTH = 2;
export const DEFAULT_KREA2_SEED_VARIANCE_RANDOMIZE_PERCENT = 50;
@@ -185,23 +188,13 @@ const getOptionalNumber = (value: unknown): number | null =>
const getStringArray = (value: unknown): string[] =>
Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];
-/**
- * Krea-2 rebalance weights are free text forwarded straight to the backend's `_parse_weights()`.
- * Validating here keeps an unparseable string (wrong count, non-numeric, NaN/Infinity) from
- * reaching a node that would fail mid-generation.
- */
-export const isValidKrea2RebalanceWeights = (value: string): boolean => {
- const parts = value.split(',');
-
- if (parts.length !== KREA2_REBALANCE_WEIGHT_COUNT) {
- return false;
- }
-
- return parts.every((part) => {
- const trimmed = part.trim();
-
- return trimmed !== '' && Number.isFinite(Number(trimmed));
- });
+// Re-exported so existing `core/settings` callers keep one import site; the rebalance
+// vector, its presets, and its geometry all live in `conditioningRebalance.ts`.
+export {
+ DEFAULT_KREA2_REBALANCE_MULTIPLIER,
+ DEFAULT_KREA2_REBALANCE_WEIGHTS,
+ isValidKrea2RebalanceWeights,
+ KREA2_REBALANCE_WEIGHT_COUNT,
};
const isGenerateLora = (value: unknown): value is GenerateLora =>
diff --git a/invokeai/frontend/webv2/src/features/generation/settings.ts b/invokeai/frontend/webv2/src/features/generation/settings.ts
index 9ee4c1d641..0c09c875a9 100644
--- a/invokeai/frontend/webv2/src/features/generation/settings.ts
+++ b/invokeai/frontend/webv2/src/features/generation/settings.ts
@@ -58,6 +58,11 @@ export {
type ResolveGenerateWidgetValuesInput,
} from './core/resolveGenerateWidgetValues';
export { isVaeCompatibleWithGenerateModel } from './core/componentCompatibility';
+export {
+ isValidKrea2RebalanceWeights,
+ normalizeRebalancePresets,
+ type RebalancePreset,
+} from './core/conditioningRebalance';
export { MIN_BATCH_COUNT, sanitizeBatchCount } from './core/batch';
export {
createDynamicPromptsSampleSeed,