【bug】可图文生图模型 KolorsPipeline IndexError: list index out of range

【bug】可图文生图模型 KolorsPipeline IndexError: list index out of range

环境

shell 复制代码
linux
diffusers     0.30.0

问题详情

报错详情

python 复制代码
from diffusers import KolorsPipeline

Traceback (most recent call last):
  File "Kolors/demo.py", line 6, in <module>
    pipe = KolorsPipeline.from_pretrained(
  File ".conda/envs/xxx/lib/python3.10/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File ".conda/envs/xxx/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 732, in from_pretrained
    variant_exists = is_folder and any(
  File ".conda/envs/xxx/lib/python3.10/site-packages/diffusers/pipelines/pipeline_utils.py", line 733, in <genexpr>
    p.split(".")[1].startswith(variant) for p in os.listdir(folder_path)
IndexError: list index out of range

运行代码

python 复制代码
import torch
from diffusers import KolorsPipeline

# 模型地址,可以改为本地离线地址
root_dir = "Kwai-Kolors/Kolors-diffusers"

pipe = KolorsPipeline.from_pretrained(
    root_dir, 
    torch_dtype=torch.float16, 
    variant="fp16"
).to("cuda")
prompt = '一张瓢虫的照片,微距,变焦,高质量,电影,拿着一个牌子,写着"可图"'
image = pipe(
    prompt=prompt,
    negative_prompt="",
    guidance_scale=5.0,
    num_inference_steps=50,
    generator=torch.Generator(pipe.device).manual_seed(66),
).images[0]
# image.show()

image.save("image.jpg")

错误说明

这个错误是由于模型中text_encoder文件夹下存在 __pycache__文件夹导致模型加载错误。

解决方法

解决方法是删除 text_encoder 文件夹下的 __pycache__文件夹。

我的模型是在可图 · 模型库 (modelscope.cn)下载的,官方没有去掉 __pycache__

如果是在Kwai-Kolors/Kolors-diffusers at main (huggingface.co) 下载,官方去掉了 __pycache__文件夹,因此不会出现这个错误

参考

Support for Kolors · Issue #8801 · huggingface/diffusers (github.com)

相关推荐
AC赳赳老秦14 分钟前
采购专员自动化:OpenClaw 自动比价、生成询价单、跟踪供应商报价进度实战指南
开发语言·数据库·人工智能·python·自动化·github·openclaw
ednO8nqdR32 分钟前
Python小游戏制作:如何实现可配置的跨分辨率界面布局
python·plotly·django·virtualenv·scikit-learn·fastapi·pygame
林泽毅40 分钟前
Qwen3.5 DPO 模型对齐实战(pytrio训练版)
人工智能·python·算法
荣码1 小时前
LangGraph多步工作流:Agent不够用的时候,我踩了4个坑
java·python
曲幽1 小时前
从卡顿到丝滑:FastAPI 调用外部 API 的正确姿势(httpx 实战)
python·fastapi·web·async·httpx·client·await·requests·aiohttp
不瘦80斤不改名1 小时前
HalfCart:基于LBS的1\.5km本地拼单系统全栈实践与踩坑复盘
python·docker·typescript·pycharm
深盾科技_Virbox2 小时前
软件交付保护如何从加壳走向代码虚拟化
java·python·安全
wok1572 小时前
Git Bash 执行中文命令报错 127:MSYS 参数编码 bug 排查与修复
git·bug·bash
YUS云生2 小时前
Python学习笔记·第28天:Git入门——版本控制与基础操作
笔记·python·学习
Bryce学亮2 小时前
1688 半自动化拟人浏览信息处理工具爬虫
爬虫·python