目前魔乐社区的昇腾适配Kolors模型只包括原生版本,链接如下:https://modelers.cn/models/MindIE/kolors,不包括ip-adapters、inpainting、controlnet等模块,本项目因需求只进行了原生及ip-adapters、inpainting模块的昇腾适配。 魔乐社区适配的原生版本在并发执行时会存在异常推理问题,推理任务会异常报错并失败,主要原因是Unet结构迁移存在问题,也做了一些不必要的并发优化,如threadlocal。
本项目主要有如下适配工作: 1、适配Kolors,修复并发推理异常问题 2、适配新模块ip-adapaters 3、适配新模块inpainting
| 配套 | 版本 | 环境准备指导 |
|---|---|---|
| Python | 3.11.6 | - |
| torch | 2.1.0 | - |
| torch_npu | 2.1.0.post11 | - |
| diffusers | 0.35.1 | - |
| transformers | 4.44.0 | - |
| MindIE | 2.1RC1 | - |
| CANN | 8.2RC1 | - |
使用Mindie2.1RC1以上版本基础镜像均可
pip install diffusers==0.35.2修改两个文件配置
vim $Path_to_diffusers/models/attention_dispatch.py
注释@torch.libraryvim $Path_to_diffusers/pipelines/pipeline_loading_utils.py
注释variant_exists = is_folder and any(p.split(".")[1].startswith(variant) for p in os.listdir(folder_path)),并添加variant_exists = is_folder and any(variant in p for p in os.listdir(folder_path))注:这里未正确截取到fp16关键字,需要修改代码
单卡执行文生图原版推理任务
source /usr/local/Ascend/mindie/set_env.sh
model_base="../Path/to/weights/"
python3 infer.py \
--path=${model_base} \
--prompt_file="./prompts/prompts.txt" \
--height=896 \
--width=1408 \
--output_dir="./ip_images/output" \
--steps=20 \
--seed=666 \
--device_id=0 \
--cache_method="agb_cache"path:权重路径 prompt_file:提示词文本路径 height:生成图像高度 width:生成图像宽度 steps:扩散执行的步数 seed:随机种子,控制初始图像内容 device_id:执行任务的卡号 cache_method:使用缓存类型
单卡执行ip-adapters推理任务
source /usr/local/Ascend/mindie/set_env.sh
model_base="../Path/to/weights/"
python3 infer2.py \
--path=${model_base} \
--prompt_file="./prompts/prompts.txt" \
--height=896 \
--width=1408 \
--output_dir="./ip_images/output" \
--steps=20 \
--seed=666 \
--device_id=0 \
--cache_method="agb_cache"单卡执行inpainting推理任务
source /usr/local/Ascend/mindie/set_env.sh
model_base="../kolor-gpu/Kolors/weights/Kolors-Inpainting/"
python3 infer-inpainting.py \
--path=${model_base} \
--prompt_file="./prompts/prompts.txt" \
--height=896 \
--width=1408 \
--output_dir="./ip_images/output" \
--steps=20 \
--seed=666 \
--device_id=0 \
--cache_method="agb_cache"Ascend910b2 单卡 分辨率 896*1408 step 20执行时间
| 模式 | 推理执行时间 |
|---|---|
| Kolors | 3.85s |
| Kolors-ipadapters | 4.45s |
| Kolors-inpainting | 8.79s |