@@ -74,6 +74,7 @@ import {
74
74
getReferenceImageState ,
75
75
getRegionalGuidanceState ,
76
76
imageDTOToImageWithDims ,
77
+ initialControlLoRA ,
77
78
initialControlNet ,
78
79
initialIPAdapter ,
79
80
initialT2IAdapter ,
@@ -462,41 +463,63 @@ export const canvasSlice = createSlice({
462
463
}
463
464
layer . controlAdapter . model = zModelIdentifierField . parse ( modelConfig ) ;
464
465
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
+
465
469
switch ( layer . controlAdapter . model . type ) {
470
+ // Converting to T2I adapter from...
466
471
case 't2i_adapter' : {
467
472
if ( layer . controlAdapter . type === 'controlnet' ) {
473
+ // T2I Adapters have all the ControlNet properties, minus control mode - strip it
468
474
const { controlMode : _ , ...rest } = layer . controlAdapter ;
469
- const t2iAdapterConfig : T2IAdapterConfig = { ...rest , type : 't2i_adapter' } ;
475
+ const t2iAdapterConfig : T2IAdapterConfig = { ...initialT2IAdapter , ... rest , type : 't2i_adapter' } ;
470
476
layer . controlAdapter = t2iAdapterConfig ;
471
477
} 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
+ } ;
473
484
layer . controlAdapter = t2iAdapterConfig ;
474
485
}
475
486
break ;
476
487
}
477
488
489
+ // Converting to ControlNet from...
478
490
case 'controlnet' : {
479
491
if ( layer . controlAdapter . type === 't2i_adapter' ) {
492
+ // ControlNets have all the T2I Adapter properties, plus control mode
480
493
const controlNetConfig : ControlNetConfig = {
494
+ ...initialControlNet ,
481
495
...layer . controlAdapter ,
482
496
type : 'controlnet' ,
483
- controlMode : initialControlNet . controlMode ,
484
497
} ;
485
498
layer . controlAdapter = controlNetConfig ;
486
499
} 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
+ } ;
488
506
layer . controlAdapter = controlNetConfig ;
489
507
}
490
508
break ;
491
509
}
492
510
511
+ // Converting to ControlLoRA from...
493
512
case 'control_lora' : {
494
513
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 ;
497
518
} 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 ;
500
523
}
501
524
break ;
502
525
}
0 commit comments