Skip to content

Commit d764aa4

Browse files
psychedeliciousRyanJDick
authored andcommitted
fix(ui): ensure only the expected properties are used when converting between control layer adapter settings
1 parent ea34726 commit d764aa4

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

invokeai/frontend/web/src/features/controlLayers/store/canvasSlice.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import {
7474
getReferenceImageState,
7575
getRegionalGuidanceState,
7676
imageDTOToImageWithDims,
77+
initialControlLoRA,
7778
initialControlNet,
7879
initialIPAdapter,
7980
initialT2IAdapter,
@@ -462,41 +463,63 @@ export const canvasSlice = createSlice({
462463
}
463464
layer.controlAdapter.model = zModelIdentifierField.parse(modelConfig);
464465

466+
// When converting between control layer types, we may need to add or remove properties. For example, ControlNet
467+
// has a control mode, while T2I Adapter does not - otherwise they are the same.
468+
465469
switch (layer.controlAdapter.model.type) {
470+
// Converting to T2I adapter from...
466471
case 't2i_adapter': {
467472
if (layer.controlAdapter.type === 'controlnet') {
473+
// T2I Adapters have all the ControlNet properties, minus control mode - strip it
468474
const { controlMode: _, ...rest } = layer.controlAdapter;
469-
const t2iAdapterConfig: T2IAdapterConfig = { ...rest, type: 't2i_adapter' };
475+
const t2iAdapterConfig: T2IAdapterConfig = { ...initialT2IAdapter, ...rest, type: 't2i_adapter' };
470476
layer.controlAdapter = t2iAdapterConfig;
471477
} else if (layer.controlAdapter.type === 'control_lora') {
472-
const t2iAdapterConfig: T2IAdapterConfig = { ...layer.controlAdapter, ...initialT2IAdapter };
478+
// Control LoRAs have only model and weight
479+
const t2iAdapterConfig: T2IAdapterConfig = {
480+
...initialT2IAdapter,
481+
...layer.controlAdapter,
482+
type: 't2i_adapter',
483+
};
473484
layer.controlAdapter = t2iAdapterConfig;
474485
}
475486
break;
476487
}
477488

489+
// Converting to ControlNet from...
478490
case 'controlnet': {
479491
if (layer.controlAdapter.type === 't2i_adapter') {
492+
// ControlNets have all the T2I Adapter properties, plus control mode
480493
const controlNetConfig: ControlNetConfig = {
494+
...initialControlNet,
481495
...layer.controlAdapter,
482496
type: 'controlnet',
483-
controlMode: initialControlNet.controlMode,
484497
};
485498
layer.controlAdapter = controlNetConfig;
486499
} else if (layer.controlAdapter.type === 'control_lora') {
487-
const controlNetConfig: ControlNetConfig = { ...layer.controlAdapter, ...initialControlNet };
500+
// ControlNets have all the Control LoRA properties, plus control mode and begin/end step pct
501+
const controlNetConfig: ControlNetConfig = {
502+
...initialControlNet,
503+
...layer.controlAdapter,
504+
type: 'controlnet',
505+
};
488506
layer.controlAdapter = controlNetConfig;
489507
}
490508
break;
491509
}
492510

511+
// Converting to ControlLoRA from...
493512
case 'control_lora': {
494513
if (layer.controlAdapter.type === 'controlnet') {
495-
const controlLoraConfig: ControlLoRAConfig = { ...layer.controlAdapter, type: 'control_lora' };
496-
layer.controlAdapter = controlLoraConfig;
514+
// We only need the model and weight for Control LoRA
515+
const { model, weight } = layer.controlAdapter;
516+
const controlNetConfig: ControlLoRAConfig = { ...initialControlLoRA, model, weight };
517+
layer.controlAdapter = controlNetConfig;
497518
} else if (layer.controlAdapter.type === 't2i_adapter') {
498-
const controlLoraConfig: ControlLoRAConfig = { ...layer.controlAdapter, type: 'control_lora' };
499-
layer.controlAdapter = controlLoraConfig;
519+
// We only need the model and weight for Control LoRA
520+
const { model, weight } = layer.controlAdapter;
521+
const t2iAdapterConfig: ControlLoRAConfig = { ...initialControlLoRA, model, weight };
522+
layer.controlAdapter = t2iAdapterConfig;
500523
}
501524
break;
502525
}

0 commit comments

Comments
 (0)