Skip to content

The inference image is pure black. This seems to be related to weight, but I have been unable to pinpoint where the problem lies. #11989

@ShanZard

Description

@ShanZard

Describe the bug

I occasionally encounter situations where, when I restart my inference script again, the resulting image turns completely black. I haven't made any changes.

My intuition tells me that this is related to weight. I am currently a combination of SD and ControlNet, which I have trained on my own dataset. I can ensure that the ControlNet starts working, but sometimes it suddenly infers completely black images. I also checked some previous issues, but it doesn't seem to matter much. I sincerely hope you can guide me to locate the specific problem.

Reproduction

from PIL import Image
import torch
import os
import json
import re
from tqdm import tqdm
import numpy as np

negative_prompt = "blurry, not remote sensing image, distorted, GSD incorrect"
controlnet_model_name_or_path = '/opt/data/workspace/shanzhe/aaaitest/tempsave/controlnet-model-rule/checkpoint-31000'
pretrained_model_name_or_path = '/opt/data/workspace/shanzhe/shanzhemodels/stable-diffusion-3-medium-diffusers'
layout_path = '/opt/data/workspace/shanzhe/igmtestdataset/loveda_600/converted_masks/2_0_512_512_1024.png'

torch_dtype = torch.float16

controlnet = SD3ControlNetModel.from_pretrained(
controlnet_model_name_or_path,
subfolder="controlnet",
torch_dtype=torch_dtype,
)
pipe = StableDiffusion3ControlNetPipeline.from_pretrained(
pretrained_model_name_or_path,
controlnet=controlnet,
torch_dtype=torch_dtype,
).to("cuda")

layout_image = Image.open(layout_path).convert("RGB")
prompt = 'This ultra-high precision remote sensing image, provides a detailed view of a landscape characterized by a distinct juxtaposition of forested and agricultural areas.'
num_images = 2

generator = torch.Generator(device=pipe.device).manual_seed(2025)
images = pipe(
prompt=[prompt] * num_images,
negative_prompt=[negative_prompt] * num_images if negative_prompt else None,
control_image=[layout_image] * num_images,
generator=generator,
height=512,
width=512,
num_inference_steps=50,
guidance_scale=7.5,
max_sequence_length=512,
).images[0]
images.save("test_contrl_acc.png")

Logs

/opt/data/workspace/shanzhe/aaaitest/inference/checkblack.py 
Loading checkpoint shards: 100%|███████████████████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 10.06it/s]
Loading pipeline components...:  56%|████████████████████████████████████▋                             | 5/9 [00:01<00:00,  4.07it/s]You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers
Loading pipeline components...: 100%|██████████████████████████████████████████████████████████████████| 9/9 [00:01<00:00,  5.92it/s]
100%|████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:09<00:00,  5.17it/s]
/root/anaconda3/lib/python3.12/site-packages/diffusers/image_processor.py:148: RuntimeWarning: invalid value encountered in cast
  images = (images * 255).round().astype("uint8")

System Info

  • 🤗 Diffusers version: 0.34.0.dev0
  • Platform: Linux-6.11.0-26-generic-x86_64-with-glibc2.39
  • Running on Google Colab?: No
  • Python version: 3.12.7
  • PyTorch version (GPU?): 2.7.1+cu126 (True)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Huggingface_hub version: 0.33.0
  • Transformers version: 4.52.4
  • Accelerate version: 1.7.0
  • PEFT version: 0.15.2
  • Bitsandbytes version: not installed
  • Safetensors version: 0.5.3
  • xFormers version: not installed
  • Accelerator: NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
    NVIDIA L20, 46068 MiB
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

Who can help?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions