DreamShaper-XL-V2-Turbo — OpenVINO INT4
將 Lykon/dreamshaper-xl-v2-turbo(SDXL 6-step Turbo 蒸餾模型)
轉換為 OpenVINO INT4 權重,並以 純 CPU 實測 1024×1024 出圖。
optimum-intel 匯出 → NNCF weight-only INT4 量化 → FP16 6.5 GB → INT4 2.06 GB(↓ ~68%)。
完整的 192 vCPU 實測數據見下方「效能實測摘要」。
目錄
快速資訊
| 項目 | 內容 |
|---|---|
| 基座模型 | Lykon/dreamshaper-xl-v2-turbo |
| Pipeline | StableDiffusionXLPipeline(diffusers 格式) |
| Scheduler | EulerDiscreteScheduler(timestep_spacing=leading) |
| 量化格式 | UNet / text_encoder / text_encoder_2 → INT4;VAE → INT8 |
| 模型大小 | FP16 6.5 GB → INT4 2.06 GB(↓ ~68%) |
| 推論裝置 | CPU(OpenVINO CPU plugin,無需 GPU) |
| 推薦參數 | num_inference_steps=6、guidance_scale=2.0、1024×1024 |
| 轉換工具 | optimum 2.3.0 / optimum-intel 2.2.0 / OpenVINO 2026.4.0 / NNCF 3.4.0 |
特色
- 體積 ↓ 68%:FP16 6.5 GB → INT4 2.06 GB,CPU 記憶體需求大幅下降。
- 6 step 出圖:Turbo/Lightning 蒸餾模型,
guidance_scale=2.0即可出圖。 - 純 CPU 可用:不依賴 GPU / CUDA,OpenVINO 自動使用全部核心。
- diffusers 目錄結構:可直接
from_pretrained(),與原模型使用方式一致。 - 附 15 張實測圖:5 組 prompt × (1024px + 512px 對照組),另加 10 張風格展示。
- 附完整 benchmark:逐 step 耗時、記憶體、系統資訊記錄於
REPORT.md與examples/benchmark.json。
安裝
pip install diffusers==0.37.1 transformers==4.57.6 tokenizers==0.22.0 huggingface-hub==0.35.1 optimum==2.3.0 optimum-intel==2.2.0 openvino==2026.4.0 nncf==3.4.0 torch pillow psutil
僅推論時不需要
nncf;nncf為重新量化所需。
快速開始
import torch
from optimum.intel import OVDiffusionPipeline
pipe = OVDiffusionPipeline.from_pretrained("HelloSun/dreamshaper-xl-v2-turbo-OpenVINO-INT4", compile=True)
image = pipe(
prompt="Astronaut in a jungle, cold color palette, muted colors, "
"detailed, 8k, photorealistic, cinematic lighting",
height=1024, width=1024,
num_inference_steps=6, guidance_scale=2.0,
generator=torch.Generator().manual_seed(43),
).images[0]
image.save("out.png")
完整可執行範例:inference_int4.py 批次生成 5 組 + benchmark:generate5.py
推論參數建議
| 參數 | 建議值 | 說明 |
|---|---|---|
num_inference_steps | 6 | Turbo/Lightning 蒸餾步數。請勿增加,更多步數不會更好。 |
guidance_scale | 2.0 | Turbo/Lightning 的標準 CFG 值,調高容易劣化。 |
height / width | 1024 | SDXL 原生解析度。 |
compile=True | 開啟 | 編譯模型以取得較佳效能(代價為編譯時間)。 |
範例結果
全部為 6 steps / guidance 2.0 / CPU,seed 42–46 固定,可完全重現。
每組另附 512px 對照組(
examples/*_512.png),點擊圖片可看原始尺寸。
01_hanfu — seed 42 — 25.1 s
Young Chinese woman in red Hanfu, intricate embroidery, impeccable makeup, red floral forehead pattern, elaborate high bun, golden phoenix headdress, soft-lit outdoor night background, silhouetted tiered pagoda, blurred colorful distant lights, photorealistic, ultra detailed, 8k

02_astronaut — seed 43 — 22.3 s
Astronaut in a jungle, cold color palette, muted colors, detailed, 8k, photorealistic, cinematic lighting

03_taipei — seed 44 — 22.8 s
Cyberpunk street in Taipei at night, heavy rain, neon signs with text 'TAIPEI' and Chinese characters '台北', reflections on wet asphalt, crowded night market, cinematic, ultra detailed

04_shiba — seed 45 — 22.2 s
Cute Shiba Inu wearing a tiny astronaut helmet, sitting in a field of sunflowers under a starry sky, dreamy illustration, vibrant colors, high quality

05_ink — seed 46 — 21.2 s
Traditional Chinese ink wash landscape, misty mountains, a small pagoda on a cliff, cranes flying, minimalist, elegant, high aesthetic quality

風格展示
以下 10 張為 10 類風格 × 同一組 5 組基礎 prompt(seed 42–51), 使用與上方基準測試完全相同的推論設定。
注意:這批圖片沒有對應的
examples/benchmark.json紀錄,也沒有腳本可重現, 完整 prompt 亦未收錄於 repo(早期說明檔中的版本已被截斷,無法還原)。
traditional_painting · 傳統繪畫
油畫、版畫、水彩等傳統媒材

anime_manga · 動漫繪師
吉卜力 × 新海誠動畫風

digital_3d · 數位 3D
UE5 寫實渲染、CG 質感

photography_cinema · 攝影電影
電影感人像攝影

cultural_regional · 文化地域
敦煌壁畫、水墨等東方美學

material_craft · 材質工藝
絲線刺繡、陶瓷、木雕等

design_commercial · 平面商業
商業插畫、扁平幾何設計

abstract_generative · 抽象生成
分形、生成藝術

era_subculture · 復古次文化
80s 霓虹、賽博龐克

render_technique · 厚塗渲染
油畫厚塗、概念設定

效能實測摘要
完整逐 step 數據見 REPORT.md 與 examples/benchmark.json。
測試環境
| 項目 | 內容 |
|---|---|
| CPU | Intel(R) Xeon(R) Platinum 8559C |
| 拓撲 | 2 sockets × 48 cores × 2 threads/core = 192 vCPU(96 實體核心) |
| RAM | 2.0 TiB |
| 虛擬化 | KVM(完整虛擬化) |
| OpenVINO | CPU only,2026.4.0(build 2026.4.0-22959-99c81491cc3-releases/2026/4) |
| 設定 | num_inference_steps=6、guidance_scale=2.0、1024×1024 + 512×512 對照 |
總結
| 指標 | 主測組 | 對照組 |
|---|---|---|
| 解析度 | 1024×1024 | 512×512 |
| 平均總耗時 | 22.74 s / 張 | 7.20 s / 張 |
| 平均單步耗時 | 3.48 s | 1.12 s |
| 最快 / 最慢 | 21.24 s / 25.08 s | 6.79 s / 7.85 s |
| 對照組倍數 | — | 3.16× |
- 對照組為同一 prompt/seed 的 512×512 重新推理(非縮圖)。
- 文字編碼與 VAE decode 的時間已包含在總耗時內。
逐張結果(1024×1024 / 6 steps)
| # | Prompt | Seed | 總耗時 (s) | 平均單步 (s) | 512px 總耗時 (s) | 512px 單步 (s) | 推論後 RSS (GB) |
|---|---|---|---|---|---|---|---|
| 01 | hanfu | 42 | 25.08 | 3.81 | 7.51 | 1.16 | 10.52 |
| 02 | astronaut | 43 | 22.34 | 3.44 | 6.87 | 1.06 | 10.46 |
| 03 | taipei | 44 | 22.79 | 3.50 | 7.85 | 1.22 | 10.45 |
| 04 | shiba | 45 | 22.24 | 3.41 | 6.79 | 1.06 | 10.46 |
| 05 | ink | 46 | 21.24 | 3.26 | 6.97 | 1.09 | 10.46 |
| 平均 | 22.74 | 3.48 | 7.20 | 1.12 | 10.47 |
模型大小
以下為 repo 內 openvino_model.bin 的實際位元組數(Git LFS 記錄值)。
| 元件 | 位元組 | 大小 | 精度 |
|---|---|---|---|
unet | 1,496,655,568 | 1.50 GB | INT4 |
text_encoder_2 | 393,063,207 | 0.39 GB | INT4 |
text_encoder | 83,658,537 | 0.08 GB | INT4 |
vae_decoder | 49,557,592 | 0.05 GB | INT8 |
vae_encoder | 34,215,068 | 0.03 GB | INT8 |
| 合計 | 2,057,149,972 | 2.06 GB |
FP16 匯出模型約 6.5 GB(unet 4.8 GB + text_encoder_2 1.3 GB + text_encoder 236 MB + vae_decoder 95 MB + vae_encoder 66 MB)——此組數值取自原始轉換紀錄,非本 repo 的量測檔。
實際下載量請以本表為準:2.06 GB(另有 XML 與 tokenizer,實際略高於此值)。
檔案結構
.
├── README.md # 本文件
├── REPORT.md # 完整轉換 + 實測報告
├── model_index.json # diffusers pipeline 索引
├── openvino_config.json # OpenVINO 量化設定
├── inference_int4.py # 單張推論範例
├── generate5.py # 5 組 prompt 批次生成 + benchmark
├── quantize_int4.py # FP16 OV → INT4 OV 量化腳本
├── unet/ # INT4 UNet
├── vae_encoder/ # INT8 VAE encoder
├── vae_decoder/ # INT8 VAE decoder
├── text_encoder/ # INT4 CLIP text encoder
├── text_encoder_2/ # INT4 CLIP text encoder (projection)
├── tokenizer/ # CLIP tokenizer
├── tokenizer_2/ # CLIP tokenizer 2
├── scheduler/ # EulerDiscreteScheduler 設定
└── examples/ # 15 張實測圖 + benchmark.json + prompts.txt
├── *_1024.png # 主測組(5 張)
├── *_512.png # 對照組(5 張)
├── *_seed*_1024.png # 風格展示(10 張)
├── benchmark.json # 逐 step 耗時 + 記憶體 + 系統資訊
└── prompts.txt # 5 組 prompt 與 seed
從零復現
# 1. 匯出 FP16 OpenVINO 模型
optimum-cli export openvino \
-m Lykon/dreamshaper-xl-v2-turbo \
--task text-to-image \
--library diffusers \
--weight-format fp16 \
./dreamshaper-xl-v2-turbo-ov-fp16
# 2. NNCF weight-only INT4 量化
python quantize_int4.py --fp16-dir ./dreamshaper-xl-v2-turbo-ov-fp16 \
--int4-dir ./dreamshaper-xl-v2-turbo-ov-int4
# 3. 單張推論
python inference_int4.py
# 4. 批次生成 5 組 + 512px 對照 + benchmark
python generate5.py --outdir examples
量化設定:
from optimum.intel.openvino.configuration import (
OVConfig, OVWeightQuantizationConfig, OVPipelineQuantizationConfig,
)
int4_config = OVWeightQuantizationConfig(
bits=4, sym=False, group_size=128,
group_size_fallback="adjust", ratio=1.0,
)
pipeline_config = OVPipelineQuantizationConfig(
quantization_configs={
"unet": int4_config,
"text_encoder": int4_config,
"text_encoder_2": int4_config,
},
default_config=OVWeightQuantizationConfig(bits=8, sym=True),
)
已知限制
- 僅為 weight-only 量化:啟動時仍需即時量化權重,首次載入 + 編譯約 12 s。
- CPU 專用:本 repo 為 OpenVINO IR 格式,若要使用 GPU 請改用原模型或自行轉換。
- 6-step 蒸餾模型:設定
num_inference_steps > 6不會變好,反而可能劣化。 - INT4 為非對稱量化(
sym=False),與 FP16 原圖仍有細微差異。 - 風格展示圖無實測紀錄:10 張風格圖未納入 benchmark,完整 prompt 亦未收錄於 repo。
- 實測僅涵蓋 192 vCPU 伺服器:一般桌上型 CPU 的絕對數字會較慢,比例關係大致相同。
授權與出處
-
授權:
openrail++(沿用來源模型授權) -
轉換:僅做格式轉換與權重量化,模型權重來自來源模型
使用本模型時請一併遵守來源模型的授權條款與 OpenRAIL++ 使用政策。
Made with OpenVINO + optimum-intel + NNCF