我在尝试使用 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