fix(ui): create all scheduler constants up-front

This commit is contained in:
psychedelicious 2023-06-18 18:49:10 +10:00
parent f1a8b9daee
commit 150059f704
3 changed files with 22 additions and 20 deletions

View File

@ -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 }> = [

View File

@ -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(

View File

@ -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
*/