Skip to content
FramesField
FIX 26 · COMFYUI & LOCAL GPU
raw .md ↗ Verified Dec 1, 2026

Fix Pure Black or NaN Outputs on FLUX & Wan in ComfyUI

Direct Fix: Strip legacy --force-fp16 and --fp16-vae launch flags, run --bf16-vae on RTX 30/40/50 cards (or --fp32-vae --fp32-text-enc on RTX 20xx/GTX 16xx), match exact scaled FP8 weights with ae.safetensors or wan_2.1_vae.safetensors, and lock FLUX CFG to 1.0.
Exact Error / Visual Signature
Solid #000000 black PNG / flat gray video | UserWarning: NaN values detected in tensor | T5-XXL / UMT5 / FLUX ae.safetensors FP16 overflow on GTX 16xx or RTX 20xx–40xx
OBSERVED SYMPTOM

ComfyUI finishes all sampling steps with zero crash messages, yet SaveImage or SaveVideo writes a completely solid #000000 black image, pure static noise, or flat muddy gray frames—often accompanied by console warnings about NaN values in latent tensors or text-encoder activations.

TECHNICAL ROOT CAUSE

IEEE float16 overflows to Inf and NaN above 65,504. FLUX.1 text encoders (T5-XXL), Alibaba Wan 2.2 encoders (UMT5-XXL), and 16-channel VAEs routinely produce intermediate activations above 65,504, so forcing --force-fp16, --fp16-vae, mismatched FP8 dtypes, wrong VAEs, or high CFG on distilled models turns the decoded pixels into NaN clamped to pure black.

Copy-Paste Verified Fix

NaN-Safe ComfyUI Launch Wrapper & Automated Black-Frame Guard fix-comfyui-nan-black-frames.sh
#!/usr/bin/env bash
set -euo pipefail

# 1. Detect GPU compute capability to choose exact NaN-safe precision flags automatically
#    Compute >= 8.0 (RTX 30xx / 40xx / 50xx / A100 / L40): native BF16 -> --bf16-vae
#    Compute <  8.0 (RTX 20xx / GTX 16xx / T4 / V100):     no native BF16 -> --fp32-vae --fp32-text-enc
COMPUTE_CAP="$(nvidia-smi --query-gpu=compute_cap --format=csv,noheader | head -n 1 | tr -d ' ')"
MAJOR="${COMPUTE_CAP%%.*}"

export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True

if [ "$MAJOR" -ge 8 ]; then
  echo "Detected Ampere/Ada/Blackwell GPU (SM $COMPUTE_CAP) -> launching with --bf16-vae"
  python main.py --bf16-vae --lowvram --preview-method auto
else
  echo "Detected Turing/Volta/Pascal GPU (SM $COMPUTE_CAP) -> launching with --fp32-vae --fp32-text-enc"
  python main.py --fp32-vae --fp32-text-enc --lowvram --preview-method auto
fi

# 2. Required graph checklist (verify in ComfyUI UI or API JSON):
#    - FLUX.1 Schnell: weight_dtype="fp8_e4m3fn" | t5xxl_fp8_e4m3fn_scaled.safetensors | ae.safetensors | BasicGuider (NO FluxGuidance) | steps=4
#    - FLUX.1 Dev:     weight_dtype="fp8_e4m3fn" | FluxGuidance=3.5 | CFG=1.0 | steps=20-28
#    - Wan 2.2 I2V:    umt5_xxl_fp8_e4m3fn_scaled.safetensors | wan_2.1_vae.safetensors | ModelSamplingSD3 shift=5.0 | CFG=3.5

Before vs. After (Broken Pattern vs. Verified Fix)

Broken · NaN-Prone Launch & Graph (Legacy SD1.5 --force-fp16 + Wrong VAE + CFG 7.5)
# Legacy launch flags force 65,504 FP16 ceiling inside T5-XXL & FLUX VAE -> pure #000000 black!
python main.py --force-fp16 --fp16-vae
# Graph mistakes: weight_dtype="fp8_e5m2", SDXL VAE, or KSampler cfg=7.5 on FLUX Schnell
Verified · NaN-Safe Launch & Graph (BF16/FP32 VAE + Matched Scaled FP8 + Exact Guidance)
# RTX 30xx / 40xx / 50xx (native BF16 hardware):
python main.py --bf16-vae --lowvram

# RTX 20xx / GTX 16xx (no native BF16 -> force FP32 VAE & text encoder):
python main.py --fp32-vae --fp32-text-enc --lowvram
# Graph: UNETLoader weight_dtype="fp8_e4m3fn", ae.safetensors (FLUX) / wan_2.1_vae.safetensors (Wan), CFG=1.0

Why this works: Removing FP16 downcasting from T5/UMT5 and the VAE preserves BF16/FP32 exponent headroom above 65,504, eliminating NaN tensors completely while matching the exact VAE channel count and distilled guidance scale.

Under the Hood

Why This Failure Happens in Real Pipelines

The single biggest cause of pure black renders in ComfyUI is standard 16-bit floating-point overflow. Standard IEEE float16 allocates only 5 exponent bits, capping maximum representable magnitude at 65,504 before saturating to Infinity and NaN (Not a Number). Modern DiT architectures—including Black Forest Labs FLUX.1 (Dev, Schnell, Kontext), Alibaba Wan 2.2, and Lightricks LTX-2—were trained in bfloat16 (8 exponent bits, matching FP32 dynamic range up to 3.4e38). When you pass legacy SD1.5 launch flags like --force-fp16 or --fp16-vae, or run on Turing/Pascal NVIDIA cards (RTX 20-series, GTX 16-series) that lack native BF16 tensor cores, a single overflowing attention score inside T5-XXL or VAEDecode poisons the entire tensor with NaN, which PNG/MP4 writers clamp straight to RGB (0, 0, 0).

A second frequent culprit is mixing quantized checkpoint variants with incompatible loader dtypes or wrong VAE architectures. Loading an fp8_e4m3fn scaled weight with fp8_e5m2 precision degrades exponent scaling and triggers silent zeroed conditioning or color-blown artifacts. Likewise, leaving an old 4-channel SDXL VAE wired into a 16-channel FLUX latent (which requires ae.safetensors) or wiring an incompatible VAE into Wan 2.2 (which requires wan_2.1_vae.safetensors) either explodes latent variance or outputs flat black/rainbow frames.

Finally, guidance misconfiguration breaks distilled models even when numeric precision is healthy. FLUX.1 Schnell is timestep-distilled for 4 steps at effective CFG 1.0 with BasicGuider (no FluxGuidance node), and FLUX.1 Dev uses FluxGuidance=3.5 with KSampler/CFGGuider CFG locked to 1.0. Cranking standard classifier-free guidance to CFG 7.5–12.0 on FLUX or setting shift incorrectly in ModelSamplingSD3 drives denoised latents straight out of bounds, producing burnt neon static or solid black frames on step 3.

Step-by-Step Resolution & Verification

  1. 01

    Audit your startup script and strip every --force-fp16 or --fp16-vae flag

    Check run_nvidia_gpu.bat, systemd units, or shell aliases for legacy Stable Diffusion 1.5 FP16 flags. Replace them with --bf16-vae on RTX 30/40/50 cards or --fp32-vae --fp32-text-enc on older RTX 20/GTX 16 hardware.

  2. 02

    Match exact model weight_dtype, scaled T5/UMT5 encoder, and VAE file

    Confirm FLUX uses ae.safetensors plus t5xxl_fp8_e4m3fn_scaled.safetensors (or fp16 only with --fp32-text-enc) and Wan 2.2 uses wan_2.1_vae.safetensors plus umt5_xxl_fp8_e4m3fn_scaled.safetensors. Set UNETLoader weight_dtype to default or fp8_e4m3fn.

  3. 03

    Reset distilled guidance to spec and verify pixel extrema automatically

    Lock FLUX.1 Schnell to 4 steps with BasicGuider (no high CFG) and FLUX.1 Dev to FluxGuidance 3.5 with CFG 1.0, then run the PIL pixel-extrema check to confirm non-zero RGB channels.

Verification Check · Verify Decoded Output Contains Valid Pixel Variance (Zero Black/NaN Clamping)
python3 -c 'import sys; from PIL import Image; im=Image.open(sys.argv[1]).convert("RGB"); ext=im.getextrema(); print("RGB extrema:", ext); assert any(hi > 10 for _, hi in ext), "BLACK/NAN OUTPUT DETECTED"' ComfyUI/output/framesfield_schnell_apache_00001_.png
Expected healthy output:
RGB extrema: ((4, 248), (6, 244), (5, 239))   # Healthy dynamic range across all 3 channels (never (0, 0))

How to Prevent This Error From Recurring

GUARDRAIL 01

Separate legacy SD1.5 launch scripts from modern DiT (FLUX/Wan/LTX) scripts

Flags invented for 2022 SD1.5 cards (--force-fp16, --fp16-vae, --xformers) actively trigger NaN overflows on 2025–2026 BF16 diffusion transformers.

GUARDRAIL 02

Prefer fp8_e4m3fn_scaled text encoders over raw fp16 T5-XXL on consumer GPUs

Scaled FP8 encoders cut VRAM/RAM footprint in half while embedding per-tensor scale factors that prevent exponent overflow inside long prompts.

GUARDRAIL 03

Add an automated RGB extrema gate inside headless batch runners

Rejecting any rendered PNG whose max pixel intensity equals 0 catches broken LoRAs or precision regressions immediately instead of wasting an overnight 200-image batch.

Troubleshooting FAQs

Why does --fp32-vae fix black outputs without slowing down sampling much?
VAEDecode runs only once at the very end of generation (taking under 0.5 seconds for stills), whereas KSampler runs 20 to 30 times. Keeping the VAE in FP32 adds negligible render time while completely preventing 65,504 FP16 overflow.
Can a corrupt or mismatched LoRA also cause pure black FLUX or Wan frames?
Yes. Loading an SDXL LoRA onto FLUX, a Wan 2.1 LoRA with broken weights onto Wan 2.2, or stacking multiple LoRAs with combined strength above 1.5 can push hidden states to NaN. Disable all LoRA nodes first to isolate precision versus LoRA instability.
What is the difference between fp8_e4m3fn and fp8_e5m2 in ComfyUI UNETLoader?
fp8_e4m3fn allocates 3 mantissa bits for higher numerical precision (preferred for almost all FLUX, Qwen-Image, and Wan 2.2 weights), while fp8_e5m2 sacrifices mantissa detail for wider exponent range and often degrades fine faces or typography.
Why did my RTX 2080 Ti render black with --bf16-vae enabled?
Turing GPUs (RTX 20-series, compute capability 7.5) lack native hardware BF16 tensor cores, so PyTorch falls back inconsistently or downcasts during attention. Use --fp32-vae --fp32-text-enc on RTX 20-series and GTX 16-series cards.
Why do I get pure static noise instead of pure black on FLUX.1 Schnell?
Static noise usually indicates a scheduler or guidance mismatch rather than VAE NaN—verify you wired EmptySD3LatentImage (16-channel latent, NOT 4-channel EmptyLatentImage), BasicGuider (effective CFG 1.0), euler sampler, and simple scheduler.
Use this page in AI tools or notes
raw .md