Stable Diffusion 调试一般分 4 层:
| 层级 | 常见问题 |
|---|---|
| 环境层 | CUDA / torch / xformers 版本不匹配 |
| 模型层 | 权重加载失败、精度错误 |
| 推理层 | 生成结果异常、显存爆炸 |
| 代码层 | 自定义 pipeline / 插件报错 |
SD 对版本非常敏感:
python - <<'PY'
import torch, sys
print(torch.__version__)
print(torch.version.cuda)
print(sys.version)
PY常见组合:
import torch
print(torch.cuda.is_available())
print(torch.cuda.memory_summary())如果 is_available() 为 False:
from safetensors.torch import load_file
state = load_file("model.safetensors")
print(len(state))常见问题:
| 模型 | 关键区别 |
|---|---|
| SD1.5 | 512×512 |
| SD2.1 | 768 |
| SDXL | 1024,结构不同 |
先跑官方最小代码:
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
image = pipe("a cat").images[0]如果这里就报错 → 环境或模型问题
generator = torch.Generator("cuda").manual_seed(42)
pipe(prompt, generator=generator)用于:
latents = pipe(
prompt,
output_type="latent",
return_dict=False
)[0]
print(latents.shape)可以看到:
正常:
异常:
--train_batch_size 1 --gradient_accumulation_steps 1python launch.py --debug| 报错 | 原因 |
|---|---|
| Out of memory | 分辨率太高 |
| shape mismatch | 模型与代码不匹配 |
| KeyError: 'lora' | 插件版本旧 |
torch.utils.bottlenecknvidia-smitensorboardpdb / breakpoint()print(latents.isnan().any())你可以告诉我:
我可以直接给你针对性排查步骤或改代码。