Commit df8b4875 authored by Your Name's avatar Your Name

Fix diffusers NaN warning by using FP32 instead of FP16

- Changed torch_dtype from float16 (when CUDA available) to float32
- This prevents NaN/Infinity values in image output that cause black/corrupted images
- FP16 can cause numerical overflow on some models like SDXL
parent 55a39eeb
......@@ -3745,14 +3745,14 @@ async def create_image_generation(request: ImageGenerationRequest, http_request:
try:
pipeline = StableDiffusionXLPipeline.from_pretrained(
model_to_use,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
torch_dtype=torch.float32,
use_safetensors=True,
)
except Exception:
# Try generic diffusion pipeline
pipeline = DiffusionPipeline.from_pretrained(
model_to_use,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
torch_dtype=torch.float32,
use_safetensors=True,
)
......@@ -5854,7 +5854,7 @@ def main():
try:
pipeline = StableDiffusionXLPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
torch_dtype=torch.float32,
use_safetensors=True,
)
except Exception as e:
......@@ -5862,7 +5862,7 @@ def main():
# Try generic diffusion pipeline
pipeline = DiffusionPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
torch_dtype=torch.float32,
use_safetensors=True,
)
......@@ -6459,14 +6459,14 @@ def main():
try:
pipeline = StableDiffusionXLPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
torch_dtype=torch.float32,
use_safetensors=True,
)
except Exception as e:
print(f"SDXL failed, trying generic pipeline: {e}")
pipeline = DiffusionPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
torch_dtype=torch.float32,
use_safetensors=True,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment