跳转至

添加 Tensor.half

流程

修改 ./python/oneflow/framework/tensor.py,添加

def _half(self):
    return flow._C.to(self, flow.float16)

同时在本文件 def RegisterMethods(): 添加

    Tensor.half = _half

修改 ./python/oneflow/framework/docstr/tensor.py,添加

add_docstr(
    oneflow.Tensor.half,
    """
    self.half() is equivalent to self.to(torch.float16).

    See :func:`oneflow.Tensor.to`

    """,
)

修改 ./docs/source/tensor.rst,在member 下添加 half。

ModuleNotFoundError

进入 ./docs,执行指令 make html,报如下错误

Running Sphinx v4.1.2

Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/sphinx/config.py", line 327, in eval_config_file
    exec(code, namespace)
  File "/home/zhongshanshan/workspace/f/docs/source/conf.py", line 17, in <module>
    import oneflow
  File "/home/zhongshanshan/workspace/f/python/oneflow/__init__.py", line 21, in <module>
    import oneflow._oneflow_internal
ModuleNotFoundError: No module named 'oneflow._oneflow_internal'

make: *** [Makefile:20: html] Error 2

进入 python 命令行,执行 import oneflow,一切正常。这里需要注意到,调用了系统的sphinx,这是因为 没装包导致到系统环境中找 sphinx,进而导致寻找不到 oneflow。

解决方法: make html 前 install docs 下的 requirements。

Back to top