0

我在尝试使用 Sphinx 记录自定义 PyTorch 模型时遇到问题:在文档中显示 jit 编译的方法没有文档字符串。我该如何解决?我签出了Python Sphinx autodoc 和 decorated members以及How to autodoc decorators with sphinx? 但建议的解决方案似乎不起作用。当我尝试使用时,..automethod我得到

AttributeError: '_CachedForward' object has no attribute '__getattr__'

这是一个 MWE;目前,我通过编写 amy_forward并在forward.

from torch import jit, Tensor


class DummyModel(jit.ScriptModule):
    """My dummy model"""

    def __init__(self, const: float):
        super(DummyModel, self).__init__()
        self.const = Tensor(const)

    @jit.script_method
    def forward(self, x: Tensor) -> Tensor:
        """This method does show as a :undoc-member: in the documentation"""
        return self.my_forward(x)

    def my_forward(self,  x: Tensor) -> Tensor:
        """This method shows up as a :member: in the documentation"""
        return x + self.const
4

1 回答 1

1

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

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

于 2021-05-27T14:12:39.567 回答