docstring

Generate PyTorch-style docstrings with Args, Returns, Examples sections.

102k|28.8k|Updated Aug 13, 2016
One-click install
npx skills add https://github.com/pytorch/pytorch --skill docstring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: docstring
Source: https://github.com/pytorch/pytorch/tree/main/.claude/skills/docstring
Command: npx skills add https://github.com/pytorch/pytorch --skill docstring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill streamlines the process of writing and updating docstrings for PyTorch functions and methods, ensuring they adhere to official PyTorch conventions. It eliminates the guesswork and manual effort involved in formatting, parameter documentation, and example inclusion, allowing developers to focus on code logic rather than documentation syntax.

Core Features & Use Cases

  • Convention Adherence: Automatically guides the generation of docstrings following Sphinx/reStructuredText format, including raw strings, function signatures, and cross-references.
  • Structured Documentation: Ensures inclusion of brief descriptions, mathematical formulas, notes, warnings, Args, Keyword Args, Returns, and Examples sections.
  • Use Case: When developing a new PyTorch function, use this Skill to quickly generate a compliant docstring template, ensuring all necessary sections are covered and correctly formatted, saving significant review time.

Quick Start

Write a docstring for a new PyTorch function my_new_function(input: Tensor, value: float) -> Tensor that applies a custom activation.

Frequently Asked Questions about docstring

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

FAQPage Schema
How do I write PyTorch-style docstrings that follow official conventions?

PyTorch-style docstrings use reStructuredText syntax with raw strings and follow a structured format: function signature, brief description, mathematical formulas, cross-references, Args, Keyword Args, Returns, and Examples sections. This Skill automates generation to ensure compliance with PyTorch conventions from torch/_tensor_docs.py and torch/nn/functional.py, eliminating manual formatting effort and review cycles.

What sections must a PyTorch docstring include?

A complete PyTorch docstring requires: function signature line, brief description, mathematical formulas when applicable, cross-references, notes and warnings, Args, Keyword Args, Returns, and Examples. This Skill ensures all required sections are present, correctly formatted in reStructuredText, and consistent across your codebase.

Can I automatically generate docstrings for existing PyTorch functions?

Yes. This Skill generates compliant docstring templates for new or existing PyTorch functions and methods by applying official PyTorch conventions. Provide the function signature and parameters; the Skill produces a structured template with Args, Returns, Examples, and all required sections ready for customization.

What documentation format does PyTorch use for docstrings?

PyTorch uses Sphinx-compatible reStructuredText (reST) format with raw strings for docstrings. This Skill handles reST syntax, cross-reference markup, code examples, and parameter formatting automatically, ensuring docstrings integrate seamlessly with Sphinx documentation generation and match PyTorch's official style.

How much time does automated docstring generation save compared to manual writing?

Automated docstring generation eliminates guesswork in formatting, parameter documentation, and example inclusion, allowing developers to focus on code logic. By generating compliant templates with all required sections pre-structured, this Skill significantly reduces review cycles and standardization effort across teams.

Do I need to know reStructuredText syntax to use this Skill?

No. This Skill handles reStructuredText formatting and Sphinx conventions automatically. You provide function signatures and parameters; the Skill generates properly formatted docstrings with correct reST syntax, cross-references, and section structure without requiring manual syntax knowledge.