记录 jit 编译的 PyTorch 类方法 (Sphinx)

问题描述

我在尝试使用 Sphinx 记录自定义 PyTorch 模型时遇到问题:jit 编译的方法在文档中显示时没有文档字符串。我该如何解决?我检查了 Python Sphinx autodoc and decorated membersHow to autodoc decorated methods with sphinx?,但建议的解决方案似乎不起作用。当我尝试使用 {X > 0 && ( <div> {fields.map((field,index) => { ... 时,我得到

..automethod

这是一个 MWE;目前我通过编写 AttributeError: '_CachedForward' object has no attribute '__getattr__' 并在 my_forward调用它来规避这个问题。

forward

解决方法

在运行 Sphinx 时将 PYTORCH_JIT 环境变量设置为 0。这将禁用脚本和跟踪注释(装饰器)。

https://pytorch.org/docs/stable/jit.html#disable-jit-for-debugging