CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
pytorch

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: pytorch/tutorials
Path: blob/main/conf.py
Views: 492
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
pio.renderers.default = 'sphinx_gallery'
49
50
51
try:
52
import torchvision
53
except ImportError:
54
import warnings
55
warnings.warn('unable to load "torchvision" package')
56
import pytorch_sphinx_theme
57
58
rst_epilog ="""
59
.. |edit| image:: /_static/pencil-16.png
60
:width: 16px
61
:height: 16px
62
"""
63
64
# -- General configuration ------------------------------------------------
65
66
# If your documentation needs a minimal Sphinx version, state it here.
67
#
68
# needs_sphinx = '1.0'
69
70
html_meta = {
71
'description': 'Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!',
72
'keywords': 'PyTorch, tutorials, Getting Started, deep learning, AI',
73
'author': 'PyTorch Contributors'
74
}
75
76
# Add any Sphinx extension module names here, as strings. They can be
77
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
78
# ones.
79
extensions = [
80
'sphinxcontrib.katex',
81
'sphinx.ext.intersphinx',
82
'sphinx_copybutton',
83
'sphinx_gallery.gen_gallery',
84
'sphinx_design',
85
'sphinx_sitemap'
86
]
87
88
intersphinx_mapping = {
89
"torch": ("https://pytorch.org/docs/stable/", None),
90
"tensordict": ("https://pytorch.github.io/tensordict/", None),
91
"torchrl": ("https://pytorch.org/rl/", None),
92
"torchaudio": ("https://pytorch.org/audio/stable/", None),
93
"torchtext": ("https://pytorch.org/text/stable/", None),
94
"torchvision": ("https://pytorch.org/vision/stable/", None),
95
}
96
97
# -- Sphinx-gallery configuration --------------------------------------------
98
99
def reset_seeds(gallery_conf, fname):
100
torch.cuda.empty_cache()
101
torch.manual_seed(42)
102
torch.set_default_device(None)
103
random.seed(10)
104
numpy.random.seed(10)
105
gc.collect()
106
107
sphinx_gallery_conf = {
108
'examples_dirs': ['beginner_source', 'intermediate_source',
109
'advanced_source', 'recipes_source', 'prototype_source'],
110
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],
111
'filename_pattern': re.compile(SPHINX_SHOULD_RUN),
112
'promote_jupyter_magic': True,
113
'backreferences_dir': None,
114
'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"
115
"# https://pytorch.org/tutorials/beginner/colab\n"
116
"%matplotlib inline"),
117
'reset_modules': (reset_seeds),
118
'ignore_pattern': r'_torch_export_nightly_tutorial.py',
119
'pypandoc': {'extra_args': ['--mathjax', '--toc'],
120
'filters': ['.jenkins/custom_pandoc_filter.py'],
121
},
122
}
123
124
html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap
125
sitemap_locales = [None]
126
sitemap_excludes = [
127
"search.html",
128
"genindex.html",
129
]
130
sitemap_url_scheme = "{link}"
131
132
if os.getenv('GALLERY_PATTERN'):
133
# GALLERY_PATTERN is to be used when you want to work on a single
134
# tutorial. Previously this was fed into filename_pattern, but
135
# if you do that, you still end up parsing all of the other Python
136
# files which takes a few seconds. This strategy is better, as
137
# ignore_pattern also skips parsing.
138
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
139
# for a more detailed description of the issue.
140
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
141
142
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
143
gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]
144
source_dir = sphinx_gallery_conf['examples_dirs'][i]
145
# Create gallery dirs if it doesn't exist
146
try:
147
os.mkdir(gallery_dir)
148
except OSError:
149
pass
150
151
# Copy rst files from source dir to gallery dir
152
for f in glob.glob(os.path.join(source_dir, '*.rst')):
153
distutils.file_util.copy_file(f, gallery_dir, update=True)
154
155
156
# Add any paths that contain templates here, relative to this directory.
157
158
159
templates_path = ['_templates']
160
161
# The suffix(es) of source filenames.
162
# You can specify multiple suffix as a list of string:
163
#
164
# source_suffix = ['.rst', '.md']
165
source_suffix = '.rst'
166
167
# The master toctree document.
168
master_doc = 'index'
169
170
# General information about the project.
171
project = 'PyTorch Tutorials'
172
copyright = '2024, PyTorch'
173
author = 'PyTorch contributors'
174
175
# The version info for the project you're documenting, acts as replacement for
176
# |version| and |release|, also used in various other places throughout the
177
# built documents.
178
#
179
# The short X.Y version.
180
version = str(torch.__version__)
181
# The full version, including alpha/beta/rc tags.
182
release = str(torch.__version__)
183
184
# The language for content autogenerated by Sphinx. Refer to documentation
185
# for a list of supported languages.
186
#
187
# This is also used if you do content translation via gettext catalogs.
188
# Usually you set "language" from the command line for these cases.
189
language = 'en'
190
191
# List of patterns, relative to source directory, that match files and
192
# directories to ignore when looking for source files.
193
# This patterns also effect to html_static_path and html_extra_path
194
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*']
195
exclude_patterns += sphinx_gallery_conf['examples_dirs']
196
exclude_patterns += ['*/index.rst']
197
198
# The name of the Pygments (syntax highlighting) style to use.
199
pygments_style = 'sphinx'
200
201
# If true, `todo` and `todoList` produce output, else they produce nothing.
202
todo_include_todos = False
203
204
205
# -- Options for HTML output ----------------------------------------------
206
207
# The theme to use for HTML and HTML Help pages. See the documentation for
208
# a list of builtin themes.
209
#
210
# html_theme = 'alabaster'
211
212
# # Theme options are theme-specific and customize the look and feel of a theme
213
# # further. For a list of options available for each theme, see the
214
# # documentation.
215
# #
216
217
# html_theme_options = {
218
# 'page_width': '1000px',
219
# 'fixed_sidebar': True,
220
# 'code_font_size': '0.87em',
221
# 'sidebar_includehidden': True
222
# }
223
224
# # Add any paths that contain custom static files (such as style sheets) here,
225
# # relative to this directory. They are copied after the builtin static files,
226
# # so a file named "default.css" will overwrite the builtin "default.css".
227
html_static_path = ['_static']
228
229
# # Custom sidebar templates, maps document names to template names.
230
# html_sidebars = {
231
# 'index': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html'],
232
# '**': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html']
233
# }
234
235
236
html_theme = 'pytorch_sphinx_theme'
237
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
238
html_logo = '_static/img/pytorch-logo-dark.svg'
239
html_theme_options = {
240
'pytorch_project': 'tutorials',
241
'collapse_navigation': False,
242
'display_version': True,
243
'navigation_with_keys': True,
244
'logo_only': False,
245
'analytics_id': 'GTM-T8XT4PS',
246
}
247
248
249
# -- Options for HTMLHelp output ------------------------------------------
250
251
# Output file base name for HTML help builder.
252
htmlhelp_basename = 'PyTorchTutorialsdoc'
253
254
255
# -- Options for LaTeX output ---------------------------------------------
256
257
latex_elements = {
258
# The paper size ('letterpaper' or 'a4paper').
259
#
260
# 'papersize': 'letterpaper',
261
262
# The font size ('10pt', '11pt' or '12pt').
263
#
264
# 'pointsize': '10pt',
265
266
# Additional stuff for the LaTeX preamble.
267
#
268
# 'preamble': '',
269
270
# Latex figure (float) alignment
271
#
272
# 'figure_align': 'htbp',
273
}
274
275
# Grouping the document tree into LaTeX files. List of tuples
276
# (source start file, target name, title,
277
# author, documentclass [howto, manual, or own class]).
278
latex_documents = [
279
(master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials',
280
'Sasank, PyTorch contributors', 'manual'),
281
]
282
283
284
# -- Options for manual page output ---------------------------------------
285
286
# One entry per manual page. List of tuples
287
# (source start file, name, description, authors, manual section).
288
man_pages = [
289
(master_doc, 'pytorchtutorials', 'PyTorch Tutorials',
290
[author], 1)
291
]
292
293
294
# -- Options for Texinfo output -------------------------------------------
295
296
# Grouping the document tree into Texinfo files. List of tuples
297
# (source start file, target name, title, author,
298
# dir menu entry, description, category)
299
texinfo_documents = [
300
(master_doc, 'PyTorchTutorials', 'PyTorch Tutorials',
301
author, 'PyTorchTutorials', 'One line description of project.',
302
'Miscellaneous'),
303
]
304
305
html_css_files = [
306
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
307
'css/custom.css',
308
'css/custom2.css'
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