@@ -356,38 +356,43 @@ static T2IParamInput()
356356 }
357357 context . Loras ??= [ .. Program . T2IModelSets [ "LoRA" ] . ListModelNamesFor ( context . Input . SourceSession ) ] ;
358358 string matched = T2IParamTypes . GetBestModelInList ( lora , context . Loras ) ;
359- if ( matched is not null )
359+ if ( matched is null )
360360 {
361- List < string > loraList = context . Input . Get ( T2IParamTypes . Loras ) ;
362- List < string > weights = context . Input . Get ( T2IParamTypes . LoraWeights ) ;
363- List < string > confinements = context . Input . Get ( T2IParamTypes . LoraSectionConfinement ) ;
364- if ( loraList is null )
365- {
366- loraList = [ ] ;
367- weights = [ ] ;
368- }
369- loraList . Add ( matched ) ;
370- weights . Add ( strength . ToString ( ) ) ;
371- context . Input . Set ( T2IParamTypes . Loras , loraList ) ;
372- context . Input . Set ( T2IParamTypes . LoraWeights , weights ) ;
373- if ( context . SectionID > 0 )
361+ Logs . Warning ( $ "Lora '{ lora } ' does not exist and will be ignored.") ;
362+ return null ;
363+ }
364+ List < string > loraList = context . Input . Get ( T2IParamTypes . Loras ) ;
365+ List < string > weights = context . Input . Get ( T2IParamTypes . LoraWeights ) ;
366+ List < string > confinements = context . Input . Get ( T2IParamTypes . LoraSectionConfinement ) ;
367+ if ( loraList is null )
368+ {
369+ loraList = [ ] ;
370+ weights = [ ] ;
371+ }
372+ if ( confinements is not null && confinements . Count > loraList . Count )
373+ {
374+ context . Input . Remove ( T2IParamTypes . LoraSectionConfinement ) ;
375+ confinements = null ;
376+ }
377+ loraList . Add ( matched ) ;
378+ weights . Add ( strength . ToString ( ) ) ;
379+ context . Input . Set ( T2IParamTypes . Loras , loraList ) ;
380+ context . Input . Set ( T2IParamTypes . LoraWeights , weights ) ;
381+ if ( context . SectionID > 0 )
382+ {
383+ if ( confinements is null )
374384 {
375- if ( confinements is null )
385+ confinements = [ ] ;
386+ for ( int i = 0 ; i < loraList . Count - 1 ; i ++ )
376387 {
377- confinements = [ ] ;
378- for ( int i = 0 ; i < loraList . Count - 1 ; i ++ )
379- {
380- confinements . Add ( "0" ) ;
381- }
388+ confinements . Add ( "0" ) ;
382389 }
383- Logs . Verbose ( $ "LoRA { lora } confined to section { context . SectionID } .") ;
384- confinements . Add ( $ "{ context . SectionID } ") ;
385- context . Input . Set ( T2IParamTypes . LoraSectionConfinement , confinements ) ;
386390 }
387- return "" ;
391+ Logs . Verbose ( $ "LoRA { lora } confined to section { context . SectionID } .") ;
392+ confinements . Add ( $ "{ context . SectionID } ") ;
393+ context . Input . Set ( T2IParamTypes . LoraSectionConfinement , confinements ) ;
388394 }
389- Logs . Warning ( $ "Lora '{ lora } ' does not exist and will be ignored.") ;
390- return null ;
395+ return "" ;
391396 } ;
392397 PromptTagPostProcessors [ "segment" ] = ( data , context ) =>
393398 {
0 commit comments