1
mirror of https://github.com/comfyanonymous/ComfyUI.git synced 2025-08-02 23:14:49 +08:00

Update sd1_clip.py (#3684)

Made token instance check more flexible so it also works with integers from numpy arrays or long tensors
This commit is contained in:
Mario Klingemann
2024-06-19 22:42:41 +02:00
committed by GitHub
parent e11052afcf
commit eee815ec99

View File

@@ -9,6 +9,7 @@ from . import model_management
import comfy.clip_model import comfy.clip_model
import json import json
import logging import logging
import numbers
def gen_empty_tokens(special_tokens, length): def gen_empty_tokens(special_tokens, length):
start_token = special_tokens.get("start", None) start_token = special_tokens.get("start", None)
@@ -130,10 +131,10 @@ class SDClipModel(torch.nn.Module, ClipTokenWeightEncoder):
for x in tokens: for x in tokens:
tokens_temp = [] tokens_temp = []
for y in x: for y in x:
if isinstance(y, int): if isinstance(y, numbers.Integral):
if y == token_dict_size: #EOS token if y == token_dict_size: #EOS token
y = -1 y = -1
tokens_temp += [y] tokens_temp += [int(y)]
else: else:
if y.shape[0] == current_embeds.weight.shape[1]: if y.shape[0] == current_embeds.weight.shape[1]:
embedding_weights += [y] embedding_weights += [y]