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): Upscale and Video share the seed field and its modes

Josh Corbettf296a3d1bc82
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index f0840a3290..1c24a2d824 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -2415,7 +2415,6 @@
},
"presetsLabel": "Treatment preset",
"prompts": "Prompts",
- "random": "Random",
"ready": "Ready",
"readyDescription": "The upscale graph is ready to queue.",
"removeLora": "Remove {{name}}",
@@ -2429,7 +2428,6 @@
"selectTileControlNet": "Select a Tile or Union ControlNet…",
"settingsAdjusted": "Adjusted incompatible settings",
"shared": "Shared",
- "shuffleSeed": "Shuffle seed",
"sharedPromptDescription": "This is the project prompt shared with Generate. For upscaling, describe medium, texture, and style rather than new scene content.",
"sourceAndTreatment": "Source & treatment",
"spandrelModel": "Spandrel model",
@@ -3804,13 +3802,11 @@
"framesDuration": "{{seconds}} s at the current frame rate",
"mainModel": "Model",
"modelRequired": "Select a Wan 2.2 or MiniMax H3 model.",
- "randomizeSeed": "Random",
"render": "Render",
"seed": "Seed",
"selectModel": "Select a video model…",
"settingsAdjusted": "Settings adjusted",
"settingsAdjustedDescription": "Adjusted for the selected model: {{labels}}.",
- "shuffleSeed": "New random seed",
"steps": "Steps",
"swapAspectRatio": "Swap orientation",
"targetResolution": "Target Resolution",
diff --git a/invokeai/frontend/webv2/src/features/generation/components.ts b/invokeai/frontend/webv2/src/features/generation/components.ts
index d562cfd34d..fdd6ae878c 100644
--- a/invokeai/frontend/webv2/src/features/generation/components.ts
+++ b/invokeai/frontend/webv2/src/features/generation/components.ts
@@ -13,5 +13,6 @@ export { NegativePromptField } from './ui/promptFields/NegativePromptField';
export { PositivePromptField } from './ui/promptFields/PositivePromptField';
export { PromptTextarea } from './ui/promptFields/PromptTextarea';
export { PROMPT_ATTENTION_TARGET_PROPS } from './ui/promptFields/promptAttentionHotkeys';
+export { SeedField, type SeedFieldPatch, type SeedFieldProps } from './ui/shared/SeedField';
export { FluxReduxControls } from './ui/reference-images/ReferenceImageControls';
export { GenerateCollapsibleSection as GenerationSettingsSection } from './ui/shared/GenerateCollapsibleSection';
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts
index 1e4df878e0..cde91cc1b5 100644
--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts
+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.test.ts
@@ -44,7 +44,7 @@ describe('upscale settings', () => {
positivePromptHeightPx: 96,
scale: 4,
scheduler: 'kdpm_2',
- shouldRandomizeSeed: true,
+ seedMode: 'random',
steps: 30,
structure: 0,
tileOverlap: 128,
@@ -58,6 +58,15 @@ describe('upscale settings', () => {
});
});
+ it('reads the seed mode saved before modes existed from the random toggle', () => {
+ expect(normalizeUpscaleWidgetValues({ shouldRandomizeSeed: false })?.seedMode).toBe('fixed');
+ expect(normalizeUpscaleWidgetValues({ shouldRandomizeSeed: true })?.seedMode).toBe('random');
+ expect(normalizeUpscaleWidgetValues({ seedMode: 'decrement', shouldRandomizeSeed: true })?.seedMode).toBe(
+ 'decrement'
+ );
+ expect(normalizeUpscaleWidgetValues({})?.seedMode).toBe('random');
+ });
+
it('normalizes partial persisted values and calculates multiple-of-eight output dimensions', () => {
expect(
normalizeUpscaleWidgetValues({ negativePromptHeightPx: 4, positivePrompt: 'detail', positivePromptHeightPx: 999 })
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
index 7a129d7f63..487e8a6320 100644
--- a/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/upscale/core/settings.ts
@@ -9,18 +9,19 @@ import type { ModelConfig } from '@features/models';
import {
DEFAULT_NEGATIVE_PROMPT_HEIGHT_PX,
- sanitizeBatchCount,
DEFAULT_POSITIVE_PROMPT_HEIGHT_PX,
isLoraCompatibleWithModel,
isLoraModelConfig,
isMainModelConfig,
isModelIdentifierConfig,
- isVaeModelConfig,
+ isSeedMode,
isVaeCompatibleWithGenerateModel,
+ isVaeModelConfig,
MAX_NEGATIVE_PROMPT_HEIGHT_PX,
MAX_POSITIVE_PROMPT_HEIGHT_PX,
MIN_NEGATIVE_PROMPT_HEIGHT_PX,
MIN_POSITIVE_PROMPT_HEIGHT_PX,
+ sanitizeBatchCount,
SEED_MAX,
} from '@features/generation/settings';
@@ -117,7 +118,7 @@ export const createDefaultUpscaleWidgetValues = (models: readonly ModelConfig[]
scale: 4,
scheduler: 'kdpm_2',
seed: 0,
- shouldRandomizeSeed: true,
+ seedMode: 'random',
steps: 30,
structure: 0,
tileControlnetModel: models.find((candidate) => isTileControlNetCandidate(candidate, model)) ?? null,
@@ -173,8 +174,14 @@ export const normalizeUpscaleWidgetValues = (value: unknown): UpscaleWidgetValue
scale: isFiniteNumber(value.scale) ? value.scale : defaults.scale,
scheduler: typeof value.scheduler === 'string' ? value.scheduler : defaults.scheduler,
seed: isFiniteNumber(value.seed) ? value.seed : defaults.seed,
- shouldRandomizeSeed:
- typeof value.shouldRandomizeSeed === 'boolean' ? value.shouldRandomizeSeed : defaults.shouldRandomizeSeed,
+ // Values saved before seed modes carry the random toggle instead.
+ seedMode: isSeedMode(value.seedMode)
+ ? value.seedMode
+ : typeof value.shouldRandomizeSeed === 'boolean'
+ ? value.shouldRandomizeSeed
+ ? 'random'
+ : 'fixed'
+ : defaults.seedMode,
steps: isFiniteNumber(value.steps) ? value.steps : defaults.steps,
structure: isFiniteNumber(value.structure) ? value.structure : defaults.structure,
tileControlnetModel: isTileControlNetModelConfig(value.tileControlnetModel) ? value.tileControlnetModel : null,
@@ -347,6 +354,6 @@ export const clearDeletedUpscaleInput = (
values.inputImage && deletedImageNames.has(values.inputImage.image_name) ? { ...values, inputImage: null } : values;
export const resolveUpscaleSeed = (values: UpscaleWidgetValues): number =>
- values.shouldRandomizeSeed ? Math.floor(Math.random() * SEED_MAX) : values.seed;
+ values.seedMode === 'random' ? Math.floor(Math.random() * SEED_MAX) : values.seed;
export const cloneUpscaleWidgetValues = (values: UpscaleWidgetValues): UpscaleWidgetValues => structuredClone(values);
diff --git a/invokeai/frontend/webv2/src/features/upscale/core/types.ts b/invokeai/frontend/webv2/src/features/upscale/core/types.ts
index 731241a891..92c9f7fa57 100644
--- a/invokeai/frontend/webv2/src/features/upscale/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/upscale/core/types.ts
@@ -4,6 +4,7 @@ import type {
ImageWithDims,
MainModelConfig,
ModelIdentifierConfig,
+ SeedMode,
VaeModelConfig,
VaePrecision,
} from '@features/generation/contracts';
@@ -31,7 +32,7 @@ export interface UpscaleWidgetValues {
scheduler: string;
batchCount: number;
seed: number;
- shouldRandomizeSeed: boolean;
+ seedMode: SeedMode;
clipSkip: number;
vae: VaeModelConfig | null;
vaePrecision: VaePrecision;
diff --git a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
index e1ae5ebed8..7a772b8cef 100644
--- a/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/features/upscale/ui/UpscaleWidgetView.tsx
@@ -7,15 +7,13 @@ import {
Badge,
createListCollection,
DataList,
- HStack,
NumberInput,
SegmentGroup,
SimpleGrid,
Stack,
- Switch,
Text,
} from '@chakra-ui/react';
-import { GenerationSettingsSection } from '@features/generation/components';
+import { GenerationSettingsSection, SeedField } from '@features/generation/components';
import {
SCHEDULER_OPTIONS,
getDefaultLoraWeight,
@@ -48,11 +46,10 @@ import {
UPSCALE_TILE_SIZE_MIN,
} from '@features/upscale/core/settings';
import { useMountEffect } from '@platform/react/useMountEffect';
-import { Combobox, Field, IconButton, Select, Tooltip } from '@platform/ui';
+import { Combobox, Field, Select, Tooltip } from '@platform/ui';
import { SliderNumberField } from '@platform/ui/SliderNumberField';
import { toaster } from '@platform/ui/toaster';
-import { DicesIcon } from 'lucide-react';
-import { memo, useCallback, useId, useMemo } from 'react';
+import { memo, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { areInputImagesEquivalent, valuesAreEqual } from './upscaleComparators';
@@ -94,7 +91,6 @@ const TILE_OVERLAP_MARKS = [UPSCALE_TILE_OVERLAP_MIN, 128, 256, UPSCALE_TILE_OVE
const GENERATION_GRID_COLUMNS = { base: 2, md: 3 };
const ADVANCED_GRID_COLUMNS = { base: 1, md: 2 };
-const SWITCH_CHECKED_PROPS = { bg: 'accent.solid' };
const PRESET_ENTRIES = Object.entries(UPSCALE_PRESETS);
const isSelectableMainModel = (model: ModelConfig): boolean => isSupportedUpscaleMainModel(model);
@@ -284,13 +280,6 @@ export const UpscaleWidgetView = () => {
[t, values]
);
const patch = useCallback((next: Partial<UpscaleWidgetValues>) => patchValues(next), [patchValues]);
- // Chakra's `Field.Root` hands its single `ids.control` to EVERY control
- // inside it, and the seed Field holds the NumberInput, the shuffle button
- // and this switch. Without an id of its own the switch's hidden input
- // collides with the seed input, so the `<label>` Switch.Root renders points
- // at the seed field and clicking the toggle only moved focus.
- const seedSwitchId = useId();
- const seedSwitchIds = useMemo(() => ({ hiddenInput: `${seedSwitchId}-randomize-seed` }), [seedSwitchId]);
const patchPromptDraft = useCallback((next: ProjectPromptDraftPatch) => patchDraft(next), [patchDraft]);
useMountEffect(() => {
@@ -386,12 +375,8 @@ export const UpscaleWidgetView = () => {
Number.isFinite(valueAsNumber) && patch({ clipSkip: valueAsNumber }),
creativity: (creativity: number) => patch({ creativity }),
inputImage: (inputImage: UpscaleWidgetValues['inputImage']) => patch({ inputImage }),
- randomizeSeed: (details: { checked: boolean }) => patch({ shouldRandomizeSeed: details.checked }),
scale: (scale: number) => patch({ scale }),
scheduler: (scheduler: string) => patch({ scheduler }),
- seed: ({ valueAsNumber }: NumberInput.ValueChangeDetails) =>
- Number.isFinite(valueAsNumber) && patch({ seed: valueAsNumber }),
- shuffleSeed: () => patch({ seed: Math.floor(Math.random() * SEED_MAX) }),
spandrelModel: (model: ModelConfig | null) =>
patch({ upscaleModel: isSpandrelModelConfig(model) ? model : null }),
steps: ({ valueAsNumber }: NumberInput.ValueChangeDetails) =>
@@ -618,48 +603,14 @@ export const UpscaleWidgetView = () => {
onValueChange={set.scheduler}
/>
</Field>
- <Field
- error={values.shouldRandomizeSeed ? undefined : errors.seed}
- hint="seed"
+ <SeedField
+ batchCount={values.batchCount}
+ error={errors.seed}
label={t('widgets.upscale.seed')}
- >
- <HStack gap="2">
- <NumberInput.Root
- disabled={values.shouldRandomizeSeed}
- max={SEED_MAX}
- min={0}
- size="xs"
- value={String(values.seed)}
- w="full"
- onValueChange={set.seed}
- >
- <NumberInput.Input fontVariantNumeric="tabular-nums" />
- </NumberInput.Root>
- <Tooltip content={t('widgets.upscale.shuffleSeed')}>
- <IconButton
- aria-label={t('widgets.upscale.shuffleSeed')}
- disabled={values.shouldRandomizeSeed}
- size="xs"
- variant="outline"
- onClick={set.shuffleSeed}
- >
- <DicesIcon />
- </IconButton>
- </Tooltip>
- <Switch.Root
- checked={values.shouldRandomizeSeed}
- ids={seedSwitchIds}
- size="sm"
- onCheckedChange={set.randomizeSeed}
- >
- <Switch.HiddenInput />
- <Switch.Control _checked={SWITCH_CHECKED_PROPS}>
- <Switch.Thumb />
- </Switch.Control>
- <Switch.Label fontSize="xs">{t('widgets.upscale.random')}</Switch.Label>
- </Switch.Root>
- </HStack>
- </Field>
+ seed={values.seed}
+ seedMode={values.seedMode}
+ onCommit={patch}
+ />
<Field hint="concepts" label={t('widgets.upscale.addLora')}>
<ModelSelect
excludeKeys={selectedLoraKeys}
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
index bec0108af0..f0a1ebf845 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.test.ts
@@ -65,6 +65,17 @@ describe('resolveVideoMode', () => {
});
describe('normalizeVideoSettings', () => {
+ it('reads the seed mode saved before modes existed from the random toggle', () => {
+ const legacy = { ...createSettings({}), seedMode: undefined };
+
+ expect(normalizeVideoSettings({ ...legacy, shouldRandomizeSeed: false })?.seedMode).toBe('fixed');
+ expect(normalizeVideoSettings({ ...legacy, shouldRandomizeSeed: true })?.seedMode).toBe('random');
+ expect(normalizeVideoSettings({ ...legacy, seedMode: 'increment', shouldRandomizeSeed: false })?.seedMode).toBe(
+ 'increment'
+ );
+ expect(normalizeVideoSettings(legacy)?.seedMode).toBe('random');
+ });
+
it('round-trips canonical settings', () => {
const settings = createSettings({ firstFrameImage: FIRST_FRAME, positivePrompt: 'a cat' });
const normalized = normalizeVideoSettings(settings);
@@ -97,7 +108,7 @@ describe('normalizeVideoSettings', () => {
numFrames: 81,
positivePrompt: 'a dog',
seed: 123,
- shouldRandomizeSeed: false,
+ seedMode: 'fixed',
steps: 40,
};
const normalized = normalizeVideoSettings(legacy);
diff --git a/invokeai/frontend/webv2/src/features/video/core/settings.ts b/invokeai/frontend/webv2/src/features/video/core/settings.ts
index 63b7d274d9..17370bf97c 100644
--- a/invokeai/frontend/webv2/src/features/video/core/settings.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/settings.ts
@@ -6,6 +6,7 @@ import {
isLoraModelConfig,
isMainModelConfig,
isModelIdentifierConfig,
+ isSeedMode,
isVaeModelConfig,
MAX_NEGATIVE_PROMPT_HEIGHT_PX,
MAX_POSITIVE_PROMPT_HEIGHT_PX,
@@ -432,7 +433,12 @@ export const normalizeVideoSettings = (values: unknown): VideoSettings | null =>
),
references,
seed: hasFiniteNumber(values, 'seed') ? (values.seed as number) : 0,
- shouldRandomizeSeed: typeof values.shouldRandomizeSeed === 'boolean' ? values.shouldRandomizeSeed : true,
+ // Values saved before seed modes carry the random toggle instead.
+ seedMode: isSeedMode(values.seedMode)
+ ? values.seedMode
+ : typeof values.shouldRandomizeSeed === 'boolean' && !values.shouldRandomizeSeed
+ ? 'fixed'
+ : 'random',
sourceVideo,
steps: hasFiniteNumber(values, 'steps') ? (values.steps as number) : SETTINGS_FALLBACKS.steps,
targetResolution: isVideoTargetResolution(values.targetResolution)
diff --git a/invokeai/frontend/webv2/src/features/video/core/types.ts b/invokeai/frontend/webv2/src/features/video/core/types.ts
index d1793520b5..78e90ff9ed 100644
--- a/invokeai/frontend/webv2/src/features/video/core/types.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/types.ts
@@ -3,6 +3,7 @@ import type {
ImageWithDims,
MainModelConfig,
ModelIdentifierConfig,
+ SeedMode,
VaeModelConfig,
} from '@features/generation/contracts';
@@ -144,7 +145,7 @@ export interface VideoSettings {
*/
acceleratorLoraKeys: string[];
seed: number;
- shouldRandomizeSeed: boolean;
+ seedMode: SeedMode;
loras: GenerateLora[];
/** Optional VAE override; null uses the VAE bundled with the main model or component source. */
vae: VaeModelConfig | null;
diff --git a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts
index 731b40ba13..e0191a7e05 100644
--- a/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/videoPolicies.ts
@@ -1324,7 +1324,7 @@ export const getDefaultVideoSettings = (
positivePromptHeightPx: 96,
references: [],
seed: Math.floor(Math.random() * SEED_MAX),
- shouldRandomizeSeed: true,
+ seedMode: 'random',
sourceVideo: null,
steps: config.defaults.steps,
targetResolution: config.defaults.targetResolution,
diff --git a/invokeai/frontend/webv2/src/features/video/core/widgetValues.test.ts b/invokeai/frontend/webv2/src/features/video/core/widgetValues.test.ts
index 472814802b..33ffa815d7 100644
--- a/invokeai/frontend/webv2/src/features/video/core/widgetValues.test.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/widgetValues.test.ts
@@ -231,9 +231,9 @@ describe('getVideoWidgetValidationReasons', () => {
describe('resolveVideoSeed', () => {
it('keeps a fixed seed and randomizes otherwise', () => {
- expect(resolveVideoSeed({ seed: 42, shouldRandomizeSeed: false })).toBe(42);
+ expect(resolveVideoSeed({ seed: 42, seedMode: 'fixed' })).toBe(42);
- const randomized = resolveVideoSeed({ seed: 42, shouldRandomizeSeed: true });
+ const randomized = resolveVideoSeed({ seed: 42, seedMode: 'random' });
expect(Number.isInteger(randomized)).toBe(true);
expect(randomized).toBeGreaterThanOrEqual(0);
diff --git a/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts b/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts
index 6fdbaf6c8a..f85af6279e 100644
--- a/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts
+++ b/invokeai/frontend/webv2/src/features/video/core/widgetValues.ts
@@ -233,5 +233,5 @@ export const getVideoWidgetValidationReasons = (
return reasons;
};
-export const resolveVideoSeed = (values: Pick<VideoWidgetValues, 'seed' | 'shouldRandomizeSeed'>): number =>
- values.shouldRandomizeSeed ? Math.floor(Math.random() * SEED_MAX) : values.seed;
+export const resolveVideoSeed = (values: Pick<VideoWidgetValues, 'seed' | 'seedMode'>): number =>
+ values.seedMode === 'random' ? Math.floor(Math.random() * SEED_MAX) : values.seed;
diff --git a/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx b/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx
index b6e401814c..c675003abe 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx
+++ b/invokeai/frontend/webv2/src/features/video/ui/VideoWidgetView.tsx
@@ -2,9 +2,9 @@ import type { ImageWithDims } from '@features/generation/contracts';
import type { ModelConfig, ModelTaxonomyType } from '@features/models';
import type { VideoReferenceItem, VideoSourceClip, VideoWidgetValues } from '@features/video/core/types';
-import { createListCollection, HStack, NumberInput, Stack, Switch, Text } from '@chakra-ui/react';
-import { GenerationSettingsSection } from '@features/generation/components';
-import { isMainModelConfig, sanitizeBatchCount, SEED_MAX } from '@features/generation/settings';
+import { createListCollection, HStack, Stack, Switch, Text } from '@chakra-ui/react';
+import { GenerationSettingsSection, SeedField } from '@features/generation/components';
+import { isMainModelConfig, sanitizeBatchCount } from '@features/generation/settings';
import { ensureModelsLoaded, useModelsSelector } from '@features/models';
import { ModelSelect } from '@features/models/react';
import { getVideoDurationSeconds, invertVideoAspectRatioId } from '@features/video/core/dimensions';
@@ -31,8 +31,8 @@ import { Field, IconButton, Select } from '@platform/ui';
import { Button } from '@platform/ui/Button';
import { SliderNumberField } from '@platform/ui/SliderNumberField';
import { toaster } from '@platform/ui/toaster';
-import { ArrowLeftRightIcon, DicesIcon } from 'lucide-react';
-import { useCallback, useEffect, useId, useMemo, useRef } from 'react';
+import { ArrowLeftRightIcon } from 'lucide-react';
+import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { areVideoValuesEqual } from './videoComparators';
@@ -187,14 +187,6 @@ export const VideoWidgetView = () => {
};
}, [projectId, values.references]);
- // Chakra's `Field.Root` hands its single `ids.control` to EVERY control
- // inside it, and this Field holds three. Without an id of its own the
- // switch's hidden input collides with the seed NumberInput, so the
- // `<label>` Switch.Root renders points at the seed field: clicking the
- // toggle focused the seed input and never toggled anything.
- const seedSwitchId = useId();
- const seedSwitchIds = useMemo(() => ({ hiddenInput: `${seedSwitchId}-randomize-seed` }), [seedSwitchId]);
-
useMountEffect(() => {
void ensureModelsLoaded();
});
@@ -260,10 +252,6 @@ export const VideoWidgetView = () => {
cfgScale: (cfgScale: number) => patch({ cfgScale }),
cfgScaleLowNoise: (cfgScaleLowNoise: number) => patch({ cfgScaleLowNoise }),
fps: (fps: number) => patch({ fps }),
- randomizeSeed: (details: { checked: boolean }) => patch({ shouldRandomizeSeed: details.checked }),
- seed: ({ valueAsNumber }: NumberInput.ValueChangeDetails) =>
- Number.isFinite(valueAsNumber) && patch({ seed: valueAsNumber }),
- shuffleSeed: () => patch({ seed: Math.floor(Math.random() * SEED_MAX) }),
steps: (steps: number) => patch({ steps }),
targetResolution: ({ value }: { value: string[] }) => {
const targetResolution = toTargetResolution(value[0]);
@@ -737,49 +725,13 @@ export const VideoWidgetView = () => {
/>
</Field>
) : null}
- <Field hint="seed" label={t('widgets.video.seed')}>
- <HStack gap="2">
- <NumberInput.Root
- disabled={values.shouldRandomizeSeed}
- flex="1"
- max={SEED_MAX}
- min={0}
- size="xs"
- step={1}
- value={String(values.seed)}
- onValueChange={set.seed}
- >
- <NumberInput.Input aria-label={t('widgets.video.seed')} />
- </NumberInput.Root>
- <IconButton
- aria-label={t('widgets.video.shuffleSeed')}
- disabled={values.shouldRandomizeSeed}
- size="xs"
- variant="ghost"
- onClick={set.shuffleSeed}
- >
- <DicesIcon />
- </IconButton>
- <HStack gap="1">
- <Switch.Root
- checked={values.shouldRandomizeSeed}
- ids={seedSwitchIds}
- size="sm"
- onCheckedChange={set.randomizeSeed}
- >
- <Switch.HiddenInput />
- <Switch.Control _checked={SWITCH_CHECKED_PROPS}>
- <Switch.Thumb />
- </Switch.Control>
- {/* Inside Switch.Root, so the words are part of the control
- (they were an inert sibling <Text> before). */}
- <Switch.Label color="fg.muted" fontSize="2xs">
- {t('widgets.video.randomizeSeed')}
- </Switch.Label>
- </Switch.Root>
- </HStack>
- </HStack>
- </Field>
+ <SeedField
+ batchCount={values.batchCount}
+ label={t('widgets.video.seed')}
+ seed={values.seed}
+ seedMode={values.seedMode}
+ onCommit={patch}
+ />
</Stack>
</GenerationSettingsSection>
diff --git a/invokeai/frontend/webv2/src/features/video/ui/seedToggle.browser.test.tsx b/invokeai/frontend/webv2/src/features/video/ui/seedToggle.browser.test.tsx
deleted file mode 100644
index 3858afcb66..0000000000
--- a/invokeai/frontend/webv2/src/features/video/ui/seedToggle.browser.test.tsx
+++ /dev/null
@@ -1,100 +0,0 @@
-import { ChakraProvider, NumberInput, Switch } from '@chakra-ui/react';
-import { Field } from '@platform/ui/Field';
-import { system } from '@theme/system';
-import { act, useId, useMemo } from 'react';
-import { createRoot, type Root } from 'react-dom/client';
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { userEvent } from 'vitest/browser';
-
-/**
- * The seed row of the Video and Upscale panels puts three controls -- a seed
- * NumberInput, a shuffle button and a randomize Switch -- inside ONE `Field`.
- * Chakra's `Field.Root` hands its single `ids.control` to every control it
- * contains, so without an id of its own the switch's hidden input collides
- * with the seed input and the `<label>` that `Switch.Root` renders resolves to
- * the seed field instead. Clicking the toggle then just moved focus.
- */
-let container: HTMLDivElement;
-let root: Root;
-
-(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
-
-beforeEach(() => {
- container = document.createElement('div');
- document.body.append(container);
- root = createRoot(container);
-});
-
-afterEach(() => {
- act(() => root.unmount());
- container.remove();
-});
-
-const SeedRow = ({ onCheckedChange }: { onCheckedChange: (details: { checked: boolean }) => void }) => {
- const seedSwitchId = useId();
- const seedSwitchIds = useMemo(() => ({ hiddenInput: `${seedSwitchId}-randomize-seed` }), [seedSwitchId]);
-
- return (
- <Field hint="seed" label="Seed">
- <NumberInput.Root size="xs" value="42">
- <NumberInput.Input aria-label="Seed" />
- </NumberInput.Root>
- <Switch.Root checked={false} ids={seedSwitchIds} size="sm" onCheckedChange={onCheckedChange}>
- <Switch.HiddenInput data-testid="switch-input" />
- <Switch.Control data-testid="switch-control">
- <Switch.Thumb />
- </Switch.Control>
- <Switch.Label>Randomize seed</Switch.Label>
- </Switch.Root>
- </Field>
- );
-};
-
-const render = (onCheckedChange: (details: { checked: boolean }) => void) =>
- act(() => {
- root.render(
- <ChakraProvider value={system}>
- <SeedRow onCheckedChange={onCheckedChange} />
- </ChakraProvider>
- );
- });
-
-describe('seed row randomize switch', () => {
- it('does not share the Field control id with the seed input', async () => {
- await render(vi.fn());
-
- const seed = container.querySelector<HTMLInputElement>('input[aria-label="Seed"]')!;
- const toggle = container.querySelector<HTMLInputElement>('[data-testid="switch-input"]')!;
-
- expect(toggle.id).not.toBe('');
- expect(toggle.id).not.toBe(seed.id);
- // The label Switch.Root renders must point at the switch, not the seed field.
- expect(toggle.closest('label')?.getAttribute('for')).toBe(toggle.id);
- });
-
- it('toggles when the control is clicked, leaving the seed input unfocused', async () => {
- const onCheckedChange = vi.fn();
-
- await render(onCheckedChange);
- const seed = container.querySelector<HTMLInputElement>('input[aria-label="Seed"]')!;
-
- await userEvent.click(container.querySelector('[data-testid="switch-control"]')!);
-
- expect(onCheckedChange).toHaveBeenCalledWith(expect.objectContaining({ checked: true }));
- expect(document.activeElement).not.toBe(seed);
- });
-
- it('toggles when the label text is clicked', async () => {
- const onCheckedChange = vi.fn();
-
- await render(onCheckedChange);
-
- const label = [...container.querySelectorAll('*')].find(
- (node) => node.textContent === 'Randomize seed' && node.children.length === 0
- )!;
-
- await userEvent.click(label);
-
- expect(onCheckedChange).toHaveBeenCalledWith(expect.objectContaining({ checked: true }));
- });
-});
diff --git a/invokeai/frontend/webv2/src/features/video/ui/videoComparators.ts b/invokeai/frontend/webv2/src/features/video/ui/videoComparators.ts
index c0fd556832..8f2a1a4e40 100644
--- a/invokeai/frontend/webv2/src/features/video/ui/videoComparators.ts
+++ b/invokeai/frontend/webv2/src/features/video/ui/videoComparators.ts
@@ -47,7 +47,7 @@ export const areVideoValuesEqual = (left: VideoWidgetValues, right: VideoWidgetV
left.acceleratorEnabled === right.acceleratorEnabled &&
stableStringify(left.acceleratorLoraKeys) === stableStringify(right.acceleratorLoraKeys) &&
left.seed === right.seed &&
- left.shouldRandomizeSeed === right.shouldRandomizeSeed &&
+ left.seedMode === right.seedMode &&
left.batchCount === right.batchCount &&
areVideoLorasEquivalent(left.loras, right.loras) &&
stableStringify(left.firstFrameImage) === stableStringify(right.firstFrameImage) &&
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts
index f70e8b2d6c..137c9f3655 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.test.ts
@@ -200,14 +200,14 @@ describe('buildVideoRecallSettings', () => {
const result = buildVideoRecallSettings({ currentValues, kind: 'seed', metadata: wanMetadata(), models: catalog });
expect(result?.fields).toEqual(['seed']);
- expect(result?.values).toMatchObject({ seed: 1234, shouldRandomizeSeed: false });
+ expect(result?.values).toMatchObject({ seed: 1234, seedMode: 'fixed' });
});
it('remix recalls everything except the seed', () => {
const result = buildVideoRecallSettings({ currentValues, kind: 'remix', metadata: wanMetadata(), models: catalog });
expect(result?.fields).not.toContain('seed');
- expect(result?.values.shouldRandomizeSeed).toBe(currentValues.shouldRandomizeSeed);
+ expect(result?.values.seedMode).toBe(currentValues.seedMode);
expect(result?.fields).toEqual(expect.arrayContaining(['model', 'frames', 'steps', 'cfg', 'size']));
});
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
index b8ca6aae2e..8a4f14963d 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/videoRecall.ts
@@ -443,7 +443,7 @@ export const buildVideoRecallSettings = ({
const seed = getSeed(metadata);
if (seed !== null) {
- values = { ...values, seed, shouldRandomizeSeed: false };
+ values = { ...values, seed, seedMode: 'fixed' };
fields.push('seed');
}
}
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
index 39c4a73cd1..3923a47ff6 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.test.ts
@@ -170,7 +170,7 @@ describe('buildVideoQueueRecallPatch', () => {
...createDefaultVideoWidgetValues(),
positivePrompt: 'snapshot prompt',
seed: 123,
- shouldRandomizeSeed: false,
+ seedMode: 'fixed' as const,
};
expect(getVideoQueueRecallCapabilities(snapshot, {})).toEqual({
all: true,
@@ -183,11 +183,11 @@ describe('buildVideoQueueRecallPatch', () => {
expect(
planQueueRecall('all', { current: null, isVideoItem: true, meta: {}, snapshot: null, videoSnapshot: snapshot })
).toEqual({ target: 'video', patch: snapshot });
- expect(buildVideoQueueRecallPatch('remix', {}, snapshot)).toEqual({ ...snapshot, shouldRandomizeSeed: true });
- expect(snapshot.shouldRandomizeSeed).toBe(false);
+ expect(buildVideoQueueRecallPatch('remix', {}, snapshot)).toEqual({ ...snapshot, seedMode: 'random' });
+ expect(snapshot.seedMode).toBe('fixed');
expect(buildVideoQueueRecallPatch('seed', { seed: 456 }, snapshot)).toEqual({
seed: 456,
- shouldRandomizeSeed: false,
+ seedMode: 'fixed',
});
});
@@ -207,7 +207,7 @@ describe('buildVideoQueueRecallPatch', () => {
});
it('patches the executed seed and stops it being re-randomised', () => {
- expect(buildVideoQueueRecallPatch('seed', { seed: 4321 })).toEqual({ seed: 4321, shouldRandomizeSeed: false });
+ expect(buildVideoQueueRecallPatch('seed', { seed: 4321 })).toEqual({ seed: 4321, seedMode: 'fixed' });
});
it('returns null when the meta carries nothing for the verb', () => {
@@ -237,7 +237,7 @@ describe('planQueueRecall', () => {
target: 'video',
});
expect(planQueueRecall('seed', { current, isVideoItem: true, meta, snapshot: null })).toEqual({
- patch: { seed: 4321, shouldRandomizeSeed: false },
+ patch: { seed: 4321, seedMode: 'fixed' },
target: 'video',
});
});
diff --git a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
index 01d4c74e2d..84f5b8566d 100644
--- a/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
+++ b/invokeai/frontend/webv2/src/workbench/queue-integration/queueRecall.ts
@@ -34,7 +34,7 @@ export const getVideoQueueRecallCapabilities = (
dimensions: false,
prompts: snapshot !== null || meta.positivePrompt !== undefined,
remix: snapshot !== null,
- seed: meta.seed !== undefined || (snapshot !== null && !snapshot.shouldRandomizeSeed),
+ seed: meta.seed !== undefined || (snapshot !== null && snapshot.seedMode !== 'random'),
});
export const buildQueueRecallValues = (
@@ -123,7 +123,7 @@ export const buildVideoQueueRecallPatch = (
return null;
}
const values = cloneVideoWidgetValues(snapshot);
- return kind === 'remix' ? { ...values, shouldRandomizeSeed: true } : values;
+ return kind === 'remix' ? { ...values, seedMode: 'random' } : values;
}
if (kind === 'prompts') {
if (snapshot) {
@@ -154,8 +154,8 @@ export const buildVideoQueueRecallPatch = (
}
if (kind === 'seed') {
- const seed = meta.seed ?? (snapshot && !snapshot.shouldRandomizeSeed ? snapshot.seed : undefined);
- return seed === undefined ? null : { seed, shouldRandomizeSeed: false };
+ const seed = meta.seed ?? (snapshot && snapshot.seedMode !== 'random' ? snapshot.seed : undefined);
+ return seed === undefined ? null : { seed, seedMode: 'fixed' };
}
return null;
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
index 870c9cf3c7..2387c14ece 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts
@@ -3350,6 +3350,71 @@ describe('workbenchReducer Phase 5 generation flow', () => {
expect(readSeed(next)).toBe(42);
});
+ it('advances Upscale and Video seeds through the same boundary', () => {
+ const upscaleModels = [
+ createUpscaleModel('main', 'main', 'sd-1'),
+ createUpscaleModel('spandrel', 'spandrel_image_to_image', 'any'),
+ createUpscaleModel('tile', 'controlnet', 'sd-1', 'Tile ControlNet'),
+ ];
+ let state = workbenchReducer(createInitialWorkbenchState(), {
+ type: 'patchWidgetValues',
+ values: {
+ ...createDefaultUpscaleWidgetValues(upscaleModels),
+ batchCount: 2,
+ inputImage: { height: 64, image_name: 'input.png', width: 64 },
+ seed: 10,
+ seedMode: 'increment',
+ },
+ widgetId: 'upscale',
+ });
+
+ state = workbenchReducer(state, {
+ backendSupportsCancellation: true,
+ models: upscaleModels,
+ route: { destination: 'gallery', destinationLocked: false, sourceId: 'upscale', sourceLocked: false },
+ type: 'submitResolvedInvocationSnapshot',
+ });
+
+ expect(readSubmission(state)).toMatchObject({ batchCount: 2, seed: 10, seedStep: 1 });
+ expect(getProjectWidgetValues(getActiveProject(state), 'upscale').seed).toBe(12);
+ // Generate's own seed is not the one that moved.
+ expect(getProjectWidgetValues(getActiveProject(state), 'generate').seed).not.toBe(12);
+
+ const wanModel: ModelConfig = {
+ base: 'wan',
+ file_size: 1,
+ format: 'diffusers',
+ hash: 'wan-t2v-hash',
+ key: 'wan-t2v_a14b-diffusers',
+ name: 'Wan 2.2 t2v_a14b',
+ path: 'wan-t2v_a14b-diffusers',
+ source: 'wan-t2v_a14b-diffusers',
+ source_type: 'path',
+ type: 'main',
+ variant: 't2v_a14b',
+ };
+ state = workbenchReducer(createInitialWorkbenchState(), {
+ region: 'left',
+ type: 'toggleRegionWidget',
+ widgetId: 'video',
+ });
+ state = workbenchReducer(state, {
+ type: 'patchWidgetValues',
+ values: { batchCount: 3, model: wanModel, positivePrompt: 'a fox running', seed: 7, seedMode: 'decrement' },
+ widgetId: 'video',
+ });
+ state = workbenchReducer(state, { sourceId: 'video', type: 'setInvocationSource' });
+ state = workbenchReducer(state, { destination: 'gallery', type: 'setInvocationDestination' });
+ state = workbenchReducer(state, {
+ backendSupportsCancellation: true,
+ models: [wanModel],
+ type: 'submitInvocationSnapshot',
+ });
+
+ expect(readSubmission(state)).toMatchObject({ batchCount: 3, seed: 7, seedStep: -1 });
+ expect(getProjectWidgetValues(getActiveProject(state), 'video').seed).toBe(4);
+ });
+
describe('from the canvas, which compiles outside the reducer', () => {
const submitCanvas = (state: WorkbenchState, values: GenerateWidgetValues) =>
workbenchReducer(state, {
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
index b0ceb56cd7..65f086a188 100644
--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts
+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts
@@ -1,6 +1,6 @@
import type { GenerateWidgetValues } from '@features/generation/contracts';
import type { ModelConfig } from '@features/models';
-import type { QueueCompiledSubmission, QueueHistoryItemStatus, QueueSeedStep } from '@features/queue/contracts';
+import type { QueueCompiledSubmission, QueueHistoryItemStatus } from '@features/queue/contracts';
import type { ProjectGraphState } from '@features/workflow/contracts';
import type {
CanvasDocumentContractV3,
@@ -3153,25 +3153,15 @@ const enqueueCompiledSnapshot = (
// so `seed` is this submission's start. The plan fixes how the batch steps
// from it and where the editable seed goes next; a submission that fails or
// is cancelled later keeps its seeds — the sequence only ever moves forward.
- const seedModeSettings = canvasGenerateSettings ?? generateSettings;
- const seedPlan = seedModeSettings
+ const seedPlan = sourceGenerateSettings
? planSeedSubmission({
- batchCount: seedModeSettings.batchCount,
+ batchCount: sourceGenerateSettings.batchCount,
promptCount: expandedPositivePrompts?.length ?? 1,
seedBehaviour: expandedSeedBehaviour ?? 'per-iteration',
- seedMode: seedModeSettings.seedMode,
- startSeed: seedModeSettings.seed,
+ seedMode: sourceGenerateSettings.seedMode,
+ startSeed: sourceGenerateSettings.seed,
})
: null;
- // Upscale and Video keep their random toggle: on, the batch steps from the
- // drawn seed; off, it holds the entered one.
- const seedStep: QueueSeedStep = seedPlan
- ? seedPlan.step
- : sourceGenerateSettings &&
- 'shouldRandomizeSeed' in sourceGenerateSettings &&
- sourceGenerateSettings.shouldRandomizeSeed
- ? 1
- : 0;
const backendSubmission: QueueCompiledSubmission = !backendGraph
? { error: `${route.sourceId} queue item is missing a compiled backend graph.`, kind: 'invalid' }
: route.sourceId === 'workflow'
@@ -3203,7 +3193,7 @@ const enqueueCompiledSnapshot = (
seed: sourceGenerateSettings.seed,
...(expandedSeedBehaviour ? { seedBehaviour: expandedSeedBehaviour } : {}),
seedNodeId: generate?.seedNodeId ?? 'seed',
- seedStep,
+ seedStep: seedPlan?.step ?? 0,
}
: { error: `${route.sourceId} queue item is missing source submission metadata.`, kind: 'invalid' };
const selectedGalleryBoardId = widgetStates.gallery?.values.selectedBoardId;
@@ -3284,7 +3274,7 @@ const enqueueCompiledSnapshot = (
const advancedProject =
seedPlan === null || seedPlan.nextSeed === null
? project
- : updateProjectWidgetValues(project, 'generate', (values) =>
+ : updateProjectWidgetValues(project, route.sourceId === 'canvas' ? 'generate' : route.sourceId, (values) =>
values.seed === seedPlan.startSeed && values.seedMode === seedPlan.seedMode
? { ...values, seed: seedPlan.nextSeed }
: values