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
fix(models): rank related models by the active main model in pickers (#10246)
Alexander Eichhornfec8b91cb1db
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex c44bc04611..92ddd33cb1 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1632,7 +1632,7 @@"library": "Model library","libraryMaintenance": "Model library maintenance","linkedModel": "Linked model",- "linkedToCurrentSelection": "Linked to the current selection",+ "linkedToModel": "Linked to {{name}}","loadingModels": "Loading models…","manageApiKeys": "Manage API keys","manageModels": "Manage models",diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateAdvancedFields.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateAdvancedFields.tsxindex 43a0fc4a9d..b0e8d0926a 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateAdvancedFields.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateAdvancedFields.tsx@@ -221,6 +221,7 @@ export const GenerateAdvancedFields = ({filter={(model) => model.base === modelBase}modelTypes={['vae']}placeholder={t('widgets.generate.modelDefault')}+ relatedTo={selectedModel?.key ?? null}value={settings.vae?.key ?? null}onChange={(model) => onCommitImmediate({ vae: isVaeModelConfig(model) ? model : null })}/>diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsxindex 74fd806da7..49d64c8ca2 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateComponentsSection.tsx@@ -136,6 +136,7 @@ const ComponentPicker = ({? t('widgets.generate.selectComponent'): (slot.placeholder ?? t('widgets.generate.modelDefault'))}+ relatedTo={ctx.model.key}value={selectedValue}onChange={onChange}/>diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsxindex 88dcdde875..cccaa0ac21 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerateConceptsSection.tsx@@ -134,6 +134,7 @@ export const GenerateConceptsContent = ({placeholder={selectedModel ? t('widgets.generate.searchCompatibleConcepts') : t('widgets.generate.selectModelFirst')}+ relatedTo={selectedModel?.key ?? null}value={null}onChange={addLora}/>diff --git a/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx b/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsxindex aa5b61dfe7..be054df075 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/GenerationUiContext.tsx@@ -19,6 +19,7 @@ export interface GenerationModelSelectProps {modelTypes: string[];onChange: (model: GenerationModelCatalogItem | null) => void;placeholder?: string;+ relatedTo?: string | null;scopeLabel?: string;showManagerButton?: boolean;size?: 'md' | 'lg' | 'xl';diff --git a/invokeai/frontend/webv2/src/features/generation/ui/reference-images/ReferenceImageCard.tsx b/invokeai/frontend/webv2/src/features/generation/ui/reference-images/ReferenceImageCard.tsxindex ca31f42d5b..c05ae6caea 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/reference-images/ReferenceImageCard.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/reference-images/ReferenceImageCard.tsx@@ -282,6 +282,7 @@ const ReferenceImageCardBase = ({<ReferenceModelSelectorconfig={config}disabled={!isEnabled}+ relatedTo={selectedModel?.key ?? null}selectedBase={selectedBase}onConfigChange={changeConfig}/>@@ -291,6 +292,7 @@ const ReferenceImageCardBase = ({<ReferenceModelSelectorconfig={config}disabled={!isEnabled}+ relatedTo={selectedModel?.key ?? null}selectedBase={selectedBase}onConfigChange={changeConfig}/>@@ -300,6 +302,7 @@ const ReferenceImageCardBase = ({<ReferenceModelSelectorconfig={config}disabled={!isEnabled}+ relatedTo={selectedModel?.key ?? null}selectedBase={selectedBase}onConfigChange={changeConfig}/>@@ -385,10 +388,12 @@ const ReferenceModelSelector = ({config,disabled,onConfigChange,+ relatedTo,selectedBase,}: {config: ModelBackedConfig;disabled: boolean;+ relatedTo: string | null;selectedBase: string | undefined;onConfigChange: (config: GenerateReferenceImageConfig) => void;}) => {@@ -437,6 +442,7 @@ const ReferenceModelSelector = ({filter={filterModel}modelTypes={modelTypes}placeholder={t('widgets.generate.selectModel')}+ relatedTo={relatedTo}value={config.model?.key ?? null}onChange={selectReferenceModel}/>diff --git a/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.browser.test.tsx b/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.browser.test.tsxindex 7e6b89bc63..20fef86838 100644--- a/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.browser.test.tsx@@ -2,6 +2,7 @@ import type { ModelConfig } from '@features/models';import { ChakraProvider, Field as ChakraField } from '@chakra-ui/react';import { setModelsSnapshotForTests } from '@features/models/data/modelsStore';+import { setRelationshipsSnapshotForTests } from '@features/models/data/relationshipsStore';import { ModelsUiProvider, NO_SCHEDULER_POLICY } from '@features/models/ui/ModelsUiContext';import { getModelsUiSnapshotForTests } from '@features/models/ui/uiStore';import { auditAccessibility, contrastOffenderTexts } from '@platform/browser/auditAccessibility.testing';@@ -16,7 +17,11 @@ import { ModelSelect } from './ModelSelect';// Browser tests run without an i18n provider, so translated copy renders as// the raw key (e.g. 'models.compactRows'); assertions below match the keys.-vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string, options?: { name?: string }) => (options?.name ? `${key}:${options.name}` : key),+ }),+}));(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;@@ -485,3 +490,68 @@ describe('ModelSelect loading states', () => {});});});++describe('ModelSelect related-model ranking', () => {+ let host: HTMLDivElement;+ let root: Root;+ const vaeA = { ...model, key: 'vae-a', name: 'Alpha VAE', type: 'vae' } as ModelConfig;+ const vaeB = { ...model, key: 'vae-b', name: 'Beta VAE', type: 'vae' } as ModelConfig;+ const vaeTypes = ['vae'] as const;++ const renderVaePicker = async (props: { relatedTo?: string | null; value: string | null }) => {+ await act(() => {+ root.render(+ <ChakraProvider value={system}>+ <ModelsUiProvider adapter={MODELS_UI_ADAPTER}>+ <ModelSelect modelTypes={vaeTypes} showManagerButton={false} onChange={vi.fn()} {...props} />+ </ModelsUiProvider>+ </ChakraProvider>+ );+ });+ await act(() => host.querySelector<HTMLButtonElement>('[aria-haspopup="listbox"]')?.click());+ await expect.poll(() => document.querySelectorAll('[role="option"]').length).toBe(2);+ };+ const options = () => [...document.querySelectorAll<HTMLElement>('[role="option"]')];+ const optionNames = () => options().map((option) => option.textContent ?? '');++ beforeEach(() => {+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);+ setModelsSnapshotForTests({ error: null, models: [model, vaeA, vaeB], status: 'loaded' });+ // Beta VAE links to the main model; the picker's own value (Alpha) links to Beta too, which must not rank.+ setRelationshipsSnapshotForTests({ relatedKeysByModelKey: { 'sdxl-main': ['vae-b'], 'vae-a': ['vae-b'] } });+ });++ afterEach(async () => {+ await act(() => root.unmount());+ host.remove();+ document.querySelectorAll('[data-scope="popover"]').forEach((element) => element.remove());+ setModelsSnapshotForTests({ error: null, models: [], status: 'idle' });+ setRelationshipsSnapshotForTests({ relatedKeysByModelKey: {} });+ });++ it('ranks models linked to the anchor first and names the anchor in the option', async () => {+ await renderVaePicker({ relatedTo: 'sdxl-main', value: null });++ await expect.poll(() => optionNames()[0]).toContain('Beta VAE');+ await expect.element(options()[0]!).toHaveAccessibleName(/^Beta VAE\s*, models\.linkedToModel:SDXL Main/);+ await expect.element(options()[1]!).toHaveAccessibleName(/^Alpha VAE/);+ await expect.element(options()[1]!).not.toHaveAccessibleName(/linked/i);+ });++ it('falls back to a generic link label when the anchor is not in the catalog', async () => {+ setRelationshipsSnapshotForTests({ relatedKeysByModelKey: { 'missing-main': ['vae-b'] } });+ await renderVaePicker({ relatedTo: 'missing-main', value: null });++ await expect.poll(() => optionNames()[0]).toContain('Beta VAE');+ await expect.element(options()[0]!).toHaveAccessibleName(/^Beta VAE\s*, models\.linkedModel/);+ });++ it('ignores the value of the picker itself when no anchor is given', async () => {+ await renderVaePicker({ value: 'vae-a' });++ expect(optionNames()[0]).toContain('Alpha VAE');+ expect(optionNames().join(' ')).not.toMatch(/linked/i);+ });+});diff --git a/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsx b/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsxindex be9d9a3e8e..ce217ff008 100644--- a/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/components/ModelSelect.tsx@@ -14,6 +14,7 @@ import {Stack,Text,useFieldContext,+ VisuallyHidden,} from '@chakra-ui/react';import { getModelBaseColorPalette, getModelBaseLabel, getModelBaseLongLabel } from '@features/models/core/baseIdentity';import { getModelPickerGroups, hasModelPickerCandidates } from '@features/models/core/library';@@ -107,6 +108,7 @@ export const ModelSelect = ({modelTypes,onChange,placeholder,+ relatedTo = null,scopeLabel: scopeLabelOverride,showManagerButton = true,size = 'md',@@ -127,6 +129,8 @@ export const ModelSelect = ({modelTypes: readonly ModelTaxonomyType[];onChange: (model: ModelConfig | null) => void;placeholder?: string;+ /** Key of the model whose links rank this picker: its related models come first and carry a link icon. */+ relatedTo?: string | null;/** Plural noun for the offered models in empty/search copy; defaults to the model type's plural label. */scopeLabel?: string;showManagerButton?: boolean;@@ -159,7 +163,10 @@ export const ModelSelect = ({(bases: ReadonlySet<string>) => setPickerBaseFilters(pickerId, [...bases]),[pickerId]);- const relatedKeyList = useLazyRelatedModelKeys(isOpen ? value : null);+ const relatedKeyList = useLazyRelatedModelKeys(isOpen ? relatedTo : null);+ const relatedToName = useModelsSelector((snapshot) =>+ relatedTo === null ? null : (snapshot.modelsByKey.get(relatedTo)?.name ?? null)+ );const relatedKeys = useMemo<ReadonlySet<string>>(() => (relatedKeyList ? new Set(relatedKeyList) : EMPTY_KEYS),[relatedKeyList]@@ -251,12 +258,13 @@ export const ModelSelect = ({<ModelOptionContentenableDescription={enableModelDescriptions}isRelated={relatedKeys.has(model.key)}+ relatedToName={relatedToName}model={model}showType={hasMixedTypes}state={state}/>),- [enableModelDescriptions, hasMixedTypes, relatedKeys]+ [enableModelDescriptions, hasMixedTypes, relatedKeys, relatedToName]);return (@@ -537,16 +545,20 @@ const ModelOptionContent = ({enableDescription,isRelated,model,+ relatedToName,showType,state,}: {enableDescription: boolean;isRelated: boolean;model: ModelConfig;+ relatedToName: string | null;showType: boolean;state: PickerOptionState;}) => {const { t } = useTranslation();+ const linkedLabel =+ relatedToName === null ? t('models.linkedModel') : t('models.linkedToModel', { name: relatedToName });const showDetail = !state.isCompact;return (@@ -565,17 +577,14 @@ const ModelOptionContent = ({<Stack flex="1" gap="0" minW="0"><HStack gap="1.5" minW="0">{isRelated ? (- <Tooltip content={t('models.linkedToCurrentSelection')}>- <Icon- as={LinkIcon}- aria-label={t('models.linkedModel')}- boxSize="3"- color="accent.solid"- flexShrink={0}- />+ <Tooltip content={linkedLabel}>+ <Icon as={LinkIcon} aria-hidden boxSize="3" color="accent.solid" flexShrink={0} /></Tooltip>) : null}<MiddleTruncate fontSize="md" minW="0" text={model.name} />+ {/* Options take their accessible name from their text, and focus stays in the search field, so the tooltip+ alone never reaches screen readers or keyboard users. */}+ {isRelated ? <VisuallyHidden>{`, ${linkedLabel}`}</VisuallyHidden> : null}{showType ? (<Badge colorPalette="gray" flexShrink={0} fontSize="xs" variant="surface">{getModelTypeLabel(model.type)}diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsxindex 0c9ed7ce68..eaf93d4799 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/DefaultSettingsSection.tsx@@ -51,6 +51,8 @@ interface FieldControlProps {label: string;/** Base of the model being edited, for same-base model pickers. */modelBase: string;+ /** Key of the model being edited; its links rank the model pickers. */+ modelKey: string;setValue: (value: unknown) => void;value: unknown;}@@ -59,7 +61,7 @@ interface FieldControlProps {const buildCollection = (options: readonly string[]) =>createListCollection({ items: options.map((option) => ({ label: option, value: option })) });-const FieldControl = ({ control, disabled, label, modelBase, setValue, value }: FieldControlProps) => {+const FieldControl = ({ control, disabled, label, modelBase, modelKey, setValue, value }: FieldControlProps) => {const { t } = useTranslation();const selectCollection = useMemo(() => (control.kind === 'select' ? buildCollection(control.options) : null),@@ -144,6 +146,7 @@ const FieldControl = ({ control, disabled, label, modelBase, setValue, value }:isClearablemodelTypes={control.modelTypes}placeholder={t(control.placeholderKey)}+ relatedTo={modelKey}showManagerButton={false}size="lg"// The 'default' sentinel renders as the placeholder: the toggle is on@@ -344,6 +347,7 @@ export const DefaultSettingsSection = ({disabled={!isEnabled || field.pending !== undefined}label={t(field.labelKey)}modelBase={String(model.base)}+ modelKey={model.key}setValue={(nextValue) => setFieldValue(field.key, nextValue)}value={isEnabled ? value : field.defaultValue}/>diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsxindex 462dcd7823..5987b82cd2 100644--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx@@ -194,10 +194,12 @@ const isSelectableMainModel = (model: ModelConfig): boolean => isSupportedUpscalconst UpscaleComponentPicker = memo(function UpscaleComponentPicker({onPatch,+ relatedTo,slot,value,}: {onPatch: (patch: Partial<UpscaleWidgetValues>) => void;+ relatedTo: string | null;slot: UpscaleComponentSlot;value: UpscaleWidgetValues[UpscaleComponentField];}) {@@ -216,6 +218,7 @@ const UpscaleComponentPicker = memo(function UpscaleComponentPicker({invalid={!value}modelTypes={ui.modelTypes}placeholder={t(ui.placeholder)}+ relatedTo={relatedTo}value={value?.key ?? null}onChange={select}/>@@ -902,6 +905,7 @@ export const UpscaleWidgetView = () => {filter={loraFilter}modelTypes={LORA_MODEL_TYPES}placeholder={t('widgets.upscale.searchCompatibleConcepts')}+ relatedTo={values.model?.key ?? null}scopeLabel={t('models.scopeConcepts')}value={null}onChange={addLora}@@ -948,6 +952,7 @@ export const UpscaleWidgetView = () => {invalid={!values.tileControlnetModel}modelTypes={CONTROLNET_MODEL_TYPES}placeholder={t('widgets.upscale.selectTileControlNet')}+ relatedTo={values.model?.key ?? null}value={values.tileControlnetModel?.key ?? null}onChange={setTileControlNet}/>@@ -964,13 +969,20 @@ export const UpscaleWidgetView = () => {isClearablemodelTypes={CONTROLNET_MODEL_TYPES}placeholder={t('widgets.upscale.selectOptionalTileControlNet')}+ relatedTo={values.model?.key ?? null}value={values.tileControlnetModel?.key ?? null}onChange={setTileControlNet}/></Field>)}{components.slots.map((slot) => (- <UpscaleComponentPicker key={slot.field} slot={slot} value={values[slot.field]} onPatch={patch} />+ <UpscaleComponentPicker+ key={slot.field}+ relatedTo={values.model?.key ?? null}+ slot={slot}+ value={values[slot.field]}+ onPatch={patch}+ />))}<ScrubberFielderror={errors.tileSize}@@ -1008,6 +1020,7 @@ export const UpscaleWidgetView = () => {isClearable={!components.vae}modelTypes={VAE_MODEL_TYPES}placeholder={components.vae ? t('widgets.upscale.selectVae') : t('widgets.upscale.bundledVae')}+ relatedTo={values.model?.key ?? null}value={values.vae?.key ?? null}onChange={set.vae}/>diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoComponentsSection.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoComponentsSection.tsxindex 83de12e138..1b2a2b875c 100644--- a/invokeai/frontend/webv2/src/features/video/ui/VideoComponentsSection.tsx+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoComponentsSection.tsx@@ -76,6 +76,7 @@ const ComponentSlotRow = memo(function ComponentSlotRow({isClearablemodelTypes={slot.modelTypes}placeholder={t('widgets.video.selectComponent')}+ relatedTo={ctx.model.key}value={value?.key ?? null}onChange={handleChange}/>diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsxindex 07b8eac25b..907d99428f 100644--- a/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoConceptsSection.tsx@@ -79,6 +79,7 @@ export const VideoConceptsSection = memo(filter={loraFilter}modelTypes={LORA_MODEL_TYPES}placeholder={t('widgets.video.addLora')}+ relatedTo={model?.key ?? null}scopeLabel={t('models.scopeConcepts')}value={null}onChange={addLora}