CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
pytorch

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: pytorch/tutorials
Path: blob/main/conf.py
Views: 710
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#
4
# PyTorch Tutorials documentation build configuration file, created by
5
# sphinx-quickstart on Wed Mar 8 22:38:10 2017.
6
#
7
# This file is execfile()d with the current directory set to its
8
# containing dir.
9
#
10
# Note that not all possible configuration values are present in this
11
# autogenerated file.
12
#
13
# All configuration values have a default; values that are commented out
14
# serve to show the default.
15
#
16
17
# Because the sphinx gallery might take a long time, you can control specific
18
# files that generate the results using `GALLERY_PATTERN` environment variable,
19
# For example to run only `neural_style_transfer_tutorial.py`:
20
# GALLERY_PATTERN="neural_style_transfer_tutorial.py" make html
21
# or
22
# GALLERY_PATTERN="neural_style_transfer_tutorial.py" sphinx-build . _build
23
#
24
# GALLERY_PATTERN variable respects regular expressions.
25
26
# If extensions (or modules to document with autodoc) are in another directory,
27
# add these directories to sys.path here. If the directory is relative to the
28
# documentation root, use os.path.abspath to make it absolute, like shown here.
29
#
30
import os
31
import sys
32
sys.path.insert(0, os.path.abspath('.'))
33
sys.path.insert(0, os.path.abspath('./.jenkins'))
34
import pytorch_sphinx_theme
35
import torch
36
import numpy
37
import gc
38
import glob
39
import random
40
import shutil
41
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
42
import distutils.file_util
43
import re
44
from get_sphinx_filenames import SPHINX_SHOULD_RUN
45
import pandocfilters
46
import pypandoc
47
import plotly.io as pio
48
from pathlib import Path
49
pio.renderers.default = 'sphinx_gallery'
50
51
52
try:
53
import torchvision
54
except ImportError:
55
import warnings
56
warnings.warn('unable to load "torchvision" package')
57
import pytorch_sphinx_theme
58
59
rst_epilog ="""
60
.. |edit| image:: /_static/pencil-16.png
61
:width: 16px
62
:height: 16px
63
"""
64
65
# -- General configuration ------------------------------------------------
66
67
# If your documentation needs a minimal Sphinx version, state it here.
68
#
69
# needs_sphinx = '1.0'
70
71
html_meta = {
72
'description': 'Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!',
73
'keywords': 'PyTorch, tutorials, Getting Started, deep learning, AI',
74
'author': 'PyTorch Contributors'
75
}
76
77
# Add any Sphinx extension module names here, as strings. They can be
78
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
79
# ones.
80
extensions = [
81
'sphinxcontrib.katex',
82
'sphinx.ext.intersphinx',
83
'sphinx_copybutton',
84
'sphinx_gallery.gen_gallery',
85
'sphinx_design',
86
'sphinx_sitemap'
87
]
88
89
intersphinx_mapping = {
90
"torch": ("https://pytorch.org/docs/stable/", None),
91
"tensordict": ("https://pytorch.github.io/tensordict/", None),
92
"torchrl": ("https://pytorch.org/rl/", None),
93
"torchaudio": ("https://pytorch.org/audio/stable/", None),
94
"torchtext": ("https://pytorch.org/text/stable/", None),
95
"torchvision": ("https://pytorch.org/vision/stable/", None),
96
}
97
98
# -- Sphinx-gallery configuration --------------------------------------------
99
100
def reset_seeds(gallery_conf, fname):
101
torch.cuda.empty_cache()
102
torch.manual_seed(42)
103
torch.set_default_device(None)
104
random.seed(10)
105
numpy.random.seed(10)
106
gc.collect()
107
108
sphinx_gallery_conf = {
109
'examples_dirs': ['beginner_source', 'intermediate_source',
110
'advanced_source', 'recipes_source', 'prototype_source'],
111
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],
112
'filename_pattern': re.compile(SPHINX_SHOULD_RUN),
113
'promote_jupyter_magic': True,
114
'backreferences_dir': None,
115
'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"
116
"# https://pytorch.org/tutorials/beginner/colab\n"
117
"%matplotlib inline"),
118
'reset_modules': (reset_seeds),
119
'ignore_pattern': r'_torch_export_nightly_tutorial.py',
120
'pypandoc': {'extra_args': ['--mathjax', '--toc'],
121
'filters': ['.jenkins/custom_pandoc_filter.py'],
122
},
123
}
124
125
html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap
126
sitemap_locales = [None]
127
sitemap_excludes = [
128
"search.html",
129
"genindex.html",
130
]
131
sitemap_url_scheme = "{link}"
132
133
if os.getenv('GALLERY_PATTERN'):
134
# GALLERY_PATTERN is to be used when you want to work on a single
135
# tutorial. Previously this was fed into filename_pattern, but
136
# if you do that, you still end up parsing all of the other Python
137
# files which takes a few seconds. This strategy is better, as
138
# ignore_pattern also skips parsing.
139
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
140
# for a more detailed description of the issue.
141
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
142
143
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
144
gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i])
145
source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])
146
147
# Copy rst files from source dir to gallery dir
148
for f in source_dir.rglob("*.rst"):
149
f_dir = Path(f).parent
150
gallery_subdir_path = gallery_dir / f_dir.relative_to(source_dir)
151
gallery_subdir_path.mkdir(parents=True, exist_ok=True)
152
distutils.file_util.copy_file(f, gallery_subdir_path, update=True)
153
154
# Add any paths that contain templates here, relative to this directory.
155
templates_path = ['_templates']
156
157
# The suffix(es) of source filenames.
158
# You can specify multiple suffix as a list of string:
159
#
160
# source_suffix = ['.rst', '.md']
161
source_suffix = '.rst'
162
163
# The master toctree document.
164
master_doc = 'index'
165
166
# General information about the project.
167
project = 'PyTorch Tutorials'
168
copyright = '2024, PyTorch'
169
author = 'PyTorch contributors'
170
171
# The version info for the project you're documenting, acts as replacement for
172
# |version| and |release|, also used in various other places throughout the
173
# built documents.
174
#
175
# The short X.Y version.
176
version = str(torch.__version__)
177
# The full version, including alpha/beta/rc tags.
178
release = str(torch.__version__)
179
180
# The language for content autogenerated by Sphinx. Refer to documentation
181
# for a list of supported languages.
182
#
183
# This is also used if you do content translation via gettext catalogs.
184
# Usually you set "language" from the command line for these cases.
185
language = 'en'
186
187
# List of patterns, relative to source directory, that match files and
188
# directories to ignore when looking for source files.
189
# This patterns also effect to html_static_path and html_extra_path
190
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*']
191
exclude_patterns += sphinx_gallery_conf['examples_dirs']
192
exclude_patterns += ['*/index.rst']
193
194
# The name of the Pygments (syntax highlighting) style to use.
195
pygments_style = 'sphinx'
196
197
# If true, `todo` and `todoList` produce output, else they produce nothing.
198
todo_include_todos = False
199
200
201
# -- Options for HTML output ----------------------------------------------
202
203
# The theme to use for HTML and HTML Help pages. See the documentation for
204
# a list of builtin themes.
205
#
206
# html_theme = 'alabaster'
207
208
# # Theme options are theme-specific and customize the look and feel of a theme
209
# # further. For a list of options available for each theme, see the
210
# # documentation.
211
# #
212
213
# html_theme_options = {
214
# 'page_width': '1000px',
215
# 'fixed_sidebar': True,
216
# 'code_font_size': '0.87em',
217
# 'sidebar_includehidden': True
218
# }
219
220
# # Add any paths that contain custom static files (such as style sheets) here,
221
# # relative to this directory. They are copied after the builtin static files,
222
# # so a file named "default.css" will overwrite the builtin "default.css".
223
html_static_path = ['_static']
224
225
# # Custom sidebar templates, maps document names to template names.
226
# html_sidebars = {
227
# 'index': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html'],
228
# '**': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html']
229
# }
230
231
232
html_theme = 'pytorch_sphinx_theme'
233
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
234
html_logo = '_static/img/pytorch-logo-dark.svg'
235
html_theme_options = {
236
'pytorch_project': 'tutorials',
237
'collapse_navigation': False,
238
'display_version': True,
239
'navigation_with_keys': True,
240
'logo_only': False,
241
'analytics_id': 'GTM-T8XT4PS',
242
}
243
244
245
# -- Options for HTMLHelp output ------------------------------------------
246
247
# Output file base name for HTML help builder.
248
htmlhelp_basename = 'PyTorchTutorialsdoc'
249
250
251
# -- Options for LaTeX output ---------------------------------------------
252
253
latex_elements = {
254
# The paper size ('letterpaper' or 'a4paper').
255
#
256
# 'papersize': 'letterpaper',
257
258
# The font size ('10pt', '11pt' or '12pt').
259
#
260
# 'pointsize': '10pt',
261
262
# Additional stuff for the LaTeX preamble.
263
#
264
# 'preamble': '',
265
266
# Latex figure (float) alignment
267
#
268
# 'figure_align': 'htbp',
269
}
270
271
# Grouping the document tree into LaTeX files. List of tuples
272
# (source start file, target name, title,
273
# author, documentclass [howto, manual, or own class]).
274
latex_documents = [
275
(master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials',
276
'Sasank, PyTorch contributors', 'manual'),
277
]
278
279
280
# -- Options for manual page output ---------------------------------------
281
282
# One entry per manual page. List of tuples
283
# (source start file, name, description, authors, manual section).
284
man_pages = [
285
(master_doc, 'pytorchtutorials', 'PyTorch Tutorials',
286
[author], 1)
287
]
288
289
290
# -- Options for Texinfo output -------------------------------------------
291
292
# Grouping the document tree into Texinfo files. List of tuples
293
# (source start file, target name, title, author,
294
# dir menu entry, description, category)
295
texinfo_documents = [
296
(master_doc, 'PyTorchTutorials', 'PyTorch Tutorials',
297
author, 'PyTorchTutorials', 'One line description of project.',
298
'Miscellaneous'),
299
]
300
301
html_css_files = [
302
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
303
'css/custom.css',
304
'css/custom2.css'
305
]
306
307
html_js_files = [
308
"js/custom.js",
309
]
310
311
def setup(app):
312
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
313
# and can be moved outside of this function (and the setup(app) function
314
# can be deleted).
315
#html_css_files = [
316
# 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
317
# 'css/custom.css'
318
#]
319
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
320
# `add_stylesheet` (deprecated in 1.8).
321
#add_css = getattr(app, 'add_css_file', app.add_stylesheet)
322
#for css_file in html_css_files:
323
# add_css(css_file)
324
# Custom CSS
325
#app.add_stylesheet('css/pytorch_theme.css')
326
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')
327
# Custom directives
328
app.add_directive('includenodoc', IncludeDirective)
329
app.add_directive('galleryitem', GalleryItemDirective)
330
app.add_directive('customgalleryitem', CustomGalleryItemDirective)
331
app.add_directive('customcarditem', CustomCardItemDirective)
332
app.add_directive('customcalloutitem', CustomCalloutItemDirective)
333
334