修复笔记: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
相关推荐
you鬰1 小时前
datawhale--llm-algo-leetcode5️⃣
python·datawhale
小白说大模型1 小时前
Codex 实战:用 AI 写运维脚本
大数据·运维·网络·人工智能·机器学习·prompt
λqaq71 小时前
MySQL 数据库基础(2)约束、用户权限、远程连接、外键与 TCP/UDP 理解
linux·数据库·python·tcp/ip·mysql
人工干智能1 小时前
科普:pandas 时间偏移别名:ts.resample(“5Min“).sum()
python·pandas
数字护盾(和中)1 小时前
和中科技剖析 EDR 绕过全链路,AMSI、ETW 规避技术与防御对策
运维·网络·人工智能·科技·安全·web安全
开源量化GO1 小时前
最新AI辅助量化表达:先理清规则,再按需求选工具
人工智能·python
Zane19941 小时前
为什么 del 一个对象有时立刻消失,有时却纹丝不动?一文讲透引用计数与垃圾回收
后端·python
IT大白鼠1 小时前
MSF环境搭建全教程(Kali/Windows/Mac/Docker)
windows·macos·msf
yichudu2 小时前
Python 装饰器 decorator
开发语言·python
i love you china2 小时前
问卷系统调查博客项目测试报告
笔记