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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(models): default VAE picker and LoRA weight bounds in default settings
joshistoast69e2ac6158a5
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex fc6f589930..602b22be3b 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -868,8 +868,11 @@"preprocessor": "Chosen automatically per image","scheduler": "App default: euler_a","steps": "App default: 30",+ "vae": "Uses the compatible default VAE","vaePrecision": "App default: fp16","weight": "App default: 0.75",+ "weightMax": "Slider default: 2",+ "weightMin": "Slider default: -1","width": "App default: 1024"},"defaultFields": {@@ -881,11 +884,15 @@"preprocessor": "Preprocessor","scheduler": "Scheduler","steps": "Steps",+ "vae": "VAE","vaePrecision": "VAE Precision","weight": "Weight",+ "weightMax": "Weight Max",+ "weightMin": "Weight Min","width": "Width"},"defaultSettings": "Default Settings",+ "defaultVae": "Default VAE","defaultSettingsHelp": "Applied automatically when this model is selected. Off = use the app default.","defaultSettingsSaved": "Default settings saved","deleteBody": "Delete \"{{name}}\"? The database record is removed, and the model files are deleted if they live inside the InvokeAI models directory.",diff --git a/invokeai/frontend/webv2/src/features/models/core/schemas.ts b/invokeai/frontend/webv2/src/features/models/core/schemas.tsindex ace2873fbc..150554735c 100644--- a/invokeai/frontend/webv2/src/features/models/core/schemas.ts+++ b/invokeai/frontend/webv2/src/features/models/core/schemas.ts@@ -44,6 +44,9 @@ export const mainDefaultSettingsSchema = z.object({),scheduler: trimmed.nullable(),steps: optionalBoundedNumber(1, 10000, 'Steps'),+ // A VAE model key, or the backend sentinel 'default' for "the compatible+ // default VAE"; null inherits the app-level setting.+ vae: trimmed.min(1, 'Choose a VAE or turn the field off.').nullable(),vaePrecision: z.enum(['fp16', 'fp32']).nullable(),width: optionalBoundedNumber(64, 8192, 'Width').refine((value) => value === null || value % 8 === 0,@@ -53,9 +56,37 @@ export const mainDefaultSettingsSchema = z.object({export type MainDefaultSettingsFormValues = z.infer<typeof mainDefaultSettingsSchema>;-export const loraDefaultSettingsSchema = z.object({- weight: optionalBoundedNumber(-10, 10, 'Weight'),-});+// Mirrors the backend validator (configs/lora.py): the effective slider range+// falls back to [-1, 2], min must stay below max, and an enabled weight must+// sit inside the effective range — otherwise the save 409s.+export const loraDefaultSettingsSchema = z+ .object({+ weight: optionalBoundedNumber(-10, 10, 'Weight'),+ weightMax: optionalBoundedNumber(-10, 10, 'Weight max'),+ weightMin: optionalBoundedNumber(-10, 10, 'Weight min'),+ })+ .superRefine((values, context) => {+ const effectiveMin = values.weightMin ?? -1;+ const effectiveMax = values.weightMax ?? 2;++ if (effectiveMin >= effectiveMax) {+ context.addIssue({+ code: 'custom',+ message: `Weight min (${effectiveMin}) must be less than weight max (${effectiveMax}).`,+ path: ['weightMin'],+ });++ return;+ }++ if (values.weight !== null && (values.weight < effectiveMin || values.weight > effectiveMax)) {+ context.addIssue({+ code: 'custom',+ message: `Weight (${values.weight}) must be within [${effectiveMin}, ${effectiveMax}].`,+ path: ['weight'],+ });+ }+ });export type LoraDefaultSettingsFormValues = z.infer<typeof loraDefaultSettingsSchema>;diff --git a/invokeai/frontend/webv2/src/features/models/core/types.ts b/invokeai/frontend/webv2/src/features/models/core/types.tsindex 9b62e905e8..125aad8fd3 100644--- a/invokeai/frontend/webv2/src/features/models/core/types.ts+++ b/invokeai/frontend/webv2/src/features/models/core/types.ts@@ -99,6 +99,8 @@ export interface MainModelDefaultSettings {export interface LoraModelDefaultSettings {weight?: number | null;+ weight_min?: number | null;+ weight_max?: number | null;}export interface ControlAdapterDefaultSettings {diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsxindex 33e7d7de44..1c7edc27de 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx@@ -4,6 +4,7 @@ import type { AnyModelDefaultSettings } from '@features/models/core/types';import { createListCollection, Grid, HStack, Icon, NumberInput, Stack, Switch, Text } from '@chakra-ui/react';import { updateModel } from '@features/models/data/api';import { replaceModelInStore } from '@features/models/data/modelsStore';+import { ModelSelect } from '@features/models/ui/components/ModelSelect';import { useScopedAction } from '@features/models/ui/shared/useScopedAction';import { assertAccountScopeCurrent } from '@platform/state/accountLifecycle';import { Button, Combobox, FieldLabel, Panel, Select } from '@platform/ui';@@ -32,6 +33,8 @@ interface FieldControlProps {control: DefaultSettingsControl;disabled: boolean;label: string;+ /** Base of the model being edited, for same-base model pickers. */+ modelBase: string;setValue: (value: unknown) => void;value: unknown;}@@ -40,7 +43,8 @@ interface FieldControlProps {const buildCollection = (options: readonly string[]) =>createListCollection({ items: options.map((option) => ({ label: option, value: option })) });-const FieldControl = ({ control, disabled, label, setValue, value }: FieldControlProps) => {+const FieldControl = ({ control, disabled, label, modelBase, setValue, value }: FieldControlProps) => {+ const { t } = useTranslation();const selectCollection = useMemo(() => (control.kind === 'select' ? buildCollection(control.options) : null),[control]@@ -120,6 +124,24 @@ const FieldControl = ({ control, disabled, label, setValue, value }: FieldContro);}+ if (control.kind === 'model') {+ return (+ <ModelSelect+ disabled={disabled}+ filter={(candidate) => !control.sameBase || String(candidate.base) === modelBase}+ isClearable+ modelTypes={control.modelTypes}+ placeholder={t(control.placeholderKey)}+ showManagerButton={false}+ size="sm"+ // The 'default' sentinel renders as the placeholder: the toggle is on+ // but no specific model is pinned.+ value={typeof value === 'string' && value !== 'default' ? value : null}+ onChange={(selected) => setValue(selected ? selected.key : 'default')}+ />+ );+ }+return null;};@@ -236,6 +258,7 @@ export const DefaultSettingsSection = ({control={field.control}disabled={!isEnabled}label={t(field.labelKey)}+ modelBase={String(model.base)}setValue={(nextValue) => setFieldValue(field.key, nextValue)}value={isEnabled ? value : field.defaultValue}/>diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.tsindex d46f116fd5..06cd1dc606 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.test.ts@@ -2,7 +2,7 @@ import type { ModelConfig } from '@features/models/core/types';import { describe, expect, it } from 'vitest';-import { getFieldsForModel, supportsFp8Storage } from './defaultSettingsFields';+import { getFieldsForModel, supportsFp8Storage, validateDefaults } from './defaultSettingsFields';const model = (base: string, type: string): Pick<ModelConfig, 'base' | 'type'> =>({ base, type }) as Pick<ModelConfig, 'base' | 'type'>;@@ -46,6 +46,7 @@ describe('getFieldsForModel', () => {expect(keys).toContain('fp8_storage');expect(keys.slice(0, -1)).toEqual([+ 'vae','scheduler','steps','cfg_scale',@@ -64,8 +65,8 @@ describe('getFieldsForModel', () => {expect(zImage).toEqual(fieldKeys(model('sdxl', 'main')).filter((key) => key !== 'fp8_storage'));});- it('leaves the LoRA field list untouched', () => {- expect(fieldKeys(model('sdxl', 'lora'))).toEqual(['weight']);+ it('gives LoRAs the weight and its slider bounds', () => {+ expect(fieldKeys(model('sdxl', 'lora'))).toEqual(['weight', 'weight_min', 'weight_max']);});it('adds fp8_storage alongside the preprocessor for a ControlNet', () => {@@ -76,3 +77,26 @@ describe('getFieldsForModel', () => {expect(fieldKeys(model('sdxl', 'control_lora'))).toEqual(['preprocessor']);});});++describe('validateDefaults', () => {+ const t = ((key: string) => key) as Parameters<typeof validateDefaults>[2];++ it('accepts the vae sentinel and a model key, rejects an empty string', () => {+ expect(validateDefaults(model('sdxl', 'main'), { vae: 'default' }, t)).toBeNull();+ expect(validateDefaults(model('sdxl', 'main'), { vae: 'some-model-key' }, t)).toBeNull();+ expect(validateDefaults(model('sdxl', 'main'), { vae: '' }, t)).not.toBeNull();+ });++ it('mirrors the backend LoRA bound validator: effective min must stay below max', () => {+ expect(validateDefaults(model('sdxl', 'lora'), { weight_max: 2, weight_min: -1 }, t)).toBeNull();+ expect(validateDefaults(model('sdxl', 'lora'), { weight_max: -1, weight_min: 1 }, t)).not.toBeNull();+ // Fallbacks are [-1, 2]: a min alone above 2 is invalid.+ expect(validateDefaults(model('sdxl', 'lora'), { weight_min: 3 }, t)).not.toBeNull();+ });++ it('requires an enabled weight to sit inside the effective range', () => {+ expect(validateDefaults(model('sdxl', 'lora'), { weight: 1.5 }, t)).toBeNull();+ expect(validateDefaults(model('sdxl', 'lora'), { weight: 2.5 }, t)).not.toBeNull();+ expect(validateDefaults(model('sdxl', 'lora'), { weight: 2.5, weight_max: 3 }, t)).toBeNull();+ });+});diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.ts b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.tsindex 6c3a8ae2f8..07d552b12b 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.ts+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/defaultSettingsFields.ts@@ -1,4 +1,4 @@-import type { AnyModelDefaultSettings, ModelConfig } from '@features/models/core/types';+import type { AnyModelDefaultSettings, ModelConfig, ModelTaxonomyType } from '@features/models/core/types';import type { TFunction } from 'i18next';import { loraDefaultSettingsSchema, mainDefaultSettingsSchema } from '@features/models/core/schemas';@@ -70,7 +70,15 @@ const PREPROCESSORS = [export type DefaultSettingsControl =| { kind: 'number'; max?: number; min?: number; step?: number }| { kind: 'select'; options: readonly string[] }- | { kind: 'combobox'; options: readonly string[] };+ | { kind: 'combobox'; options: readonly string[] }+ | {+ kind: 'model';+ modelTypes: readonly ModelTaxonomyType[];+ /** Restrict candidates to the edited model's base. */+ sameBase: boolean;+ /** Placeholder shown for the backend's 'default' sentinel. */+ placeholderKey: string;+ };export interface FieldSpec {key: keyof AnyModelDefaultSettings;@@ -104,6 +112,15 @@ const FP8_STORAGE_FIELD: FieldSpec = {};const MAIN_FIELDS: FieldSpec[] = [+ {+ control: { kind: 'model', modelTypes: ['vae'], placeholderKey: 'models.defaultVae', sameBase: true },+ // The backend sentinel for "the compatible default VAE" — what legacy+ // writes when the toggle is on but no specific model is picked.+ defaultValue: 'default',+ inheritLabelKey: 'models.defaultFieldInherited.vae',+ key: 'vae',+ labelKey: 'models.defaultFields.vae',+ },{control: { kind: 'combobox', options: SCHEDULERS },defaultValue: 'euler_a',@@ -170,6 +187,20 @@ const LORA_FIELDS: FieldSpec[] = [key: 'weight',labelKey: 'models.defaultFields.weight',},+ {+ control: { kind: 'number', max: 10, min: -10, step: 0.05 },+ defaultValue: -1,+ inheritLabelKey: 'models.defaultFieldInherited.weightMin',+ key: 'weight_min',+ labelKey: 'models.defaultFields.weightMin',+ },+ {+ control: { kind: 'number', max: 10, min: -10, step: 0.05 },+ defaultValue: 2,+ inheritLabelKey: 'models.defaultFieldInherited.weightMax',+ key: 'weight_max',+ labelKey: 'models.defaultFields.weightMax',+ },];const CONTROL_ADAPTER_FIELDS: FieldSpec[] = [@@ -224,6 +255,7 @@ export const validateDefaults = (height: settings.height ?? null,scheduler: settings.scheduler ?? null,steps: settings.steps ?? null,+ vae: settings.vae ?? null,vaePrecision: settings.vae_precision ?? null,width: settings.width ?? null,});@@ -232,7 +264,11 @@ export const validateDefaults = (}if (model.type === 'lora') {- const result = loraDefaultSettingsSchema.safeParse({ weight: settings.weight ?? null });+ const result = loraDefaultSettingsSchema.safeParse({+ weight: settings.weight ?? null,+ weightMax: settings.weight_max ?? null,+ weightMin: settings.weight_min ?? null,+ });return result.success ? null : (result.error.issues[0]?.message ?? t('models.invalidDefaultSettings'));}