修复笔记: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
相关推荐
你要飞1 小时前
Hexo + Butterfly 博客添加 Live2D 看板娘指南
笔记
apocelipes2 小时前
golang unique包和字符串内部化
java·python·性能优化·golang
Geoking.3 小时前
NumPy zeros() 函数详解
python·numpy
Full Stack Developme3 小时前
java.text 包详解
java·开发语言·python
Do_GH3 小时前
【Linux】07.Ubuntu开发环境部署
linux·运维·ubuntu
丁浩6664 小时前
Python机器学习---2.算法:逻辑回归
python·算法·机器学习
勤源科技4 小时前
全链路智能运维中的实时流处理架构与状态管理技术
运维·架构
CHH32134 小时前
在 Mac/linux 的 VSCode 中使用Remote-SSH远程连接 Windows
linux·windows·vscode·macos
tryCbest4 小时前
Linux使用Docker部署项目后期更新
linux·运维·docker
B站_计算机毕业设计之家4 小时前
计算机毕业设计:Python农业数据可视化分析系统 气象数据 农业生产 粮食数据 播种数据 爬虫 Django框架 天气数据 降水量(源码+文档)✅
大数据·爬虫·python·机器学习·信息可视化·课程设计·农业