DiTCache加速特性
以Qwen-Image-Edit-2509模型为例,展示如何使用DiTCache加速特性,进行模型优化。
前置准备
-
权重下载
- 原始权重来自HuggingFace
- 国内权重可使用此处
-
使用以下命令在任意路径(例如:/home/{用户名}/example/)下载模型代码并安装所需依赖
git clone https://modelers.cn/MindIE/Qwen-Image-Edit-2509.git && cd Qwen-Image-Edit-2509 pip install -r requirements.txt -
将
examples/cache目录下的cache.py文件拷贝到Qwen-Image-Edit-2509目录下。关于该模型的更多内容请参考魔乐社区。
使能DiTCache
执行以下命令开启cache优化并进行推理,通过对比开启cache前后的模型平均推理时间观察加速效果。
export COND_CACHE=1
export UNCOND_CACHE=1
python cache.py \
--model_path /mnt/data/Qwen-Image-Edit-2509 \
--device_id 0 \
--img_paths ./yarn-art-pikachu.png
参数说明:
- model_path: 模型权重路径。
- device_id: 执行模型推理的设备ID。
- img_paths: 输入图片路径,多图则用逗号分隔,如
img1,img2。
注:若关闭cache加速,将环境变量COND_CACHE和UNCOND_CACHE赋值为0。