docstring

Generate PyTorch docstrings with reST formatting and cross-references.

1|Updated Apr 5, 2026
One-click install
npx skills add https://github.com/steleman/pytorch-cuda-2.11.0 --skill docstring-steleman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docstring
Source: https://github.com/steleman/pytorch-cuda-2.11.0/tree/main/.claude/skills/docstring
Command: npx skills add https://github.com/steleman/pytorch-cuda-2.11.0 --skill docstring-steleman

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps contributors write clear, correct docstrings for PyTorch functions and methods, following PyTorch conventions.

Core Features & Use Cases

  • Enforces raw string formatting using r"""...""", reStructuredText (reST) syntax, and cross-references to related classes and functions.
  • Provides a consistent structure for function signatures, Args, Returns, and Examples to improve readability and usability.
  • Supports maintaining high-quality API documentation across PyTorch codebases and tutorials.

Quick Start

Follow this guide to draft a PyTorch docstring that includes the function signature, a brief description, an Args section, a Returns section, and an Examples block.

Frequently Asked Questions about docstring

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write PyTorch docstrings that follow the official project conventions?

Write PyTorch docstrings using raw string formatting (r"""..."""), reStructuredText syntax, and cross-references. Structure them with function signatures, Args, Returns, and Examples sections to match conventions in torch/_tensor_docs.py and torch/nn/functional.py.

What is the correct format for Args and Returns sections in PyTorch codebases?

The correct format for PyTorch docstrings uses reStructuredText (reST) syntax for Args and Returns sections. Arguments should be listed with their types and descriptions, ensuring raw strings are used consistently throughout the documentation block.

How do I add cross-references to other functions in PyTorch API documentation?

Add cross-references in PyTorch API documentation by using reStructuredText (reST) formatting syntax. This ensures related classes and functions are linked correctly within the generated Sphinx API reference documentation.

Can I use this docstring guide for general Python code or is it exclusively for PyTorch?

This guide is specifically for PyTorch codebases, applying conventions from torch/_tensor_docs.py and torch/nn/functional.py. While the reST and raw string formatting principles apply generally, the structure targets PyTorch's API reference standards.

Why do PyTorch docstrings require raw strings (r"""...""") instead of regular strings?

PyTorch docstrings require raw strings (r"""...""") to prevent escape sequence interpretation. This ensures reStructuredText (reST) formatting, cross-references, and code examples remain intact without character corruption during Sphinx documentation generation.

What is the best way to generate API reference documentation for PyTorch functions?

The best way to generate PyTorch API reference documentation is to write well-structured docstrings using reST syntax, including function signatures, Args, Returns, and Examples. This ensures high-quality, readable output when processed by Sphinx.