模型名称: Lykon/dreamshaper-7
模型链接: HuggingFace
模型描述: DreamShaper 是一个文本到图像生成模型,基于 Stable Diffusion v1.2 架构微调。能够生成高质量、细节丰富的图像。
模型架构: Stable Diffusion v1.2 (Latent Diffusion Model)
参数规模: ~2.3B (fp16)
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch_npu | >= 2.1.0 | 昇腾 NPU 后端 |
| diffusers | >= 0.25.0 | 扩散模型 pipeline |
| transformers | >= 4.30.0 | HuggingFace Transformers |
| accelerate | >= 0.20.0 | 加速推理 |
| safetensors | >= 0.3.0 | 安全张量格式 |
| pillow | >= 9.0.0 | 图像处理 |
| 昇腾驱动 | CANN 8.0+ | 推荐 CANN 8.5.1 |
安装命令:
pip install torch torch_npu diffusers transformers accelerate safetensors pillow# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"# 使用 huggingface_hub 下载(设置 HF_ENDPOINT 为镜像加速)
export HF_ENDPOINT=https://hf-mirror.com
python3 -c "from huggingface_hub import snapshot_download; snapshot_download('Lykon/dreamshaper-7', local_dir='./dreamshaper-7')"DreamShaper-7 使用 diffusers StableDiffusionPipeline 进行推理,无需单独启动服务进程。 直接运行 inference.py 即可完成单条或批量推理调用。
# 单条推理
python inference.py \
--model-path ./dreamshaper-7 \
--prompt "a beautiful sunset over mountains, oil painting style" \
--num-inference-steps 20 \
--output output.png
# 批量推理 (4张)
python inference.py \
--model-path ./dreamshaper-7 \
--prompt "a cat sitting on a chair" \
--batch-size 4 \
--num-inference-steps 20 \
--output output.png[模型] Lykon/dreamshaper-7
[设备] Ascend910_9362 (npu:0)
[输入] Prompt: "a photo of a cat sitting on a chair, high quality, detailed"
[负向Prompt] "ugly, blurry, low quality, distorted"
[输出] 512x512 RGB image saved to output.png
[耗时] 1.8s (20 steps, ~0.09s/step)
[状态] SUCCESS[基准测试] 批量推理 (batch_size=1):
单条推理: 1.8s (512x512, 20 steps)
模型加载: 8.9s (cold start), 0.4s (cached)注意: 推理失败时必须输出
[状态] FAILED和错误信息,不得静默退出。
运行命令:
python inference.py \
--model-path ./dreamshaper-7 \
--prompt "a photo of a cat sitting on a chair, high quality, detailed" \
--negative-prompt "ugly, blurry, low quality, distorted" \
--num-inference-steps 20 \
--guidance-scale 7.5 \
--seed 42 \
--output output.png输出:
[INFO] NPU device: Ascend910_9362
[INFO] NPU count: 2
[INFO] Loading DreamShaper-7 from ./dreamshaper-7...
[INFO] Model loaded in 8.9s
[INFO] Generating image...
Prompt: a photo of a cat sitting on a chair, high quality, detailed
Negative prompt: ugly, blurry, low quality, distorted
Size: 512x512
Steps: 20
Guidance scale: 7.5
Seed: 42
100%|██████████| 20/20 [00:01<00:00, 16.35it/s]
[INFO] Image saved to output.png
[INFO] Inference time: 1.8s
[INFO] Time per step: 0.09s
[INFO] Done!运行命令:
python inference.py \
--model-path ./dreamshaper-7 \
--prompt "a beautiful sunset over mountains, oil painting style, dramatic lighting" \
--negative-prompt "ugly, blurry, low quality" \
--guidance-scale 7.5 \
--seed 12345 \
--output sunset.png输出:
[INFO] NPU device: Ascend910_9362
[INFO] NPU count: 2
[INFO] Model loaded in 8.9s
[INFO] Generating image...
Prompt: a beautiful sunset over mountains, oil painting style, dramatic lighting
Negative prompt: ugly, blurry, low quality
Size: 512x512
Steps: 20
Guidance scale: 7.5
Seed: 12345
100%|██████████| 20/20 [00:01<00:00, 16.35it/s]
[INFO] Image saved to sunset.png
[INFO] Inference time: 1.8s
[INFO] Time per step: 0.09s
[INFO] Done!


DreamShaper-7 是基于 Stable Diffusion v1.2 微调的文本到图像生成模型。以下为 Ascend 910 NPU 上的实际推理性能指标。
评测指标:
| 指标 | 结果 | Baseline | 差异 |
|---|---|---|---|
| 模型加载时间 (cold start) | 8.9s | - | Ascend910_9362, fp32 |
| 模型加载时间 (cached) | 0.4s | - | 组件已缓存 |
| 推理速度 (512x512, 20 steps) | 0.09s/step | - | Ascend910_9362, fp32 |
| 端到端推理 (512x512, 20 steps) | 1.8s | - | 含 post-processing |
| NPU 显存占用 | ~6.2GB (HBM) | - | UNet 3.3GB + VAE 0.3GB + Text Encoder 0.5GB |
推理性能统计(20步 512x512):
[基准测试] 5次推理统计:
平均: 1.8s
最小: 1.5s
最大: 2.0s
每步: ~0.09s评测命令:
# FID 评测需要 COCO 验证集(可选)
python -m torch_npu.distributed.launch --nproc_per_node=2 evaluate_fid.py \
--model-path ./dreamshaper-7 \
--coco-val-dir /path/to/coco/val2014 \
--coco-ann-file /path/to/coco/annotations/captions_val2014.json
# 单张推理验证
python inference.py \
--model-path ./dreamshaper-7 \
--prompt "a photo of a cat sitting on a chair" \
--num-inference-steps 20 \
--output output.pngsafety_checker 和 requires_safety_checker 为 True。