Skip to content

Commit 3428ea1

Browse files
feat(ui): use config for all numerical params
Centralize the initial/min/max/etc values for all numerical params. We used this for some but at some point stopped updating it. All numerical params now use their respective configs. Far fewer hardcoded values throughout the app now. Also updated the config types a bit to better accommodate slider vs number input constraints.
1 parent 6024fc7 commit 3428ea1

29 files changed

+530
-445
lines changed

invokeai/frontend/web/src/app/types/invokeai.ts

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ export type SDFeature =
4343
| 'vae'
4444
| 'hrf';
4545

46+
export type NumericalParameterConfig = {
47+
initial: number;
48+
sliderMin: number;
49+
sliderMax: number;
50+
numberInputMin: number;
51+
numberInputMax: number;
52+
fineStep: number;
53+
coarseStep: number;
54+
};
55+
4656
/**
4757
* Configuration options for the InvokeAI UI.
4858
* Distinct from system settings which may be changed inside the app.
@@ -66,69 +76,32 @@ export type AppConfig = {
6676
defaultModel?: string;
6777
disabledControlNetModels: string[];
6878
disabledControlNetProcessors: (keyof typeof CONTROLNET_PROCESSORS)[];
69-
iterations: {
70-
initial: number;
71-
min: number;
72-
sliderMax: number;
73-
inputMax: number;
74-
fineStep: number;
75-
coarseStep: number;
76-
};
77-
width: {
78-
initial: number;
79-
min: number;
80-
sliderMax: number;
81-
inputMax: number;
82-
fineStep: number;
83-
coarseStep: number;
84-
};
85-
height: {
86-
initial: number;
87-
min: number;
88-
sliderMax: number;
89-
inputMax: number;
90-
fineStep: number;
91-
coarseStep: number;
92-
};
93-
steps: {
94-
initial: number;
95-
min: number;
96-
sliderMax: number;
97-
inputMax: number;
98-
fineStep: number;
99-
coarseStep: number;
100-
};
101-
guidance: {
102-
initial: number;
103-
min: number;
104-
sliderMax: number;
105-
inputMax: number;
106-
fineStep: number;
107-
coarseStep: number;
108-
};
109-
img2imgStrength: {
110-
initial: number;
111-
min: number;
112-
sliderMax: number;
113-
inputMax: number;
114-
fineStep: number;
115-
coarseStep: number;
116-
};
117-
hrfStrength: {
118-
initial: number;
119-
min: number;
120-
sliderMax: number;
121-
inputMax: number;
122-
fineStep: number;
123-
coarseStep: number;
124-
};
79+
// Core parameters
80+
iterations: NumericalParameterConfig;
81+
width: NumericalParameterConfig; // initial value comes from model
82+
height: NumericalParameterConfig; // initial value comes from model
83+
steps: NumericalParameterConfig;
84+
guidance: NumericalParameterConfig;
85+
cfgRescaleMultiplier: NumericalParameterConfig;
86+
img2imgStrength: NumericalParameterConfig;
87+
// Canvas
88+
boundingBoxHeight: NumericalParameterConfig; // initial value comes from model
89+
boundingBoxWidth: NumericalParameterConfig; // initial value comes from model
90+
scaledBoundingBoxHeight: NumericalParameterConfig; // initial value comes from model
91+
scaledBoundingBoxWidth: NumericalParameterConfig; // initial value comes from model
92+
canvasCoherenceStrength: NumericalParameterConfig;
93+
canvasCoherenceSteps: NumericalParameterConfig;
94+
infillTileSize: NumericalParameterConfig;
95+
infillPatchmatchDownscaleSize: NumericalParameterConfig;
96+
// Misc advanced
97+
clipSkip: NumericalParameterConfig; // slider and input max are ignored for this, because the values depend on the model
98+
maskBlur: NumericalParameterConfig;
99+
hrfStrength: NumericalParameterConfig;
125100
dynamicPrompts: {
126-
maxPrompts: {
127-
initial: number;
128-
min: number;
129-
sliderMax: number;
130-
inputMax: number;
131-
};
101+
maxPrompts: NumericalParameterConfig;
102+
};
103+
ca: {
104+
weight: NumericalParameterConfig;
132105
};
133106
};
134107
};

invokeai/frontend/web/src/features/controlAdapters/components/parameters/ParamControlAdapterWeight.tsx

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useAppDispatch } from 'app/store/storeHooks';
1+
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
22
import { InvControl } from 'common/components/InvControl/InvControl';
33
import { InvControlGroup } from 'common/components/InvControl/InvControlGroup';
44
import { InvNumberInput } from 'common/components/InvNumberInput/InvNumberInput';
@@ -17,10 +17,22 @@ type ParamControlAdapterWeightProps = {
1717
const formatValue = (v: number) => v.toFixed(2);
1818

1919
const ParamControlAdapterWeight = ({ id }: ParamControlAdapterWeightProps) => {
20+
const { t } = useTranslation();
21+
const dispatch = useAppDispatch();
2022
const isEnabled = useControlAdapterIsEnabled(id);
2123
const weight = useControlAdapterWeight(id);
22-
const dispatch = useAppDispatch();
23-
const { t } = useTranslation();
24+
const initial = useAppSelector((s) => s.config.sd.ca.weight.initial);
25+
const sliderMin = useAppSelector((s) => s.config.sd.ca.weight.sliderMin);
26+
const sliderMax = useAppSelector((s) => s.config.sd.ca.weight.sliderMax);
27+
const numberInputMin = useAppSelector(
28+
(s) => s.config.sd.ca.weight.numberInputMin
29+
);
30+
const numberInputMax = useAppSelector(
31+
(s) => s.config.sd.ca.weight.numberInputMax
32+
);
33+
const coarseStep = useAppSelector((s) => s.config.sd.ca.weight.coarseStep);
34+
const fineStep = useAppSelector((s) => s.config.sd.ca.weight.fineStep);
35+
2436
const onChange = useCallback(
2537
(weight: number) => {
2638
dispatch(controlAdapterWeightChanged({ id, weight }));
@@ -43,23 +55,23 @@ const ParamControlAdapterWeight = ({ id }: ParamControlAdapterWeightProps) => {
4355
<InvSlider
4456
value={weight}
4557
onChange={onChange}
46-
defaultValue={1}
47-
min={0}
48-
max={2}
49-
step={0.05}
50-
fineStep={0.01}
58+
defaultValue={initial}
59+
min={sliderMin}
60+
max={sliderMax}
61+
step={coarseStep}
62+
fineStep={fineStep}
5163
marks={marks}
5264
formatValue={formatValue}
5365
/>
5466
<InvNumberInput
5567
value={weight}
5668
onChange={onChange}
57-
min={-1}
58-
max={2}
59-
step={0.05}
60-
fineStep={0.01}
69+
min={numberInputMin}
70+
max={numberInputMax}
71+
step={coarseStep}
72+
fineStep={fineStep}
6173
maxW={20}
62-
defaultValue={1}
74+
defaultValue={initial}
6375
/>
6476
</InvControl>
6577
</InvControlGroup>

invokeai/frontend/web/src/features/dynamicPrompts/components/ParamDynamicPromptsMaxPrompts.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ import { useTranslation } from 'react-i18next';
77

88
const ParamDynamicPromptsMaxPrompts = () => {
99
const maxPrompts = useAppSelector((s) => s.dynamicPrompts.maxPrompts);
10-
const min = useAppSelector((s) => s.config.sd.dynamicPrompts.maxPrompts.min);
10+
const sliderMin = useAppSelector(
11+
(s) => s.config.sd.dynamicPrompts.maxPrompts.sliderMin
12+
);
1113
const sliderMax = useAppSelector(
1214
(s) => s.config.sd.dynamicPrompts.maxPrompts.sliderMax
1315
);
14-
const inputMax = useAppSelector(
15-
(s) => s.config.sd.dynamicPrompts.maxPrompts.inputMax
16+
const numberInputMin = useAppSelector(
17+
(s) => s.config.sd.dynamicPrompts.maxPrompts.numberInputMin
18+
);
19+
const numberInputMax = useAppSelector(
20+
(s) => s.config.sd.dynamicPrompts.maxPrompts.numberInputMax
1621
);
1722
const initial = useAppSelector(
1823
(s) => s.config.sd.dynamicPrompts.maxPrompts.initial
@@ -36,14 +41,15 @@ const ParamDynamicPromptsMaxPrompts = () => {
3641
renderInfoPopoverInPortal={false}
3742
>
3843
<InvSlider
39-
min={min}
44+
min={sliderMin}
4045
max={sliderMax}
4146
value={maxPrompts}
4247
defaultValue={initial}
4348
onChange={handleChange}
4449
marks
4550
withNumberInput
46-
numberInputMax={inputMax}
51+
numberInputMin={numberInputMin}
52+
numberInputMax={numberInputMax}
4753
/>
4854
</InvControl>
4955
);

invokeai/frontend/web/src/features/hrf/components/ParamHrfStrength.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ import { useTranslation } from 'react-i18next';
88
const ParamHrfStrength = () => {
99
const hrfStrength = useAppSelector((s) => s.hrf.hrfStrength);
1010
const initial = useAppSelector((s) => s.config.sd.hrfStrength.initial);
11-
const min = useAppSelector((s) => s.config.sd.hrfStrength.min);
11+
const sliderMin = useAppSelector((s) => s.config.sd.hrfStrength.sliderMin);
1212
const sliderMax = useAppSelector((s) => s.config.sd.hrfStrength.sliderMax);
13+
const numberInputMin = useAppSelector(
14+
(s) => s.config.sd.hrfStrength.numberInputMin
15+
);
16+
const numberInputMax = useAppSelector(
17+
(s) => s.config.sd.hrfStrength.numberInputMax
18+
);
1319
const coarseStep = useAppSelector((s) => s.config.sd.hrfStrength.coarseStep);
1420
const fineStep = useAppSelector((s) => s.config.sd.hrfStrength.fineStep);
1521
const dispatch = useAppDispatch();
@@ -25,7 +31,7 @@ const ParamHrfStrength = () => {
2531
return (
2632
<InvControl label={t('parameters.denoisingStrength')}>
2733
<InvSlider
28-
min={min}
34+
min={sliderMin}
2935
max={sliderMax}
3036
step={coarseStep}
3137
fineStep={fineStep}
@@ -34,6 +40,8 @@ const ParamHrfStrength = () => {
3440
onChange={onChange}
3541
marks
3642
withNumberInput
43+
numberInputMin={numberInputMin}
44+
numberInputMax={numberInputMax}
3745
/>
3846
</InvControl>
3947
);

invokeai/frontend/web/src/features/parameters/components/Advanced/ParamCFGRescaleMultiplier.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ const ParamCFGRescaleMultiplier = () => {
99
const cfgRescaleMultiplier = useAppSelector(
1010
(s) => s.generation.cfgRescaleMultiplier
1111
);
12+
const initial = useAppSelector(
13+
(s) => s.config.sd.cfgRescaleMultiplier.initial
14+
);
15+
const sliderMin = useAppSelector(
16+
(s) => s.config.sd.cfgRescaleMultiplier.sliderMin
17+
);
18+
const sliderMax = useAppSelector(
19+
(s) => s.config.sd.cfgRescaleMultiplier.sliderMax
20+
);
21+
const numberInputMin = useAppSelector(
22+
(s) => s.config.sd.cfgRescaleMultiplier.numberInputMin
23+
);
24+
const numberInputMax = useAppSelector(
25+
(s) => s.config.sd.cfgRescaleMultiplier.numberInputMax
26+
);
27+
const coarseStep = useAppSelector(
28+
(s) => s.config.sd.cfgRescaleMultiplier.coarseStep
29+
);
30+
const fineStep = useAppSelector(
31+
(s) => s.config.sd.cfgRescaleMultiplier.fineStep
32+
);
33+
1234
const dispatch = useAppDispatch();
1335
const { t } = useTranslation();
1436

@@ -24,12 +46,14 @@ const ParamCFGRescaleMultiplier = () => {
2446
>
2547
<InvSlider
2648
value={cfgRescaleMultiplier}
27-
defaultValue={0}
28-
min={0}
29-
max={0.99}
30-
step={0.1}
31-
fineStep={0.01}
49+
defaultValue={initial}
50+
min={sliderMin}
51+
max={sliderMax}
52+
step={coarseStep}
53+
fineStep={fineStep}
3254
onChange={handleChange}
55+
numberInputMin={numberInputMin}
56+
numberInputMax={numberInputMax}
3357
withNumberInput
3458
marks
3559
/>

invokeai/frontend/web/src/features/parameters/components/Advanced/ParamClipSkip.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { useTranslation } from 'react-i18next';
88

99
const ParamClipSkip = () => {
1010
const clipSkip = useAppSelector((s) => s.generation.clipSkip);
11-
11+
const initial = useAppSelector((s) => s.config.sd.clipSkip.initial);
12+
const sliderMin = useAppSelector((s) => s.config.sd.clipSkip.sliderMin);
13+
const numberInputMin = useAppSelector(
14+
(s) => s.config.sd.clipSkip.numberInputMin
15+
);
16+
const coarseStep = useAppSelector((s) => s.config.sd.clipSkip.coarseStep);
17+
const fineStep = useAppSelector((s) => s.config.sd.clipSkip.fineStep);
1218
const { model } = useAppSelector((s) => s.generation);
1319

1420
const dispatch = useAppDispatch();
@@ -43,12 +49,15 @@ const ParamClipSkip = () => {
4349
<InvControl label={t('parameters.clipSkip')} feature="clipSkip">
4450
<InvSlider
4551
value={clipSkip}
46-
defaultValue={0}
47-
min={0}
52+
defaultValue={initial}
53+
min={sliderMin}
4854
max={max}
49-
step={1}
55+
step={coarseStep}
56+
fineStep={fineStep}
5057
onChange={handleClipSkipChange}
5158
withNumberInput
59+
numberInputMin={numberInputMin}
60+
numberInputMax={max}
5261
marks={sliderMarks}
5362
/>
5463
</InvControl>

0 commit comments

Comments
 (0)