diff --git a/__init__.py b/__init__.py index bf468ed..7364754 100644 --- a/__init__.py +++ b/__init__.py @@ -8,12 +8,6 @@ import folder_paths import comfy.sd import comfy.utils -class TensorEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, torch.Tensor): - return obj.cpu().tolist() - return super().default(obj) - class TensorEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, torch.Tensor): @@ -59,7 +53,7 @@ def pack_tensors(tensors): t = torch.zeros((1, 77, 768)) else: t = torch.zeros((1, 768)) - t = t.contiguous().cpu() + t = t.detach().contiguous().cpu() raw = t.numpy().tobytes() meta[name] = {"dtype": str(t.dtype), "shape": list(t.shape), "size": len(raw)} blobs.append(raw) @@ -146,9 +140,10 @@ class SendRemoteCLIP: log("Warning: invalid request, skipping") continue log(f"Encoding prompt ({len(meta['text'])} chars)") - tokens = CLIP.tokenize(meta["text"], **meta["kwargs"]) - cond, pooled = CLIP.encode_from_tokens(tokens, return_pooled=True) - tensor_meta, blob = pack_tensors({"cond": cond, "pooled": pooled}) + with torch.inference_mode(): + tokens = CLIP.tokenize(meta["text"], **meta["kwargs"]) + cond, pooled = CLIP.encode_from_tokens(tokens, return_pooled=True) + tensor_meta, blob = pack_tensors({"cond": cond, "pooled": pooled}) reply_meta = {"tensors": tensor_meta, "blob_size": len(blob)} send_packet(conn, reply_meta, blob) log(f"Sent embeddings ({len(blob)} bytes)") diff --git a/pyproject.toml b/pyproject.toml index 30db579..8da3632 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "remotecliploader" description = "" -version = "1.1.0" +version = "1.1.1" license = {file = "LICENSE"} # classifiers = [ # # For OS-independent nodes (works on all operating systems)