当前位置: 首页 > news >正文

修复笔记:SkyReels-V2 项目中的 torch.load 警告

#工作记录

一、问题描述

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

FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.

二、受影响的文件和行号
  1. 文件:F:\PythonProjects\SkyReels-V2\skyreels_v2_infer\modules\vae.py

    • 行号:第 566 行

    • 原代码

      model.load_state_dict(torch.load(pretrained_path, map_location=device), assign=True)
  2. 文件:F:\PythonProjects\SkyReels-V2\skyreels_v2_infer\modules\t5.py

    • 行号:第 437 行

    • 原代码

      model.load_state_dict(torch.load(checkpoint_path, map_location="cpu"))
三、修复过程
  1. 查找相关代码:在项目中查找使用 torch.load 的代码片段。

  2. 修改代码:在 torch.load 中添加 weights_only=True 参数。

  3. 测试修改后的代码:重新运行脚本,确认警告是否消失。

四、修改后的代码
  1. vae.py 文件第 566 行

    model.load_state_dict(torch.load(pretrained_path, map_location=device, weights_only=True), assign=True)
  2. t5.py 文件第 437 行

    model.load_state_dict(torch.load(checkpoint_path, map_location="cpu", weights_only=True))
五、验证修改

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

python generate_video.py --resolution 540P
六、总结

通过上述步骤,成功修复了项目中的 torch.load 警告。这些修改确保了代码在未来版本的库中仍然兼容,并提高了代码的安全性。

希望这份修复笔记能帮助你解决相同的问题。

http://www.dtcms.com/a/170542.html

相关文章:

  • 使用 IDEA + Maven 搭建传统 Spring MVC 项目的详细步骤(非Spring Boot)
  • Linux中的粘滞位和开发工具和文本编辑器vim
  • 神经网络发展的时间线——积跬步至千里
  • terraform resource创建了5台阿里云ecs,如要使用terraform删除其中一台主机,如何删除?
  • 【ThinkBook 16+ 电脑重做系统type-c接口部分功能失效解决方案】
  • Ubuntu 系统上广受好评的浏览器推荐
  • Python 数据智能实战 (12):效果评估 - 超越传统指标
  • Monorepo项目多项目一次性启动工具对比与实践
  • 修复笔记:获取 torch._dynamo 的详细日志信息
  • 如何使用python保存字典
  • 【Java idea配置】
  • 深入了解Linux系统—— 环境变量
  • 8.2 GitHub企业级PDF报告生成实战:ReportLab高级技巧与性能优化全解析
  • 【PostgreSQL数据分析实战:从数据清洗到可视化全流程】2.4 正则表达式与文本处理(LIKE/REGEXP_MATCHES)
  • 【机器学习案列-22】基于线性回归(LR)的手机发布价格预测
  • 【操作系统】死锁
  • 理解MAC-IP映射、ARP协议与ARP欺骗及防护
  • PCIe TLP | 报头 / 包格式 / 地址转换 / 寄存器 / 配置空间类型
  • Java变量学习笔记
  • 重新构想E-E-A-T:提升销售与搜索可见性的SEO策略
  • SQL语句--postgis语句(矢量数据的定义与操作)
  • 生成式 AI 的工作原理
  • 数学实验(Matlab语言环境和线性代数实验)
  • PyTorch_张量转换为numpy数组
  • 用可视化学习逆置法
  • 基于LangChain 实现 Advanced RAG-后检索优化(上)-Reranker
  • 如何提升个人的思维能力?
  • 人工智能:如何快速筛选出excel中某列存在跳号的单元格位置?
  • C++ 中的继承
  • scikit-learn在监督学习算法的应用