修复笔记:SkyReels-V2 项目中的 torch.cuda.amp.autocast 警告和错误

#工作记录

一、问题描述

在运行项目时,出现以下警告和错误:

复制代码
FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cuda', args...)` instead.
  with torch.cuda.amp.autocast(dtype=pipe.transformer.dtype), torch.no_grad():
...
TypeError: set_autocast_enabled(): argument 'enabled' (position 2) must be bool, not str

二、受影响的文件和行号

  1. 文件:F:\PythonProjects\SkyReels-V2\skyreels_v2_infer\pipelines\text2video_pipeline.py

    • 行号:第 86 行和第 93 行

    • 原代码

      复制代码
      with torch.cuda.amp.autocast(dtype=self.transformer.dtype), torch.no_grad():

三、修复过程

1. 查找相关代码

在项目中查找使用 torch.cuda.amp.autocast 的代码片段。

2. 修改代码

根据警告提示,将 torch.cuda.amp.autocast 替换为 torch.amp.autocast,并正确设置参数。

3. 测试修改后的代码

重新运行 generate_video.py 脚本,确认警告是否消失。

四、修改后的代码

  1. text2video_pipeline.py 文件第 86 行

    复制代码
    with torch.amp.autocast(device_type='cuda', dtype=self.transformer.dtype), torch.no_grad():

五、验证修改

完成上述修改后,重新运行项目以确保所有问题都已解决:

复制代码
python generate_video.py --resolution 540P
相关推荐
你们补药再卷啦23 分钟前
windows,java后端开发常用软件的下载,使用配置
windows
mxpan24 分钟前
Alpine Docker 容器中安装包缓存与 C/C++ 运行问题
运维·docker·容器
西猫雷婶28 分钟前
python学智能算法(十三)|机器学习朴素贝叶斯方法进阶-简单二元分类
开发语言·人工智能·python·深度学习·机器学习·矩阵·分类
芊言芊语1 小时前
CAN2.0、DoIP、CAN-FD汽车协议详解与应用
运维·服务器·网络
板栗栗-71 小时前
Windows系统提示“mfc140u.dll丢失”?详细修复指南,一键恢复程序运行!
windows·dll·dll修复·dll错误·dll缺失
张朝阳的博客1 小时前
哈夫曼树Python实现
开发语言·python
里探2 小时前
FastAPI的初步学习(Django用户过来的)
python·django·fastapi
Lz__Heng2 小时前
记一次使用HPE SSMC管理停用HPE 3par存储报连接出错
运维·存储
鸽子一号2 小时前
c#基础概念之进制
笔记
、我是男生。2 小时前
Linux、Ubuntu、虚拟机三者的关系和角色
linux·运维·ubuntu