From a4dec53b4d71ced1657a2159be991b98f5b15b88 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Fri, 7 Jul 2023 19:05:10 +1200 Subject: [PATCH 1/4] fix: Adjust clip skip layer count based on model --- .../Parameters/Advanced/ParamClipSkip.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx b/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx index a096d3d3fc..97a02b0c4b 100644 --- a/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx +++ b/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx @@ -5,11 +5,26 @@ import { setClipSkip } from 'features/parameters/store/generationSlice'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; +const clipSkipMap = { + 'sd-1': { + maxClip: 12, + markers: [0, 1, 2, 3, 4, 8, 12], + }, + 'sd-2': { + maxClip: 24, + markers: [0, 1, 2, 3, 5, 10, 15, 20, 24], + }, +}; + export default function ParamClipSkip() { const clipSkip = useAppSelector( (state: RootState) => state.generation.clipSkip ); + const selectedModelId = useAppSelector( + (state: RootState) => state.generation.model + ).split('/')[0]; + const dispatch = useAppDispatch(); const { t } = useTranslation(); @@ -29,12 +44,14 @@ export default function ParamClipSkip() { label={t('parameters.clipSkip')} aria-label={t('parameters.clipSkip')} min={0} - max={30} + max={clipSkipMap[selectedModelId as keyof typeof clipSkipMap].maxClip} step={1} value={clipSkip} onChange={handleClipSkipChange} withSliderMarks - sliderMarks={[0, 1, 2, 3, 5, 10, 15, 25, 30]} + sliderMarks={ + clipSkipMap[selectedModelId as keyof typeof clipSkipMap].markers + } withInput withReset handleReset={handleClipSkipReset} From 53cb200f856c266aa84f55adb29af82bec6b872c Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Fri, 7 Jul 2023 19:29:11 +1200 Subject: [PATCH 2/4] fix: Clamp clipskip value when model changes --- .../components/Parameters/Advanced/ParamClipSkip.tsx | 2 +- .../web/src/features/parameters/store/generationSlice.ts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx b/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx index 97a02b0c4b..a4f9d37f3c 100644 --- a/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx +++ b/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamClipSkip.tsx @@ -5,7 +5,7 @@ import { setClipSkip } from 'features/parameters/store/generationSlice'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -const clipSkipMap = { +export const clipSkipMap = { 'sd-1': { maxClip: 12, markers: [0, 1, 2, 3, 4, 8, 12], diff --git a/invokeai/frontend/web/src/features/parameters/store/generationSlice.ts b/invokeai/frontend/web/src/features/parameters/store/generationSlice.ts index 3e9356747d..0a5d358935 100644 --- a/invokeai/frontend/web/src/features/parameters/store/generationSlice.ts +++ b/invokeai/frontend/web/src/features/parameters/store/generationSlice.ts @@ -5,6 +5,7 @@ import { configChanged } from 'features/system/store/configSlice'; import { setShouldShowAdvancedOptions } from 'features/ui/store/uiSlice'; import { clamp } from 'lodash-es'; import { ImageDTO } from 'services/api/types'; +import { clipSkipMap } from '../components/Parameters/Advanced/ParamClipSkip'; import { CfgScaleParam, HeightParam, @@ -216,6 +217,12 @@ export const generationSlice = createSlice({ }, modelSelected: (state, action: PayloadAction) => { state.model = action.payload; + + // Clamp ClipSkip Based On Selected Model + const clipSkipMax = + clipSkipMap[action.payload.split('/')[0] as keyof typeof clipSkipMap] + .maxClip; + state.clipSkip = clamp(state.clipSkip, 0, clipSkipMax); }, vaeSelected: (state, action: PayloadAction) => { state.vae = action.payload; From 74557c8b6e7878b45ef1e6f71a34bf7aa4fc32c7 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Fri, 7 Jul 2023 23:27:21 +1200 Subject: [PATCH 3/4] fix: Loras breaking with clip skip --- .../nodes/util/graphBuilders/addLoRAsToGraph.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts index 9712ef4d5f..74cc8b1f57 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/addLoRAsToGraph.ts @@ -4,6 +4,7 @@ import { forEach, size } from 'lodash-es'; import { LoraLoaderInvocation } from 'services/api/types'; import { modelIdToLoRAModelField } from '../modelIdToLoRAName'; import { + CLIP_SKIP, LORA_LOADER, MAIN_MODEL_LOADER, NEGATIVE_CONDITIONING, @@ -27,14 +28,19 @@ export const addLoRAsToGraph = ( const loraCount = size(loras); if (loraCount > 0) { - // remove any existing connections from main model loader, we need to insert the lora nodes + // Remove MAIN_MODEL_LOADER unet connection to feed it to LoRAs graph.edges = graph.edges.filter( (e) => !( e.source.node_id === MAIN_MODEL_LOADER && - ['unet', 'clip'].includes(e.source.field) + ['unet'].includes(e.source.field) ) ); + // Remove CLIP_SKIP connections to conditionings to feed it through LoRAs + graph.edges = graph.edges.filter( + (e) => + !(e.source.node_id === CLIP_SKIP && ['clip'].includes(e.source.field)) + ); } // we need to remember the last lora so we can chain from it @@ -73,7 +79,7 @@ export const addLoRAsToGraph = ( graph.edges.push({ source: { - node_id: MAIN_MODEL_LOADER, + node_id: CLIP_SKIP, field: 'clip', }, destination: { From a8fc75b6d0f28ad40eadb26886456bc5a6acb172 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Fri, 7 Jul 2023 21:42:16 +1000 Subject: [PATCH 4/4] feat(ui): make clipSkip activeLabel "Clip Skip" we know its active if it displays --- .../components/Parameters/Advanced/ParamAdvancedCollapse.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamAdvancedCollapse.tsx b/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamAdvancedCollapse.tsx index 5eae7f2800..984ad833a6 100644 --- a/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamAdvancedCollapse.tsx +++ b/invokeai/frontend/web/src/features/parameters/components/Parameters/Advanced/ParamAdvancedCollapse.tsx @@ -11,7 +11,7 @@ const selector = createSelector( (state: RootState) => { const clipSkip = state.generation.clipSkip; return { - activeLabel: clipSkip > 0 ? `Clip Skip Active` : undefined, + activeLabel: clipSkip > 0 ? 'Clip Skip' : undefined, }; }, defaultSelectorOptions