28
28
MainBnbQuantized4bCheckpointConfig ,
29
29
MainCheckpointConfig ,
30
30
T5EncoderConfig ,
31
+ T5Encoder8bConfig ,
31
32
VAECheckpointConfig ,
32
33
)
33
34
from invokeai .backend .model_manager .load .model_loader_registry import ModelLoaderRegistry
34
35
from invokeai .backend .model_manager .load .model_loaders .generic_diffusers import GenericDiffusersLoader
35
36
from invokeai .backend .quantization .bnb_nf4 import quantize_model_nf4
36
37
from invokeai .backend .util .silence_warnings import SilenceWarnings
38
+ from invokeai .backend .quantization .fast_quantized_transformers_model import FastQuantizedTransformersModel
37
39
38
40
app_config = get_config ()
39
41
@@ -82,15 +84,36 @@ def _load_model(
82
84
submodel_type : Optional [SubModelType ] = None ,
83
85
) -> AnyModel :
84
86
if not isinstance (config , CLIPEmbedDiffusersConfig ):
85
- raise Exception ("Only Checkpoint Flux models are currently supported." )
87
+ raise Exception ("Only CLIPEmbedDiffusersConfig models are currently supported here ." )
86
88
87
89
match submodel_type :
88
90
case SubModelType .Tokenizer :
89
91
return CLIPTokenizer .from_pretrained (config .path , max_length = 77 )
90
92
case SubModelType .TextEncoder :
91
93
return CLIPTextModel .from_pretrained (config .path )
92
94
93
- raise Exception ("Only Checkpoint Flux models are currently supported." )
95
+ raise Exception ("Only Tokenizer and TextEncoder submodels are currently supported." )
96
+
97
+
98
+ @ModelLoaderRegistry .register (base = BaseModelType .Any , type = ModelType .T5Encoder , format = ModelFormat .T5Encoder8b )
99
+ class T5Encoder8bCheckpointModel (GenericDiffusersLoader ):
100
+ """Class to load main models."""
101
+
102
+ def _load_model (
103
+ self ,
104
+ config : AnyModelConfig ,
105
+ submodel_type : Optional [SubModelType ] = None ,
106
+ ) -> AnyModel :
107
+ if not isinstance (config , T5Encoder8bConfig ):
108
+ raise Exception ("Only T5Encoder8bConfig models are currently supported here." )
109
+
110
+ match submodel_type :
111
+ case SubModelType .Tokenizer2 :
112
+ return T5Tokenizer .from_pretrained (Path (config .path ) / "tokenizer_2" , max_length = 512 )
113
+ case SubModelType .TextEncoder2 :
114
+ return FastQuantizedTransformersModel .from_pretrained (Path (config .path ) / "text_encoder_2" )
115
+
116
+ raise Exception ("Only Tokenizer and TextEncoder submodels are currently supported." )
94
117
95
118
96
119
@ModelLoaderRegistry .register (base = BaseModelType .Any , type = ModelType .T5Encoder , format = ModelFormat .T5Encoder )
@@ -103,7 +126,7 @@ def _load_model(
103
126
submodel_type : Optional [SubModelType ] = None ,
104
127
) -> AnyModel :
105
128
if not isinstance (config , T5EncoderConfig ):
106
- raise Exception ("Only Checkpoint Flux models are currently supported." )
129
+ raise Exception ("Only T5EncoderConfig models are currently supported here ." )
107
130
108
131
match submodel_type :
109
132
case SubModelType .Tokenizer2 :
@@ -113,7 +136,7 @@ def _load_model(
113
136
Path (config .path ) / "text_encoder_2"
114
137
) # TODO: Fix hf subfolder install
115
138
116
- raise Exception ("Only Checkpoint Flux models are currently supported." )
139
+ raise Exception ("Only Tokenizer and TextEncoder submodels are currently supported." )
117
140
118
141
119
142
@ModelLoaderRegistry .register (base = BaseModelType .Flux , type = ModelType .Main , format = ModelFormat .Checkpoint )
@@ -126,7 +149,7 @@ def _load_model(
126
149
submodel_type : Optional [SubModelType ] = None ,
127
150
) -> AnyModel :
128
151
if not isinstance (config , CheckpointConfigBase ):
129
- raise Exception ("Only Checkpoint Flux models are currently supported." )
152
+ raise Exception ("Only CheckpointConfigBase models are currently supported here ." )
130
153
legacy_config_path = app_config .legacy_conf_path / config .config_path
131
154
config_path = legacy_config_path .as_posix ()
132
155
with open (config_path , "r" ) as stream :
@@ -139,7 +162,7 @@ def _load_model(
139
162
case SubModelType .Transformer :
140
163
return self ._load_from_singlefile (config , flux_conf )
141
164
142
- raise Exception ("Only Checkpoint Flux models are currently supported." )
165
+ raise Exception ("Only Transformer submodels are currently supported." )
143
166
144
167
def _load_from_singlefile (
145
168
self ,
@@ -171,7 +194,7 @@ def _load_model(
171
194
submodel_type : Optional [SubModelType ] = None ,
172
195
) -> AnyModel :
173
196
if not isinstance (config , CheckpointConfigBase ):
174
- raise Exception ("Only Checkpoint Flux models are currently supported." )
197
+ raise Exception ("Only CheckpointConfigBase models are currently supported here ." )
175
198
legacy_config_path = app_config .legacy_conf_path / config .config_path
176
199
config_path = legacy_config_path .as_posix ()
177
200
with open (config_path , "r" ) as stream :
@@ -184,7 +207,7 @@ def _load_model(
184
207
case SubModelType .Transformer :
185
208
return self ._load_from_singlefile (config , flux_conf )
186
209
187
- raise Exception ("Only Checkpoint Flux models are currently supported." )
210
+ raise Exception ("Only Transformer submodels are currently supported." )
188
211
189
212
def _load_from_singlefile (
190
213
self ,
0 commit comments