From 3bb4dec720bd3be13a6fd381f641929386476efc Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Sat, 28 Sep 2024 14:42:14 -0400 Subject: [PATCH] Fix issue with loras, lowvram and --fast fp8. --- comfy/model_patcher.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/comfy/model_patcher.py b/comfy/model_patcher.py index 6ca124e6..2ba30633 100644 --- a/comfy/model_patcher.py +++ b/comfy/model_patcher.py @@ -88,8 +88,12 @@ def __init__(self, key, patches): self.key = key self.patches = patches def __call__(self, weight): - return comfy.lora.calculate_weight(self.patches[self.key], weight, self.key, intermediate_dtype=weight.dtype) + intermediate_dtype = weight.dtype + if intermediate_dtype not in [torch.float32, torch.float16, torch.bfloat16]: #intermediate_dtype has to be one that is supported in math ops + intermediate_dtype = torch.float32 + return comfy.float.stochastic_rounding(comfy.lora.calculate_weight(self.patches[self.key], weight.to(intermediate_dtype), self.key, intermediate_dtype=intermediate_dtype), weight.dtype, seed=string_to_seed(self.key)) + return comfy.lora.calculate_weight(self.patches[self.key], weight, self.key, intermediate_dtype=intermediate_dtype) class ModelPatcher: def __init__(self, model, load_device, offload_device, size=0, weight_inplace_update=False): self.size = size