From 150059f7049dfc85fe42944a7a3eea5c67ef6b64 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 18 Jun 2023 18:49:10 +1000 Subject: [PATCH] fix(ui): create all scheduler constants up-front --- invokeai/frontend/web/src/app/constants.ts | 34 ++++++++++--------- .../Parameters/Core/ParamScheduler.tsx | 4 +-- .../parameters/store/parameterZodSchemas.ts | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/invokeai/frontend/web/src/app/constants.ts b/invokeai/frontend/web/src/app/constants.ts index af125c7157..3f737b669b 100644 --- a/invokeai/frontend/web/src/app/constants.ts +++ b/invokeai/frontend/web/src/app/constants.ts @@ -1,6 +1,5 @@ import { SelectItem } from '@mantine/core'; -// TODO: use Enums? export const SCHEDULERS: SelectItem[] = [ { label: 'Euler', value: 'euler', group: 'Standard' }, { label: 'DEIS', value: 'deis', group: 'Standard' }, @@ -22,28 +21,31 @@ export const SCHEDULERS: SelectItem[] = [ { label: 'KDPM 2 Ancestral', value: 'kdpm_2_a', group: 'Ancestral' }, ]; -export const SCHEDULER_ITEMS = [ - 'ddim', - 'lms', - 'lms_k', +// zod needs the array to be `as const` to infer the type correctly +export const SCHEDULER_NAMES_AS_CONST = [ 'euler', - 'euler_k', - 'euler_a', - 'dpmpp_2s', - 'dpmpp_2s_k', - 'dpmpp_2m', - 'dpmpp_2m_k', - 'kdpm_2', - 'kdpm_2_a', 'deis', + 'ddim', 'ddpm', - 'pndm', + 'dpmpp_2s', + 'dpmpp_2m', 'heun', - 'heun_k', + 'kdpm_2', + 'lms', + 'pndm', 'unipc', + 'euler_k', + 'dpmpp_2s_k', + 'dpmpp_2m_k', + 'heun_k', + 'lms_k', + 'euler_a', + 'kdpm_2_a', ] as const; -export type Scheduler = (typeof SCHEDULER_ITEMS)[number]; +export const SCHEDULER_NAMES = [...SCHEDULER_NAMES_AS_CONST]; + +export type Scheduler = (typeof SCHEDULER_NAMES)[number]; // Valid upscaling levels export const UPSCALING_LEVELS: Array<{ label: string; value: string }> = [ diff --git a/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx b/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx index 1fed60fa74..321f57ca6f 100644 --- a/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx +++ b/invokeai/frontend/web/src/features/parameters/components/Parameters/Core/ParamScheduler.tsx @@ -1,4 +1,4 @@ -import { SCHEDULER_ITEMS, Scheduler } from 'app/constants'; +import { SCHEDULER_NAMES, Scheduler } from 'app/constants'; import { RootState } from 'app/store/store'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import IAIMantineSelect from 'common/components/IAIMantineSelect'; @@ -25,7 +25,7 @@ const ParamScheduler = () => { useEffect(() => { if (selectedSchedulers.length === 0) { - dispatch(setSelectedSchedulers([...SCHEDULER_ITEMS])); + dispatch(setSelectedSchedulers(SCHEDULER_NAMES)); } const schedulerFound = activeSchedulers.find( diff --git a/invokeai/frontend/web/src/features/parameters/store/parameterZodSchemas.ts b/invokeai/frontend/web/src/features/parameters/store/parameterZodSchemas.ts index b865faf121..61567d3fb8 100644 --- a/invokeai/frontend/web/src/features/parameters/store/parameterZodSchemas.ts +++ b/invokeai/frontend/web/src/features/parameters/store/parameterZodSchemas.ts @@ -1,4 +1,4 @@ -import { NUMPY_RAND_MAX, SCHEDULER_ITEMS } from 'app/constants'; +import { NUMPY_RAND_MAX, SCHEDULER_NAMES_AS_CONST } from 'app/constants'; import { z } from 'zod'; /** @@ -73,7 +73,7 @@ export const isValidCfgScale = (val: unknown): val is CfgScaleParam => /** * Zod schema for scheduler parameter */ -export const zScheduler = z.enum(SCHEDULER_ITEMS); +export const zScheduler = z.enum(SCHEDULER_NAMES_AS_CONST); /** * Type alias for scheduler parameter, inferred from its zod schema */