Skip to content

Commit 40b4fa7

Browse files
psychedelicioushipsterusername
authored andcommitted
feat(ui): SDXL clip skip
Uses the same CLIP Skip value for both CLIP1 and CLIP2. Adjusted SDXL CLIP Skip min/max/markers to be within the valid range (0 to 11). Closes #4583
1 parent 3b1743b commit 40b4fa7

File tree

4 files changed

+26
-13
lines changed

4 files changed

+26
-13
lines changed

invokeai/frontend/web/src/features/nodes/util/graph/generation/addSDXLLoRAs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export const addSDXLLoRas = (
1111
denoise: Invocation<'denoise_latents'>,
1212
modelLoader: Invocation<'sdxl_model_loader'>,
1313
seamless: Invocation<'seamless'> | null,
14+
clipSkip: Invocation<'clip_skip'>,
15+
clipSkip2: Invocation<'clip_skip'>,
1416
posCond: Invocation<'sdxl_compel_prompt'>,
1517
negCond: Invocation<'sdxl_compel_prompt'>
1618
): void => {
@@ -37,8 +39,8 @@ export const addSDXLLoRas = (
3739
g.addEdge(loraCollector, 'collection', loraCollectionLoader, 'loras');
3840
// Use seamless as UNet input if it exists, otherwise use the model loader
3941
g.addEdge(seamless ?? modelLoader, 'unet', loraCollectionLoader, 'unet');
40-
g.addEdge(modelLoader, 'clip', loraCollectionLoader, 'clip');
41-
g.addEdge(modelLoader, 'clip2', loraCollectionLoader, 'clip2');
42+
g.addEdge(clipSkip, 'clip', loraCollectionLoader, 'clip');
43+
g.addEdge(clipSkip2, 'clip', loraCollectionLoader, 'clip2');
4244
// Reroute UNet & CLIP connections through the LoRA collection loader
4345
g.deleteEdgesTo(denoise, ['unet']);
4446
g.deleteEdgesTo(posCond, ['clip', 'clip2']);

invokeai/frontend/web/src/features/nodes/util/graph/generation/buildGenerationTabSDXLGraph.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { RootState } from 'app/store/store';
22
import { fetchModelConfigWithTypeGuard } from 'features/metadata/util/modelFetchingHelpers';
33
import {
4+
CLIP_SKIP,
45
LATENTS_TO_IMAGE,
56
NEGATIVE_CONDITIONING,
67
NEGATIVE_CONDITIONING_COLLECT,
@@ -29,6 +30,7 @@ export const buildGenerationTabSDXLGraph = async (state: RootState): Promise<Non
2930
model,
3031
cfgScale: cfg_scale,
3132
cfgRescaleMultiplier: cfg_rescale_multiplier,
33+
clipSkip: skipped_layers,
3234
scheduler,
3335
seed,
3436
steps,
@@ -51,6 +53,16 @@ export const buildGenerationTabSDXLGraph = async (state: RootState): Promise<Non
5153
id: SDXL_MODEL_LOADER,
5254
model,
5355
});
56+
const clipSkip = g.addNode({
57+
type: 'clip_skip',
58+
id: CLIP_SKIP,
59+
skipped_layers,
60+
});
61+
const clipSkip2 = g.addNode({
62+
type: 'clip_skip',
63+
id: `${CLIP_SKIP}_2`,
64+
skipped_layers,
65+
});
5466
const posCond = g.addNode({
5567
type: 'sdxl_compel_prompt',
5668
id: POSITIVE_CONDITIONING,
@@ -103,10 +115,12 @@ export const buildGenerationTabSDXLGraph = async (state: RootState): Promise<Non
103115
let imageOutput: Invocation<'l2i'> | Invocation<'img_nsfw'> | Invocation<'img_watermark'> = l2i;
104116

105117
g.addEdge(modelLoader, 'unet', denoise, 'unet');
106-
g.addEdge(modelLoader, 'clip', posCond, 'clip');
107-
g.addEdge(modelLoader, 'clip', negCond, 'clip');
108-
g.addEdge(modelLoader, 'clip2', posCond, 'clip2');
109-
g.addEdge(modelLoader, 'clip2', negCond, 'clip2');
118+
g.addEdge(modelLoader, 'clip', clipSkip, 'clip');
119+
g.addEdge(modelLoader, 'clip2', clipSkip2, 'clip');
120+
g.addEdge(clipSkip, 'clip', posCond, 'clip');
121+
g.addEdge(clipSkip, 'clip', negCond, 'clip');
122+
g.addEdge(clipSkip2, 'clip', posCond, 'clip2');
123+
g.addEdge(clipSkip2, 'clip', negCond, 'clip2');
110124
g.addEdge(posCond, 'conditioning', posCondCollect, 'item');
111125
g.addEdge(negCond, 'conditioning', negCondCollect, 'item');
112126
g.addEdge(posCondCollect, 'collection', denoise, 'positive_conditioning');
@@ -132,12 +146,13 @@ export const buildGenerationTabSDXLGraph = async (state: RootState): Promise<Non
132146
scheduler,
133147
positive_style_prompt: positiveStylePrompt,
134148
negative_style_prompt: negativeStylePrompt,
149+
clip_skip: skipped_layers,
135150
vae: vae ?? undefined,
136151
});
137152

138153
const seamless = addSeamless(state, g, denoise, modelLoader, vaeLoader);
139154

140-
addSDXLLoRas(state, g, denoise, modelLoader, seamless, posCond, negCond);
155+
addSDXLLoRas(state, g, denoise, modelLoader, seamless, clipSkip, clipSkip2, posCond, negCond);
141156

142157
// We might get the VAE from the main model, custom VAE, or seamless node.
143158
const vaeSource = seamless ?? vaeLoader ?? modelLoader;

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ const ParamClipSkip = () => {
3939
return CLIP_SKIP_MAP[model.base].markers;
4040
}, [model]);
4141

42-
if (model?.base === 'sdxl') {
43-
return null;
44-
}
45-
4642
return (
4743
<FormControl>
4844
<InformationalPopover feature="clipSkip">

invokeai/frontend/web/src/features/parameters/types/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const CLIP_SKIP_MAP = {
3939
markers: [0, 1, 2, 3, 5, 10, 15, 20, 24],
4040
},
4141
sdxl: {
42-
maxClip: 24,
43-
markers: [0, 1, 2, 3, 5, 10, 15, 20, 24],
42+
maxClip: 11,
43+
markers: [0, 1, 2, 5, 11],
4444
},
4545
'sdxl-refiner': {
4646
maxClip: 24,

0 commit comments

Comments
 (0)