Skip to content

Commit 334aab0

Browse files
Don't stop workflow if loading embedding fails.
1 parent 61e7767 commit 334aab0

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

comfy/sd1_clip.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from transformers import CLIPTokenizer, CLIPTextModel, CLIPTextConfig
44
import torch
5+
import traceback
56

67
class ClipTokenWeightEncoder:
78
def encode_token_weights(self, token_weight_pairs):
@@ -194,14 +195,21 @@ def load_embed(embedding_name, embedding_directory):
194195

195196
embed_path = valid_file
196197

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")
203202
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+
205213
if 'string_to_param' in embed:
206214
values = embed['string_to_param'].values()
207215
else:

0 commit comments

Comments
 (0)