🚀 DFloat11壓縮模型:black-forest-labs/FLUX.1-Canny-dev
本項目是使用自定義的 DFloat11 格式對 black-forest-labs/FLUX.1-Canny-dev
進行 無損壓縮 後的版本。該壓縮模型的輸出與原始的 BFloat16 模型 逐位相同,同時可將 GPU 內存消耗降低約 30%。
🚀 快速開始
安裝步驟
- 安裝或升級 DFloat11 的 pip 包(會自動安裝 CUDA 內核;需要支持 CUDA 的 GPU 並已安裝 PyTorch):
pip install -U dfloat11[cuda12]
- 安裝或升級 diffusers 和 controlnet_aux 包:
pip install -U diffusers controlnet_aux
使用示例
基礎用法
要使用 DFloat11 模型,請運行以下 Python 示例代碼:
import torch
from controlnet_aux import CannyDetector
from diffusers import FluxControlPipeline
from diffusers.utils import load_image
from dfloat11 import DFloat11Model
pipe = FluxControlPipeline.from_pretrained("black-forest-labs/FLUX.1-Canny-dev", torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload()
DFloat11Model.from_pretrained('DFloat11/FLUX.1-Canny-dev-DF11', device='cpu', bfloat16_model=pipe.transformer)
prompt = "A robot made of exotic candies and chocolates of different kinds. The background is filled with confetti and celebratory gifts."
control_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/robot.png")
processor = CannyDetector()
control_image = processor(control_image, low_threshold=50, high_threshold=200, detect_resolution=1024, image_resolution=1024)
image = pipe(
prompt=prompt,
control_image=control_image,
height=1024,
width=1024,
num_inference_steps=50,
guidance_scale=30.0,
).images[0]
image.save("output.png")
✨ 主要特性
工作原理
DFloat11 通過對 BFloat16 指數位進行 霍夫曼編碼 來壓縮模型權重,並結合 硬件感知的算法設計,實現了在 GPU 上直接進行高效的即時解壓縮。在推理過程中,權重在 GPU 內存中保持壓縮狀態,並在 矩陣乘法之前進行解壓縮,使用後 立即丟棄,以最小化內存佔用。
主要優勢
- 無需 CPU 解壓縮或主機 - 設備數據傳輸:所有操作均在 GPU 上完成。
- DFloat11 比 CPU 卸載方法快得多,可在內存受限的環境中進行實際部署。
- 壓縮是 完全無損的,保證模型的輸出與原始模型 逐位相同。
📚 詳細文檔
更多信息
📦 模型信息
屬性 |
詳情 |
基礎模型 |
black-forest-labs/FLUX.1-Canny-dev |
基礎模型關係 |
量化 |
任務類型 |
文本到圖像 |
標籤 |
dfloat11、df11、無損壓縮、70% 大小,100% 準確率 |