pytorch - torchscript中的torch.jit.trace和torch.jit.script有什么区别?

标签 pytorch jit torchscript

Torchscript 提供了 torch.jit.trace 和 torch.jit.script 将 pytorch 代码从 Eager 模式转换为脚本模型。从文档中,我可以理解 torch.jit.trace 无法处理 Python 中存在的控制流和其他数据结构。因此,torch.jit.script 被开发来克服 torch.jit.trace 中的问题。
但是看起来 torch.jit.script 适用于所有情况,那为什么我们需要 torch.jit.trace 呢?
请帮助我理解这两种方法之间的区别

最佳答案

torch.jit.script适用于您的代码,那么这就是您所需要的。编译器不支持使用动态行为(如多态)的代码 torch.jit.script使用,因此对于此类情况,您需要使用 torch.jit.trace .

关于pytorch - torchscript中的torch.jit.trace和torch.jit.script有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62626052/

相关文章:

pytorch - torch.jit.script(module) 与 @torch.jit.script 装饰器

python-decorators - 为什么我不能使用类对 `torch.jit.script` 装饰器下的函数参数进行类型注释?

python - 将索引选择的 numpy 数组添加到另一个具有重叠索引的 numpy 数组

python - 在 Pytorch 中创建一个具有固定权重的线性模型

python - 如何扩展 Pytorch 损失函数

Java JIT 编译器下载

c# - C# JITter 能否优化重复的委托(delegate)调用?

python - Pylint 与 pytorch : Is there a way to tell pylint to look for module in different place?

java - 解释字节码与编译字节码?

c++ - 尝试构建 torchscript 扩展会导致 INVALID TYPE : Only int64_t and bool are supported as an integral argument type error