Agent skill · writing content · aiskillstore

docstring

Write docstrings for PyTorch functions and methods following PyTorch conventions. Use when writing or updating docstrings in PyTorch code.

Why this skill is useful

Provides specific guidelines for writing PyTorch docstrings that the AI wouldn't reliably generate on its own.

What it needs

About 5k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.

What this skill does

PyTorch Docstring Writing Guide This skill describes how to write docstrings for functions and methods in the PyTorch project, following the conventions in torch/tensordocs.py and torch/nn/functional.py. General Principles Use raw strings (r"""...""") for all docstrings to avoid issues with LaTeX/math backslashes Follow Sphinx/reStructuredText (reST) format for documentation Be concise but complete - include all essential information Always include examples when possible Use cross-references to related functions/classes Docstring Structure 1. Function Signature (First Line) Start with the function signature showing all parameters: Notes: Include the function name Show positional and keyword-only arguments (use separator) Include default values Show return type annotation This line should NOT end with a period 2. Brief Description Provide a one-line description of what the function does: 3. Mathematical Formulas (if applicable) Use Sphinx math directives for mathematical expressions: Or inline math: :math:\x^2\ 4. Cross-References Link to related classes and functions using Sphinx roles: :class:\~torch.nn.ModuleName\ - Link to a class :func:\torch.functionname\ - Link to a function :meth:\~Tensor.methodname\ - Link to a method :attr:\attributename\ - Reference an attribute The ~ prefix shows only the last component (e.g., Conv2d instead of torch.nn.Conv2d) Example: 5. Notes and Warnings Use admonitions for important information: 6. Args Section Document all parameters with type annotations and descriptions: Formatting rules: Parameter name in lowercase Type in parentheses: (Type), (Type, optional) for optional parameters Description follows the type For optional parameters, include "Default: value" at the end Use double backticks for inline code: Indent continuation lines by 2 spaces 7. Keyword Args Section (if applicable) Sometimes keyword arguments are documented separately: 8. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills aiskillstore/docstring

View the source on GitHub

Browse the @skills marketplace