@@ -77,25 +77,37 @@ export type AnyModelConfig =
7777 | MainModelConfig
7878 | CLIPVisionDiffusersConfig ;
7979
80- const check_submodel = ( submodels : AnyModelConfig [ 'submodels' ] , check_str : string ) : boolean => {
80+ /**
81+ * Checks if a list of submodels contains any that match a given variant or type
82+ * @param submodels The list of submodels to check
83+ * @param checkStr The string to check against for variant or type
84+ * @returns A boolean
85+ */
86+ const checkSubmodel = ( submodels : AnyModelConfig [ 'submodels' ] , checkStr : string ) : boolean => {
8187 for ( const submodel in submodels ) {
8288 if (
8389 submodel &&
8490 submodels [ submodel ] &&
85- ( submodels [ submodel ] . model_type === check_str || submodels [ submodel ] . variant === check_str )
91+ ( submodels [ submodel ] . model_type === checkStr || submodels [ submodel ] . variant === checkStr )
8692 ) {
8793 return true ;
8894 }
8995 }
9096 return false ;
9197} ;
9298
93- const check_submodels = ( indentifiers : string [ ] , config : AnyModelConfig ) : boolean => {
94- return indentifiers . every (
95- ( indentifier ) =>
99+ /**
100+ * Checks if a main model config has submodels that match a given variant or type
101+ * @param identifiers A list of strings to check against for variant or type in submodels
102+ * @param config The model config
103+ * @returns A boolean
104+ */
105+ const checkSubmodels = ( identifiers : string [ ] , config : AnyModelConfig ) : boolean => {
106+ return identifiers . every (
107+ ( identifier ) =>
96108 config . type === 'main' &&
97109 config . submodels &&
98- ( indentifier in config . submodels || check_submodel ( config . submodels , indentifier ) )
110+ ( identifier in config . submodels || checkSubmodel ( config . submodels , identifier ) )
99111 ) ;
100112} ;
101113
@@ -104,22 +116,22 @@ export const isLoRAModelConfig = (config: AnyModelConfig): config is LoRAModelCo
104116} ;
105117
106118export const isVAEModelConfig = ( config : AnyModelConfig , excludeSubmodels ?: boolean ) : config is VAEModelConfig => {
107- return config . type === 'vae' || ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 'vae' ] , config ) ) ;
119+ return config . type === 'vae' || ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 'vae' ] , config ) ) ;
108120} ;
109121
110122export const isNonFluxVAEModelConfig = (
111123 config : AnyModelConfig ,
112124 excludeSubmodels ?: boolean
113125) : config is VAEModelConfig => {
114126 return (
115- ( config . type === 'vae' || ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 'vae' ] , config ) ) ) &&
127+ ( config . type === 'vae' || ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 'vae' ] , config ) ) ) &&
116128 config . base !== 'flux'
117129 ) ;
118130} ;
119131
120132export const isFluxVAEModelConfig = ( config : AnyModelConfig , excludeSubmodels ?: boolean ) : config is VAEModelConfig => {
121133 return (
122- ( config . type === 'vae' || ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 'vae' ] , config ) ) ) &&
134+ ( config . type === 'vae' || ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 'vae' ] , config ) ) ) &&
123135 config . base === 'flux'
124136 ) ;
125137} ;
@@ -146,7 +158,7 @@ export const isT5EncoderModelConfig = (
146158) : config is T5EncoderModelConfig | T5EncoderBnbQuantizedLlmInt8bModelConfig => {
147159 return (
148160 config . type === 't5_encoder' ||
149- ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 't5_encoder' ] , config ) )
161+ ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 't5_encoder' ] , config ) )
150162 ) ;
151163} ;
152164
@@ -156,7 +168,7 @@ export const isCLIPEmbedModelConfig = (
156168) : config is CLIPEmbedModelConfig => {
157169 return (
158170 config . type === 'clip_embed' ||
159- ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 'clip_embed' ] , config ) )
171+ ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 'clip_embed' ] , config ) )
160172 ) ;
161173} ;
162174
@@ -166,7 +178,7 @@ export const isCLIPLEmbedModelConfig = (
166178) : config is CLIPLEmbedModelConfig => {
167179 return (
168180 ( config . type === 'clip_embed' && config . variant === 'large' ) ||
169- ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 'clip_embed' , 'large' ] , config ) )
181+ ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 'clip_embed' , 'large' ] , config ) )
170182 ) ;
171183} ;
172184
@@ -176,7 +188,7 @@ export const isCLIPGEmbedModelConfig = (
176188) : config is CLIPGEmbedModelConfig => {
177189 return (
178190 ( config . type === 'clip_embed' && config . variant === 'gigantic' ) ||
179- ( ! excludeSubmodels && config . type === 'main' && check_submodels ( [ 'clip_embed' , 'gigantic' ] , config ) )
191+ ( ! excludeSubmodels && config . type === 'main' && checkSubmodels ( [ 'clip_embed' , 'gigantic' ] , config ) )
180192 ) ;
181193} ;
182194
0 commit comments