From bb6ba3283af5c2a27d3afa9f1e6426ee5f2a9b8c Mon Sep 17 00:00:00 2001 From: "Dr.Lt.Data" Date: Wed, 2 Oct 2024 00:50:12 +0900 Subject: [PATCH] Hotfix for the div zero occurrence when memory_used_encode is 0 https://github.com/comfyanonymous/ComfyUI/issues/5069#issuecomment-2382656368 --- comfy/sd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comfy/sd.py b/comfy/sd.py index 99859d241..b8e549b59 100644 --- a/comfy/sd.py +++ b/comfy/sd.py @@ -348,7 +348,7 @@ class VAE: memory_used = self.memory_used_encode(pixel_samples.shape, self.vae_dtype) model_management.load_models_gpu([self.patcher], memory_required=memory_used) free_memory = model_management.get_free_memory(self.device) - batch_number = int(free_memory / memory_used) + batch_number = int(free_memory / max(1, memory_used)) batch_number = max(1, batch_number) samples = torch.empty((pixel_samples.shape[0], self.latent_channels) + tuple(map(lambda a: a // self.downscale_ratio, pixel_samples.shape[2:])), device=self.output_device) for x in range(0, pixel_samples.shape[0], batch_number):