|
2 | 2 |
|
3 | 3 | from transformers import CLIPTokenizer, CLIPTextModel, CLIPTextConfig |
4 | 4 | import torch |
| 5 | +import traceback |
5 | 6 |
|
6 | 7 | class ClipTokenWeightEncoder: |
7 | 8 | def encode_token_weights(self, token_weight_pairs): |
@@ -194,14 +195,21 @@ def load_embed(embedding_name, embedding_directory): |
194 | 195 |
|
195 | 196 | embed_path = valid_file |
196 | 197 |
|
197 | | - if embed_path.lower().endswith(".safetensors"): |
198 | | - import safetensors.torch |
199 | | - embed = safetensors.torch.load_file(embed_path, device="cpu") |
200 | | - else: |
201 | | - if 'weights_only' in torch.load.__code__.co_varnames: |
202 | | - embed = torch.load(embed_path, weights_only=True, map_location="cpu") |
| 198 | + try: |
| 199 | + if embed_path.lower().endswith(".safetensors"): |
| 200 | + import safetensors.torch |
| 201 | + embed = safetensors.torch.load_file(embed_path, device="cpu") |
203 | 202 | else: |
204 | | - embed = torch.load(embed_path, map_location="cpu") |
| 203 | + if 'weights_only' in torch.load.__code__.co_varnames: |
| 204 | + embed = torch.load(embed_path, weights_only=True, map_location="cpu") |
| 205 | + else: |
| 206 | + embed = torch.load(embed_path, map_location="cpu") |
| 207 | + except Exception as e: |
| 208 | + print(traceback.format_exc()) |
| 209 | + print() |
| 210 | + print("error loading embedding, skipping loading:", embedding_name) |
| 211 | + return None |
| 212 | + |
205 | 213 | if 'string_to_param' in embed: |
206 | 214 | values = embed['string_to_param'].values() |
207 | 215 | else: |
|
0 commit comments