Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Torchscript Deprecation

未关闭
#8,632 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
重构
描述清晰度
需要澄清
活跃度
停滞
技术栈
python, pytorch

调研方向

先从使用 torch.export 的文档化 monai.networks.nets.UNet 示例开始,然后审查 MONAI 现有的 torch.jit 用法。识别不兼容的网络和行为,并开发所列出的辅助例程、兼容性测试、适配、教程以及旧用法移除。完成的标准是:在不依赖不受支持的 Torchscript 依赖项的情况下,解决迁移范围内的问题。

由索引模型根据 Issue 内容生成。

描述

Torchscript is now fully deprecated in Pytorch 2.9. We should investigate converting usage in MONAI of torch.jit over to torch.export. Not all features and behaviours are supported as it is not the same sort of JIT architecture, and torch.compile is not meant for exporting models to a saved format.

Some MONAI models will have no issues with torch.export.export, however it doesn't capture control flow like Torchscript and is more like tracing. Networks without control flow in their forward definitions can be exported currently, eg.:

import torch
from monai.networks.nets import UNet

net = UNet(spatial_dims=2, in_channels=2, out_channels=1, channels=[4, 8, 16], strides=[2, 2])

t1 = torch.rand(3, 2, 16, 16)
t2 = torch.rand(5, 2, 32, 32)

print(net(t1).shape, net(t2).shape)  # expected shapes

D = torch.export.Dim.DYNAMIC
S = torch.export.Dim.STATIC
enet = torch.export.export(net, args=(t1,), dynamic_shapes=((D, S, D, D),))
torch.export.save(enet, "out.pt2")
enet1 = torch.export.load("out.pt2")

net1 = enet1.module()
print(net1(t1).shape, net1(t2).shape) # same as expected shapes

Work is needed to develop:

  • Helper routines to help export then import networks in regular use.
  • Helper routines and tests to ensure compatibility.
  • Adaptation of existing code to overcome any compatibility issues.
  • Tutorials on this new usage and how to design compatible networks.
  • Removal of legacy Torchscript usage wherever present, especially when its removal from Pytorch is imminent.
主要语言
Python
星标
8.7k
派生
1.6k
平均合并
5 天 20 小时
30 天内合并 PR
12

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Project-MONAI/MONAI 的其他 Issue

查看 Project-MONAI/MONAI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。