Skip to content

Commit 28b7452

Browse files
psychedelicioushipsterusername
authored andcommitted
fix(ui): fix dynamic prompts with single prompt
Closes #5292 The special handling for single prompt is totally extraneous and caused a bug.
1 parent 9359c03 commit 28b7452

File tree

1 file changed

+71
-110
lines changed

1 file changed

+71
-110
lines changed

invokeai/frontend/web/src/features/nodes/util/graph/buildLinearBatchConfig.ts

Lines changed: 71 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -23,165 +23,126 @@ export const prepareLinearUIBatch = (
2323
const { prompts, seedBehaviour } = state.dynamicPrompts;
2424

2525
const data: Batch['data'] = [];
26+
const firstBatchDatumList: components['schemas']['BatchDatum'][] = [];
27+
const secondBatchDatumList: components['schemas']['BatchDatum'][] = [];
2628

27-
if (prompts.length === 1) {
29+
// add seeds first to ensure the output order groups the prompts
30+
if (seedBehaviour === 'PER_PROMPT') {
2831
const seeds = generateSeeds({
29-
count: iterations,
32+
count: prompts.length * iterations,
3033
start: shouldRandomizeSeed ? undefined : seed,
3134
});
3235

33-
const zipped: components['schemas']['BatchDatum'][] = [];
34-
3536
if (graph.nodes[NOISE]) {
36-
zipped.push({
37+
firstBatchDatumList.push({
3738
node_path: NOISE,
3839
field_name: 'seed',
3940
items: seeds,
4041
});
4142
}
4243

44+
// add to metadata
4345
if (getHasMetadata(graph)) {
44-
// add to metadata
4546
removeMetadata(graph, 'seed');
46-
zipped.push({
47+
firstBatchDatumList.push({
4748
node_path: METADATA,
4849
field_name: 'seed',
4950
items: seeds,
5051
});
5152
}
5253

5354
if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
54-
zipped.push({
55+
firstBatchDatumList.push({
5556
node_path: CANVAS_COHERENCE_NOISE,
5657
field_name: 'seed',
5758
items: seeds.map((seed) => (seed + 1) % NUMPY_RAND_MAX),
5859
});
5960
}
60-
61-
data.push(zipped);
6261
} else {
63-
// prompts.length > 1 aka dynamic prompts
64-
const firstBatchDatumList: components['schemas']['BatchDatum'][] = [];
65-
const secondBatchDatumList: components['schemas']['BatchDatum'][] = [];
66-
67-
// add seeds first to ensure the output order groups the prompts
68-
if (seedBehaviour === 'PER_PROMPT') {
69-
const seeds = generateSeeds({
70-
count: prompts.length * iterations,
71-
start: shouldRandomizeSeed ? undefined : seed,
62+
// seedBehaviour = SeedBehaviour.PerRun
63+
const seeds = generateSeeds({
64+
count: iterations,
65+
start: shouldRandomizeSeed ? undefined : seed,
66+
});
67+
68+
if (graph.nodes[NOISE]) {
69+
secondBatchDatumList.push({
70+
node_path: NOISE,
71+
field_name: 'seed',
72+
items: seeds,
7273
});
74+
}
7375

74-
if (graph.nodes[NOISE]) {
75-
firstBatchDatumList.push({
76-
node_path: NOISE,
77-
field_name: 'seed',
78-
items: seeds,
79-
});
80-
}
81-
82-
// add to metadata
83-
if (getHasMetadata(graph)) {
84-
removeMetadata(graph, 'seed');
85-
firstBatchDatumList.push({
86-
node_path: METADATA,
87-
field_name: 'seed',
88-
items: seeds,
89-
});
90-
}
91-
92-
if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
93-
firstBatchDatumList.push({
94-
node_path: CANVAS_COHERENCE_NOISE,
95-
field_name: 'seed',
96-
items: seeds.map((seed) => (seed + 1) % NUMPY_RAND_MAX),
97-
});
98-
}
99-
} else {
100-
// seedBehaviour = SeedBehaviour.PerRun
101-
const seeds = generateSeeds({
102-
count: iterations,
103-
start: shouldRandomizeSeed ? undefined : seed,
76+
// add to metadata
77+
if (getHasMetadata(graph)) {
78+
removeMetadata(graph, 'seed');
79+
secondBatchDatumList.push({
80+
node_path: METADATA,
81+
field_name: 'seed',
82+
items: seeds,
10483
});
84+
}
10585

106-
if (graph.nodes[NOISE]) {
107-
secondBatchDatumList.push({
108-
node_path: NOISE,
109-
field_name: 'seed',
110-
items: seeds,
111-
});
112-
}
113-
114-
// add to metadata
115-
if (getHasMetadata(graph)) {
116-
removeMetadata(graph, 'seed');
117-
secondBatchDatumList.push({
118-
node_path: METADATA,
119-
field_name: 'seed',
120-
items: seeds,
121-
});
122-
}
123-
124-
if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
125-
secondBatchDatumList.push({
126-
node_path: CANVAS_COHERENCE_NOISE,
127-
field_name: 'seed',
128-
items: seeds.map((seed) => (seed + 1) % NUMPY_RAND_MAX),
129-
});
130-
}
131-
data.push(secondBatchDatumList);
86+
if (graph.nodes[CANVAS_COHERENCE_NOISE]) {
87+
secondBatchDatumList.push({
88+
node_path: CANVAS_COHERENCE_NOISE,
89+
field_name: 'seed',
90+
items: seeds.map((seed) => (seed + 1) % NUMPY_RAND_MAX),
91+
});
13292
}
93+
data.push(secondBatchDatumList);
94+
}
95+
96+
const extendedPrompts =
97+
seedBehaviour === 'PER_PROMPT'
98+
? range(iterations).flatMap(() => prompts)
99+
: prompts;
100+
101+
// zipped batch of prompts
102+
if (graph.nodes[POSITIVE_CONDITIONING]) {
103+
firstBatchDatumList.push({
104+
node_path: POSITIVE_CONDITIONING,
105+
field_name: 'prompt',
106+
items: extendedPrompts,
107+
});
108+
}
109+
110+
// add to metadata
111+
if (getHasMetadata(graph)) {
112+
removeMetadata(graph, 'positive_prompt');
113+
firstBatchDatumList.push({
114+
node_path: METADATA,
115+
field_name: 'positive_prompt',
116+
items: extendedPrompts,
117+
});
118+
}
133119

134-
const extendedPrompts =
135-
seedBehaviour === 'PER_PROMPT'
136-
? range(iterations).flatMap(() => prompts)
137-
: prompts;
120+
if (shouldConcatSDXLStylePrompt && model?.base_model === 'sdxl') {
121+
const stylePrompts = extendedPrompts.map((p) =>
122+
[p, positiveStylePrompt].join(' ')
123+
);
138124

139-
// zipped batch of prompts
140125
if (graph.nodes[POSITIVE_CONDITIONING]) {
141126
firstBatchDatumList.push({
142127
node_path: POSITIVE_CONDITIONING,
143-
field_name: 'prompt',
144-
items: extendedPrompts,
128+
field_name: 'style',
129+
items: stylePrompts,
145130
});
146131
}
147132

148133
// add to metadata
149134
if (getHasMetadata(graph)) {
150-
removeMetadata(graph, 'positive_prompt');
135+
removeMetadata(graph, 'positive_style_prompt');
151136
firstBatchDatumList.push({
152137
node_path: METADATA,
153-
field_name: 'positive_prompt',
138+
field_name: 'positive_style_prompt',
154139
items: extendedPrompts,
155140
});
156141
}
157-
158-
if (shouldConcatSDXLStylePrompt && model?.base_model === 'sdxl') {
159-
const stylePrompts = extendedPrompts.map((p) =>
160-
[p, positiveStylePrompt].join(' ')
161-
);
162-
163-
if (graph.nodes[POSITIVE_CONDITIONING]) {
164-
firstBatchDatumList.push({
165-
node_path: POSITIVE_CONDITIONING,
166-
field_name: 'style',
167-
items: stylePrompts,
168-
});
169-
}
170-
171-
// add to metadata
172-
if (getHasMetadata(graph)) {
173-
removeMetadata(graph, 'positive_style_prompt');
174-
firstBatchDatumList.push({
175-
node_path: METADATA,
176-
field_name: 'positive_style_prompt',
177-
items: extendedPrompts,
178-
});
179-
}
180-
}
181-
182-
data.push(firstBatchDatumList);
183142
}
184143

144+
data.push(firstBatchDatumList);
145+
185146
const enqueueBatchArg: BatchConfig = {
186147
prepend,
187148
batch: {

0 commit comments

Comments
 (0)