From af1eb58be8ce7707f9884b8caac843661e9b4017 Mon Sep 17 00:00:00 2001 From: comfyanonymous <121283862+comfyanonymous@users.noreply.github.com> Date: Wed, 11 Jun 2025 12:09:11 -0700 Subject: [PATCH] Fix black images on some flux models in fp16. (#8495) --- comfy/ldm/flux/model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/comfy/ldm/flux/model.py b/comfy/ldm/flux/model.py index 53f27e3a7..09dd2482c 100644 --- a/comfy/ldm/flux/model.py +++ b/comfy/ldm/flux/model.py @@ -187,6 +187,9 @@ class Flux(nn.Module): if add is not None: img[:, txt.shape[1] :, ...] += add + if img.dtype == torch.float16: + img = torch.nan_to_num(img, nan=0.0, posinf=65504, neginf=-65504) + img = img[:, txt.shape[1] :, ...] img = self.final_layer(img, vec) # (N, T, patch_size ** 2 * out_channels)