集成Hotshot-XL的AI视频生成应用导入inference.py报错求助
问题描述
我正在开发一款集成Hotshot-XL的AI视频生成应用,直接从GitHub克隆的inference.py可以正常运行,但修改该文件的main函数参数定义后,将其导入自研应用中调用时,触发以下报错:
ValueError: unet/hotshot_xl.py as defined in model_index.json does not exist in hotshotco/Hotshot-XL and is not a module in 'diffusers/pipelines'
修改后的inference.py仅调整了main函数的参数定义(代码如下),在自研应用中调用该main函数传入参数生成GIF时出现上述错误。
修改后的inference.py代码片段
def main(pretrained_path='hotshotco/Hotshot-XL', xformers=False, spatial_unet_base=None, lora=None, output='output_scuba.gif', steps=30, prompt='Sasquatch scuba diving, anime style', negative_prompt='blurry', seed=455, width=672, height=384, target_width=512, target_height=512, og_width=1920, og_height=1080, video_length=8, video_duration=1000, low_vram_mode=False, scheduler='EulerAncestralDiscreteScheduler', control_type=None, controlnet_conditioning_scale=0.7, control_guidance_start=0.0, control_guidance_end=1.0, gif=None, precision='f16', autocast=None): args = argparse.Namespace( pretrained_path=pretrained_path, xformers=xformers, spatial_unet_base=spatial_unet_base, lora=lora, output=output, steps=steps, prompt=prompt, negative_prompt=negative_prompt, seed=seed, width=width, height=height, target_width=target_width, target_height=target_height, og_width=og_width, og_height=og_height, video_length=video_length, video_duration=video_duration, low_vram_mode=low_vram_mode, scheduler=scheduler, control_type=control_type, controlnet_conditioning_scale=controlnet_conditioning_scale, control_guidance_start=control_guidance_start, control_guidance_end=control_guidance_end, gif=gif, precision=precision, autocast=autocast ) # 以下代码与原inference.py一致
自研应用中调用main函数的代码片段
if generate_value == 4: main(pretrained_path='hotshotco/Hotshot-XL', xformers=False, spatial_unet_base=None, lora=None, output=filename_vid, steps=steps, prompt=prompt, negative_prompt=negative_prompt, seed=455, width=width, height=height, target_width=width, target_height=height, og_width=width, og_height=height, video_length=video_length, video_duration=1000, low_vram_mode=False, scheduler='EulerAncestralDiscreteScheduler', control_type=None, controlnet_conditioning_scale=0.7, control_guidance_start=0.0, control_guidance_end=1.0, gif=None, precision=precision, autocast=None )
解决方案
这个错误的核心是diffusers库无法定位Hotshot-XL的自定义Unet模块,单独导入修改后的inference.py时,模块路径上下文改变,导致模型加载逻辑失效。可通过以下方式解决:
添加Hotshot-XL路径到Python环境
将Hotshot-XL仓库克隆到自研应用目录下,或在代码开头添加路径配置,让Python能找到自定义模块:import sys sys.path.append("/你的Hotshot-XL本地路径")使用本地模型路径加载
将pretrained_path参数设置为本地克隆的Hotshot-XL目录路径,而非远程的hotshotco/Hotshot-XL,避免远程加载时找不到自定义模块的问题。匹配diffusers版本
Hotshot-XL对diffusers有特定版本要求,确认安装的diffusers版本与Hotshot-XL仓库的要求一致,版本不匹配也会引发模块加载失败。
内容的提问来源于stack exchange,提问作者Glissando
相关产品推荐
相关产品推荐

