【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)

相关推荐
华科大胡子44 分钟前
Chrome安全机制深度解析
python
易标AI1 小时前
标书智能体(四)——提示词顺序优化,让缓存命中,输入成本直降10倍
人工智能·python·提示词·智能体·招投标
深耕AI1 小时前
【VS Code 中 Python 虚拟环境降级完整指南(含 uv 工具实战)】
开发语言·python·uv
→长歌1 小时前
2026Java面试30题精解
java·python·面试
Bert.Cai1 小时前
pymysql自动提交设置
开发语言·python
吃一根烤肠1 小时前
Python调试革命:用ChatGPT Copilot快速定位复杂bug
python·chatgpt·copilot
小白学大数据2 小时前
攻克滑动拼图反爬:Python 高效爬取网页图片实战案例
开发语言·爬虫·python
阿荻在肝了3 小时前
Agent学习四:RAG 技术应用
python·学习·agent
ZC跨境爬虫3 小时前
Base64编码详解(含JS_Python实现+实战逆向案例)
前端·javascript·python
小陈工3 小时前
Python Web开发入门(八):用户认证系统实现,给你的应用加上安全锁
开发语言·前端·数据库·python·安全·django·sqlite