diff --git a/nodes.py b/nodes.py index 609716e..7957bd5 100644 --- a/nodes.py +++ b/nodes.py @@ -145,7 +145,7 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): if device_to is not None: out_weight = weight.to(device_to, copy=True) else: - out_weight = weight.clone() + out_weight = weight.to(weight.device, copy=True) # make sure patches are copied if self.patch_on_device: patches = move_patch_to_cuda(patches, self.load_device) @@ -165,6 +165,10 @@ class GGUFModelPatcher(comfy.model_patcher.ModelPatcher): else: comfy.utils.set_attr_param(self.model, key, out_weight) + def load(self, *args, force_patch_weights=False, **kwargs): + # always call `patch_weight_to_device` even for lowvram + return super().load(*args, force_patch_weights=True, **kwargs) + def clone(self, *args, **kwargs): n = GGUFModelPatcher(self.model, self.load_device, self.offload_device, self.size, weight_inplace_update=self.weight_inplace_update) n.patches = {} diff --git a/tools/convert.py b/tools/convert.py index a49ef1c..63bded9 100644 --- a/tools/convert.py +++ b/tools/convert.py @@ -109,6 +109,9 @@ def handle_tensors(args, writer, state_dict): if data.dtype == torch.bfloat16: data = data.to(torch.float32).numpy() + # this is so we don't break torch 2.0.X + elif data.dtype in [getattr(torch, "float8_e4m3fn", "_invalid"), getattr(torch, "float8_e5m2", "_invalid")]: + data = data.to(torch.float16).numpy() else: data = data.numpy()