document-public-apis
Original:🇺🇸 English
Translated
Document undocumented public APIs in PyTorch by removing functions from coverage_ignore_functions and coverage_ignore_classes in docs/source/conf.py, running Sphinx coverage, and adding the appropriate autodoc directives to the correct .md or .rst doc files. Use when a user asks to remove functions from conf.py ignore lists.
5installs
Sourcepytorch/pytorch
Added on
NPX Install
npx skill4agent add pytorch/pytorch document-public-apisTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Document Public APIs
This skill documents undocumented public APIs in PyTorch by removing entries from the coverage ignore lists in and adding Sphinx autodoc directives (e.g., , , , ) to the corresponding or doc source files in .
docs/source/conf.pyautosummarycurrentmoduleautoclassautomodule.md.rstdocs/source/"Documenting" means adding autodoc directives to doc source files — NEVER modifying Python source code. Do not add or edit docstrings in files. Do not read or inspect Python source files. Sphinx will pull whatever docstring exists (or render an empty entry if none exists). Your only job is to add the correct directive to the correct doc file.
.pyOverview
docs/source/conf.py- : undocumented functions
coverage_ignore_functions - : undocumented classes
coverage_ignore_classes
Entries are organized by module comment groups. Each group has a module label comment followed by the function/class names that belong to that module:
python
coverage_ignore_functions = [
# torch.ao.quantization.fx.convert <-- module label comment
"convert", # <-- entries belonging to this module
"convert_custom_module",
"convert_standalone_module",
"convert_weighted_module",
# torch.ao.quantization.fx.fuse <-- next module group
"fuse",
# torch.nn.functional
"assert_int_or_pair", # looks unintentionally public <-- entry with inline comment
"constant", # deprecated <-- entry with inline comment
]There are two kinds of comments:
- Module label comments (): these label which module the entries below belong to. They appear on their own line before a group of entries.
# torch.ao.quantization.fx.convert - Inline comments (,
# deprecated): these appear after a string entry on the same line and explain why the entry is in the ignore list.# documented as adaptive_max_pool1d
The module label comment directly tells you:
- Which module the functions belong to
- Where to add them in the docs (e.g., → the functions go under
# torch.ao.quantization.fx.convertin the doc file)torch.ao.quantization.fx.convert
Instructions
Each invocation of this skill processes one batch of module groups. Pick one or more complete module groups from the ignore lists, document their functions, and verify.
Step 1: Select module groups to document
Read and select one or more complete module groups to document. A module group is a module label comment and all entries beneath it up to the next module label comment. Process entire groups — never split a group across batches.
docs/source/conf.pyFor example, selecting the group means taking all of:
torch.ao.quantization.fx.convertpython
# torch.ao.quantization.fx.convert
"convert",
"convert_custom_module",
"convert_standalone_module",
"convert_weighted_module",Work through the lists top-to-bottom. Choose enough groups to make meaningful progress (aim for 5–15 functions total, but always include complete groups even if that means going slightly over).
Check inline comments before including an entry. Some entries have inline comments that indicate they should not be documented:
- — The function is deprecated. Leave it in the ignore list.
# deprecated - — Already documented under a different name. Leave it.
# documented as <other_name> - — Probably not meant to be public API. Leave it.
# looks unintentionally public - — Same as deprecated. Leave it.
# legacy helper for ... - - Leave it.
# utility function
If a module group has a mix of regular entries and entries with inline comments, still process the group — but only comment out the regular entries. Leave entries with inline comments untouched in the ignore list.
Step 2: Present the batch to the user
Before making any edits, present the selected module groups and their functions to the user. Show them organized by module:
Module: torch.ao.quantization.fx.convert
- convert
- convert_custom_module
- convert_standalone_module
- convert_weighted_module
Module: torch.ao.quantization.fx.fuse
- fuseThen use the tool to let the user confirm, with options like:
AskUserQuestion- "Proceed with this batch"
- "Skip some entries" (user can specify which to remove)
- "Pick a different batch"
Step 3: Comment out entries in conf.py
After the user confirms, edit and comment out (do not delete) the selected entries. Use a prefix on each string entry line:
docs/source/conf.py#python
# torch.ao.quantization.fx.convert
# "convert",
# "convert_custom_module",
# "convert_standalone_module",
# "convert_weighted_module",This preserves the original entries so they can be restored if verification fails.
Step 4: Run Sphinx coverage
bash
cd docs && make coverageIgnore the terminal output of . It often contains unrelated tracebacks and errors from Sphinx extensions (e.g., , , ) that have nothing to do with coverage. The only thing that matters is whether was generated. Read that file to see the specific undocumented APIs.
make coverageonnx_irkatexsphinxcontribdocs/build/coverage/python.txtThe format of lists each undocumented API as:
python.txttorch.ao.quantization.fx.convert
* convert
* convert_custom_module
* convert_standalone_module
* convert_weighted_moduleNot all commented-out functions will appear in . Some may already be documented elsewhere. This is fine — only add directives for functions that actually appear in .
python.txtpython.txtIf fails due to missing dependencies, first run:
make coveragebash
cd docs && pip install -r requirements.txtStep 5: Add documentation directives
For each function listed in , use the module label comment from to determine where it should be added. The module comment gives you the full module path, which maps to a doc source file and a section within that file.
python.txtconf.pyFinding the correct doc file
The module comment maps to a doc source file in . When unsure, search for other functions from the same module:
docs/source/bash
grep -rn "torch.module_name" docs/source/*.md docs/source/*.rstOr list candidate files:
bash
ls docs/source/*module_name*If no doc file exists for a submodule, check whether a parent module's doc file has a section for it (e.g., has sections for , , etc.). If not, add a new section to the parent file following existing patterns.
backends.mdtorch.backends.cudatorch.backends.cudnnAdding the directives
Read the target doc file first and match the exact patterns already used there. Do not invent new patterns or use bare with fully qualified names — always use the proper hierarchical structure with , , and short names. Do not use since that just suppresses errors and doesn't actually document the function. Look at other files that match the target file's format (e.g., vs. ) under to see examples.
autofunctionautomodulecurrentmodule. py:module::.md.rstdocs/source/There are two file formats. Match the one used in the target file.
Pattern A — MyST Markdown files (): Used in files like , , .
.mdaccelerator.mdbackends.mdcuda.mdThe hierarchical structure uses to register the module, to set context, then short names:
automodulecurrentmodulemarkdown
## torch.ao.quantization.fx.convert
```{eval-rst}
.. automodule:: torch.ao.quantization.fx.convert.. currentmodule:: torch.ao.quantization.fx.convert.. autofunction:: convert.. autofunction:: convert_custom_module
For `autosummary` blocks (used in some files instead of individual directives):
```markdown
```{eval-rst}
.. autosummary::
:toctree: generated
:nosignatures:
existing_function
your_new_function
`` `For classes:
markdown
```{eval-rst}
.. autoclass:: YourClass
:members:
`` `Pattern B — reStructuredText files (): Used in files like , .
.rsttorch.rstnn.rstSame hierarchical structure without the markdown fences:
rst
torch.ao.quantization.fx.convert
---------------------------------
.. automodule:: torch.ao.quantization.fx.convert
.. currentmodule:: torch.ao.quantization.fx.convert
.. autosummary::
:toctree: generated
:nosignatures:
convert
convert_custom_module
convert_standalone_module
convert_weighted_moduleFor individual directives:
rst
.. automodule:: torch.submodule
.. currentmodule:: torch.submodule
.. autofunction:: function_name
.. autoclass:: ClassName
:members:Key rules:
- The module label comment from (e.g.,
conf.py) tells you exactly which# torch.ao.quantization.fx.convertandautomoduleto use.currentmodule - Always set and
.. automodule::before documenting functions from a module... currentmodule:: - Use short names (e.g., , not
convert) aftertorch.ao.quantization.fx.convert.convertis set.currentmodule - If the module already has an /
automodulein the file, don't add another — just add your function under the existing one.currentmodule - Match whichever style the file already uses (blocks vs. individual
autosummarydirectives).autofunction
Placing in the right section
Read the target doc file and find the appropriate section. If the module already has a section (e.g., in ), add the functions there. If no section exists yet, create one following the existing section patterns in the file. Group all functions from the same module group together.
## torch.backends.cudabackends.mdStep 6: Verify with coverage
Run coverage again:
bash
cd docs && make coverageIgnore the terminal output — only read . Verification passes when contains zero undocumented functions across ALL modules. It should only have the statistics table with 100% coverage and 0 undocumented for every module. For example:
docs/build/coverage/python.txtpython.txtUndocumented Python objects
===========================
Statistics
----------
+---------------------------+----------+--------------+
| Module | Coverage | Undocumented |
+===========================+==========+==============+
| torch | 100.00% | 0 |
+---------------------------+----------+--------------+
| torch.accelerator | 100.00% | 0 |
+---------------------------+----------+--------------+If any module shows undocumented functions (coverage below 100% or undocumented count > 0), verification has failed.
If verification succeeds (zero undocumented across all modules): Go to Step 7.
If verification fails (any undocumented functions remain): Read to see which functions are still listed as undocumented. Common issues include:
docs/build/coverage/python.txt- Wrong doc file: the function was added to the wrong /
.mdfile. Move the directive to the correct file..rst - Wrong directive type: e.g., used for a class, or
autofunctionfor a function. Fix the directive.autoclass - Wrong module path in the directive: e.g., should be
torch.foo.bar. Correct the qualified name.torch.foo.baz.bar - Function added to an block with the wrong
autosummary: make sure thecurrentmoduledirective above the block matches... currentmodule:: - Missing for a submodule that hasn't been registered yet. Add a
automoduledirective before documenting functions from that submodule... automodule:: torch.submodule
Fix the doc directive based on the error, then re-run . Repeat until verification passes.
make coverageIf a function still fails after multiple attempts, stop and show the error to the user. Present the function name and the error, then use the tool with options like:
AskUserQuestion- "Uncomment it to restore to ignore list (skip for now)"
- "Try a different approach"
- "Investigate further"
Step 7: Report progress
Present a progress summary to the user showing:
- Which module groups were processed and how many functions were documented
- Which functions were skipped or restored to the ignore list (and why)
- How many entries remain in and
coverage_ignore_functionscoverage_ignore_classes
Step 8: Clean up commented-out entries in conf.py
Now that verification has passed, delete the commented-out string entries from Step 3. These are lines that start with inside and . Commented-out string entries always contain quotes — that's how you distinguish them from module label comments:
# "coverage_ignore_functionscoverage_ignore_classespython
# "disable_global_flags", <-- commented-out string entry (has quotes) → DELETE
# torch.backends <-- module label comment (no quotes) → KEEP if it has active entriesAlso delete any module label comments that no longer have active entries beneath them (i.e., all their entries were either commented out and now deleted, or had inline comments and were left in place but the module label is otherwise empty).
Important notes
- Follow the steps exactly as written. Do not add extra investigation steps like importing Python modules to check docstrings, inspecting source code to verify function signatures, or running any commands not specified in the instructions. The step is the only verification needed — let it tell you what's wrong.
make coverage - Never modify Python source files (). This skill only edits
.pyand doc source files (docs/source/conf.py/.md) in.rst. Do not add or edit docstrings, do not read Python source to check function signatures, do not inspect implementations.docs/source/ - Entries are commented out in Step 3, verified in Step 6, and cleaned up in Step 8 after verification passes. Never delete uncommented entries directly.
- Read inline comments on entries before deciding to document them. Entries marked ,
# deprecated,# documented as ..., or# looks unintentionally publicshould stay in the ignore list.# legacy helper - The list uses bare function names (not fully qualified), so the same name can appear multiple times for different modules. Use the module label comment above each entry to identify which module it belongs to. Be careful during Step 8 cleanup to only delete the correct commented-out lines — commented-out string entries have quotes (
coverage_ignore_functions), module label comments do not.# "func_name", - Always match the existing style of the target doc file — don't mix style directives into
.mdfiles or vice versa..rst - Use the module label comment (e.g., ) as the primary guide for both the
# torch.ao.quantization.fx.convert/automoduledirectives and for finding the right section in the doc file.currentmodule - Always process complete module groups — never split a group across invocations.