From 6b499ec49e3e3f06aa37c571d8333645e5a49764 Mon Sep 17 00:00:00 2001 From: City <125218114+city96@users.noreply.github.com> Date: Fri, 23 Aug 2024 02:13:48 +0200 Subject: [PATCH] Hotfix to work as normal tensor Fixes [ViT-L-14-BEST...] not working --- dequant.py | 8 +++++--- nodes.py | 4 ++-- ops.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/dequant.py b/dequant.py index 3a9aa71..f23aca6 100644 --- a/dequant.py +++ b/dequant.py @@ -6,10 +6,12 @@ from tqdm import tqdm def dequantize_tensor(tensor, dtype=torch.float16): data = torch.tensor(tensor.data) - qtype = tensor.tensor_type - oshape = tensor.tensor_shape + qtype = getattr(tensor, "tensor_type", None) + oshape = getattr(tensor, "tensor_shape", tensor.data.shape) - if qtype == gguf.GGMLQuantizationType.F32: + if qtype == None: + return data.to(dtype) + elif qtype == gguf.GGMLQuantizationType.F32: return data.to(dtype) elif qtype == gguf.GGMLQuantizationType.F16: return data.to(dtype) diff --git a/nodes.py b/nodes.py index 3451fc7..ee69c9e 100644 --- a/nodes.py +++ b/nodes.py @@ -190,10 +190,10 @@ class CLIPLoaderGGUF: # for some reason this is just missing in some SAI checkpoints if getattr(clip.cond_stage_model, "clip_l", None) is not None: - if clip.cond_stage_model.clip_l.transformer.text_projection.weight.tensor_shape == None: + if getattr(clip.cond_stage_model.clip_l.transformer.text_projection.weight, "tensor_shape", None) == None: clip.cond_stage_model.clip_l.transformer.text_projection = comfy.ops.manual_cast.Linear(768, 768) if getattr(clip.cond_stage_model, "clip_g", None) is not None: - if clip.cond_stage_model.clip_g.transformer.text_projection.weight.tensor_shape == None: + if getattr(clip.cond_stage_model.clip_g.transformer.text_projection.weight, "tensor_shape", None) == None: clip.cond_stage_model.clip_g.transformer.text_projection = comfy.ops.manual_cast.Linear(1280, 1280) return clip diff --git a/ops.py b/ops.py index d214fc6..6bc1e2a 100644 --- a/ops.py +++ b/ops.py @@ -21,9 +21,9 @@ class GGMLTensor(torch.Tensor): def to(self, *args, **kwargs): new = super().to(*args, **kwargs) - new.tensor_type = self.tensor_type - new.tensor_shape = self.tensor_shape - new.patches = self.patches.copy() + new.tensor_type = getattr(self, "tensor_type", None) + new.tensor_shape = getattr(self, "tensor_shape", new.data.shape) + new.patches = getattr(self, "patches", []).copy() return new def clone(self, *args, **kwargs):