Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev add docstring #5449

Merged
merged 15 commits into from
Jul 12, 2021
Merged

Dev add docstring #5449

merged 15 commits into from
Jul 12, 2021

Conversation

doombeaker
Copy link
Contributor

@doombeaker doombeaker commented Jul 10, 2021

在 Python 层,通过在初始化时,runtime 地给 functional 方法添加 __doc__,达到添加文档的目的。

使用方法:
参照 oneflow/python/framework/docstr/math_ops.pyoneflow/python/framework/docstr/random.py 的例子。调用 add_docstr 即可:

add_docstr(
    oneflow.F.bernoulli, r"""
    ...
    """

其它:

  • 新增了3个例子(sin, cos, bernoulli),是为了展示可以把 add_docstr 放在多个文件中(math_ops.pyrandom.py
  • oneflow/python/test/modules/test_functional_docstr.py 文件,会遍历 flow.Fflow.experimental.F 测试 docstr

image
image
image

@doombeaker doombeaker marked this pull request as ready for review July 11, 2021 02:02
@doombeaker
Copy link
Contributor Author

@hjchen2 @BBuf 我周五试错了半天,发现之前和你们介绍的 PyTorch 给 functional 添加文档的思路,我们是没有必要学,也不好学的,原因有:

  • PyTorch 是用 Python 原生方法导出的 C 接口,属于历史遗留问题:PyTorch 现存有原生导出 C 接口和使用 pybind11 导出接口两种方式,但是我们只有 pybind11 一种,没有必要为了 docstr,开倒车新引入一种导出方式。
  • 如果一定要引入原生导出方式,要改一些比较琐碎的头文件文职、cmakelist配置
  • 可以 Python 层做到给 functional 方法添加 docstr,并测试(这个是最主要原因哈哈)

你们帮忙看下这个 PR 的思路可以的吗?

@doombeaker doombeaker requested review from oneflow-ci-bot and removed request for oneflow-ci-bot July 11, 2021 13:01
@oneflow-ci-bot oneflow-ci-bot removed their request for review July 11, 2021 14:15
@doombeaker doombeaker requested review from oneflow-ci-bot and removed request for oneflow-ci-bot July 11, 2021 16:11
@oneflow-ci-bot oneflow-ci-bot removed their request for review July 11, 2021 17:25
@oneflow-ci-bot oneflow-ci-bot requested review from oneflow-ci-bot and removed request for oneflow-ci-bot July 12, 2021 01:39
@oneflow-ci-bot oneflow-ci-bot merged commit 498e00b into master Jul 12, 2021
@oneflow-ci-bot oneflow-ci-bot deleted the dev_add_docstring branch July 12, 2021 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants