Name Date Size #Lines LOC

..--

source/H25-Apr-2025-14,67610,587

.gitignoreH A D25-Apr-202564 65

MakefileH A D25-Apr-2025648 239

README.mdH A D25-Apr-20258.2 KiB241173

README.md

1# ExecuTorch Documentation
2
3Welcome to the ExecuTorch documentation! This README.md will provide an overview
4of the ExecuTorch docs and its features, as well as instructions on how to
5contribute and build locally.
6
7All current documentation is located in the `docs/source` directory.
8
9<!-- toc -->
10
11- [Toolchain Overview](#toolchain-overview)
12- [Building Locally](#building-locally)
13- [Using Custom Variables](#using-custom-variables)
14- [Including READMEs to the Documentation Build](#including-readmes-to-the-documentation-build)
15- [Contributing](#contributing)
16- [Adding Tutorials](#adding-tutorials)
17- [Auto-generated API documentation](#auto-generated-api-documentation)
18  - [Python APIs](#python-apis)
19  - [C++ APIs](#c-apis)
20  <!-- tocstop -->
21
22## Toolchain Overview
23
24We are using [sphinx](https://www.sphinx-doc.org/en/master/) with
25[myst_parser](https://myst-parser.readthedocs.io/en/latest/),
26[sphinx-gallery](https://sphinx-gallery.github.io/stable/index.html), and
27[sphinx_design](https://sphinx-design.readthedocs.io/en/latest/) in this
28documentation set.
29
30We support both `.rst` and `.md` files but prefer the content to be authored in
31`.md` as much as possible.
32
33## Building Locally
34
35Documentation dependencies are stored in
36[.ci/docker/requirements-ci.txt](https://github.com/pytorch/executorch/blob/main/.ci/docker/requirements-ci.txt).
37
38To build the documentation locally:
39
401. Clone the ExecuTorch repo to your machine.
41
421. If you don't have it already, start a conda environment:
43
44   ```{note}
45   The below command generates a completely new environment and resets
46   any existing dependencies. If you have an environment already, skip
47   the `conda create` command.
48   ```
49
50   ```bash
51   conda create -yn executorch python=3.10.0
52   conda activate executorch
53   ```
54
551. Install dependencies:
56
57   ```bash
58   pip3 install -r ./.ci/docker/requirements-ci.txt
59   ```
601. Update submodules
61
62   ```bash
63   git submodule sync && git submodule update --init
64   ```
651. Run:
66
67   ```bash
68   bash install_requirements.sh
69   ```
70
711. Go to the `docs/` directory.
72
731. Build the documentation set:
74
75   ```
76   make html
77   ```
78
79   This should build both documentation and tutorials. The build will be placed
80   in the `_build` directory.
81
821. You can preview locally by using
83   [sphinx-serve](https://pypi.org/project/sphinx-serve/). To install
84   sphinx-serve, run: `pip3 install sphinx-serve`. To serve your documentation:
85
86   ```
87   sphinx-serve -b _build
88   ```
89
90   Open http://0.0.0.0:8081/ in your browser to preview your updated
91   documentation.
92
93## Using Custom Variables
94
95You can use custom variables in your `.md` and `.rst` files. The variables take
96their values from the files listed in the `./.ci/docker/ci_commit_pins/`
97directory. For example, to insert a variable that specifies the latest PyTorch
98version, use the following syntax:
99
100```
101The current version of PyTorch is ${executorch_version:pytorch}.
102```
103
104This will result in the following output:
105
106<img src="./source/_static/img/s_custom_variables_extension.png" width="300">
107
108Right now we only support PyTorch version as custom variable, but will support others in the future.
109
110You can use the variables in both regular text and code blocks.
111
112## Including READMEs to the Documentation Build
113
114You might want to include some of the `README.md` files from various directories
115in this repositories in your documentation build. To do that, create an `.md`
116file and use the `{include}` directive to insert your `.md` files. Example:
117
118````
119```{include} ../README.md
120````
121
122**NOTE:** Many `README.md` files are written as placeholders with limited
123information provided. Some of that content you might want to keep in the
124repository rather than on the website. If you still want to add it, make sure to
125check the content for accuracy, structure, and overall quality.
126
127## Contributing
128
129Use the
130[PyTorch contributing guidelines](https://github.com/pytorch/pytorch/blob/main/CONTRIBUTING.md#writing-documentation)
131to contribute to the documentation.
132
133In addition to that, see
134[Markdown in Sphinx Tips and Tricks](https://pytorch.org/executorch/markdown-sphinx-tips-tricks.html)
135for tips on how to author high-quality markdown pages with Myst Parser.
136
137## Adding Tutorials
138
139You can add both interactive (`.py`) and non-interactive tutorials (`.md`) to
140this documentation. All tutorials should go to the `tutorials_source/`
141directory. Use one of the following templates:
142
143- [Python Template](https://github.com/pytorch/executorch/blob/main/docs/source/tutorials_source/template_tutorial.py)
144- [Markdown template](https://github.com/pytorch/executorch/blob/main/docs/source/tutorial-template.md)
145
146After creating a tutorial, make sure to add the corresponding path in the
147[index.rst](./source/index.rst) file in the following places:
148
149- In the
150  [tutorials torctree](https://github.com/pytorch/executorch/blob/main/docs/source/index.rst?plain=1#L183)
151- In the
152  [customcard section](https://github.com/pytorch/executorch/blob/main/docs/source/index.rst?plain=1#L201)
153
154If you want to include a Markdown tutorial that is stored in another directory
155outside of the `docs/source` directory, complete the following steps:
156
1571. Create an `.md` file under `source/tutorials_source`. Name that file after
158   your tutorial.
1592. Include the following in that file:
160
161   ````
162   ```{include} ../path-to-your-file/outside-of-the-docs-dir.md```
163   ````
164
165   **NOTE:** Your tutorial source file needs to follow the tutorial template.
166
1673. Add the file that you have created in **Step 1** to the `index.rst` toctree
168   and add a `customcarditem` with the link to that file.
169
170For example, if I wanted to include the `README.md` file from
171`examples/selective_build` as a tutorial under
172`pytorch.org/executorch/tutorials`, I could create a file called
173`tutorials_source/selective-build-tutorial.md` and add the following to that
174file:
175
176````
177```{include} ../../../examples/selective_build/README.md
178````
179
180In the `index.rst` file, I would add `tutorials/selective-build-tutorial` in
181both the `toctree` and the `cusotmcarditem` sections.
182
183# Auto-generated API documentation
184
185We use Sphinx to generate both Python and C++ documentation in the form of HTML
186pages.
187
188### Python APIs
189
190We generate Python API documentation through Sphinx and `sphinx.ext.autodoc`.
191
192The setup for Python documentation lies within `source/`. Sphinx uses the
193`conf.py` configuration file where `sphinx.ext.autodoc` is configured as
194extension. During the build, Sphinx generates the API documentation from the
195docstrings defined in your Python files.
196
197To define which API documentation to generate, you need to set up `.rst` files
198that reference the modules you want to build documentation for. To auto-generate
199APIs for a specific module, the `automodule` tag is needed to tell Sphinx what
200specific module to document. For example, if we wanted a page to display
201auto-generated documentation for everything in `exir/__init__.py` (relative to
202the root of the repo), the RST file would look something like the following:
203
204```
205executorch.exir
206=======================
207
208.. automodule:: exir
209   :members:
210   :undoc-members:
211   :show-inheritance:
212```
213
214These separate `.rst` files should all be linked together, with the initial
215landing page under `index.rst`.
216
217### C++ APIs
218
219Following Pytorch's way of generating C++ documentation, we generate C++ API
220documentation through Doxygen, which is then converted into
221[Sphinx](http://www.sphinx-doc.org/) using
222[Breathe](https://github.com/michaeljones/breathe).
223
224Specifically, we use Doxygen to generate C++ documentation in the form of XML
225files, and through configs set in Sphinx's `conf.py` file, we use Breathe and
226Exhale to use the XML files and generate RST files which are then used to
227generate HTML files.
228
229To configure Doxygen, we can run `doxygen Doxyfile` in the root of our
230repository (ex. `docs/source`) which will generate a `Doxyfile` containing
231configurations for generating c++ documentation. Specifically, the most
232important/relevant parts are:
233
234- `OUTPUT_DIRECTORY` specifies where to output the auto-generated XML files
235- `INPUT` specifies which files to generate documenation for
236- `GENERATE_XML = YES`
237
238If you need to include new files, simply add them to the `INPUT` in the
239`Doxyfile`. The generated output is included to the ExecuTorch documentation
240build and referenced in `index.rst`.
241