修复笔记: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
相关推荐
38242782712 分钟前
python3网络爬虫开发实战 第二版:绑定回调
开发语言·数据库·python
好大哥呀14 分钟前
微 PE 工具制作,以后自己重装系统就不需要钱了
windows
im_AMBER15 分钟前
Leetcode 87 等价多米诺骨牌对的数量
数据结构·笔记·学习·算法·leetcode
BIBI204917 分钟前
Windows 上配置 Nacos Server 3.x.x 使用 MySQL 5.7
java·windows·spring boot·后端·mysql·nacos·配置
dagouaofei22 分钟前
培训项目总结 PPT 工具对比评测,哪款更专业
python·powerpoint
Hello eveybody22 分钟前
用代码生成你的电影预告片(Python)
python
一只旭宝25 分钟前
Linux专题四:静态库,动态库,进程进阶以及fork()函数初步
linux·运维
今儿敲了吗29 分钟前
计算机网络第一章笔记
笔记·计算机网络
小白不想白a31 分钟前
ELB--弹性负载均衡器
运维·负载均衡
山沐与山34 分钟前
【设计模式】 Python代理模式:从入门到实战
python·设计模式·代理模式