SuperAPI AI 工具集

tripy-documentation

写作与研究

查看项目

更新于 10-16 02:35

技能介绍

用途:为 nvtripy 编写或更新公开 API 的文档,包括函数、类、模块的 docstring,添加可运行代码示例,选择正确的 document_under 路径,以及理解文档的生成与构建流程。

文档流水线:@export.public_api(document_under="...") 将 API 注册到 PUBLIC_APIS 列表;docs/generate_rsts.py 读取该列表并在 docs 层级中生成 .rst 文件;Sphinx 再据此构建最终 HTML 文档;docstring 中的代码示例会在测试期间被提取并校验。

@export.public_api 参数:document_under 指定文档层级路径;autodoc_options 传入 Sphinx autodoc 选项,如 [":special-members:"] 包含 init、call,[":no-members:", ":no-special-members:"] 只显示类或模块本身,[":no-value:"] 隐藏变量默认值;bypass_dispatch 为 True 时对函数禁用注册表重载分发与类型检查,对类则绕过所有方法,也可用 ["init", "call"] 仅绕过指定方法。

document_under 路径约定:"operations/functions" 用于通用张量运算(如 softmax、reshape);"operations/initializers" 用于张量创建(ones、zeros、full、arange);"operations/modules" 用于神经网络模块(Linear、LayerNorm 等);"compiling_code/compile.rst" 用于编译相关 API;"compiling_code/input_info/index.rst" 用于 InputInfo 及相关类;"config.rst" 用于配置变量。路径会创建目录结构,指向同一 .rst 文件的 API 渲染在同一页面。

docstring 格式:函数需包含一行简述、可含数学公式的详细说明、Args、Returns,以及带 :linenos: 的 .. code-block:: python 示例和 .. seealso:: 交叉引用。类需为各字段写 docstring,init 中同样包含 Args 与代码示例。含 :math: 的 docstring 应使用 r""" 原始字符串。

代码示例约定:需包含用 tp.iota()、tp.ones()、tp.zeros() 或 tp.Tensor() 创建输入的 Setup、调用被测函数或模块的 Operation,以及用 assert(tp.allclose、np.array_equal 或形状检查)的断言。代码块自动可访问 tp、np、cp、torch。特殊指令包括 # doc: omit(该行不渲染但仍执行)、# doc: no-print-locals <var>(抑制变量自动打印)、:linenos:(始终包含)。交叉引用使用 :func:、:class:、:math: 与 .. seealso::。

限制:资料未提供安装命令、收费信息及更多平台细节。