Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Hotfix for the div zero occurrence when memory_used_encode is 0 (#5121)

Dr.Lt.Data5f9d5a244b0c
diff --git a/comfy/sd.py b/comfy/sd.py
index feb1138d7..65d8117c4 100644
--- a/comfy/sd.py
+++ b/comfy/sd.py
@@ -347,7 +347,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):