Skip to content

Commit ffab05c

Browse files
committed
Update
1 parent 34b91c9 commit ffab05c

File tree

2 files changed

+106
-143
lines changed

2 files changed

+106
-143
lines changed

conf.py

+93-126
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,34 @@
2929
#
3030
import os
3131
import sys
32-
33-
sys.path.insert(0, os.path.abspath("."))
34-
sys.path.insert(0, os.path.abspath("./.jenkins"))
35-
import distutils.file_util
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
3637
import gc
3738
import glob
3839
import random
39-
import re
4040
import shutil
41-
from pathlib import Path
42-
43-
import numpy
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
4445
import pandocfilters
45-
import plotly.io as pio
4646
import pypandoc
47-
import pytorch_sphinx_theme
48-
import torch
49-
from custom_directives import (
50-
CustomCalloutItemDirective,
51-
CustomCardItemDirective,
52-
CustomGalleryItemDirective,
53-
GalleryItemDirective,
54-
IncludeDirective,
55-
)
56-
from get_sphinx_filenames import SPHINX_SHOULD_RUN
57-
58-
pio.renderers.default = "sphinx_gallery"
47+
import plotly.io as pio
48+
from pathlib import Path
49+
pio.renderers.default = 'sphinx_gallery'
5950

6051

6152
try:
6253
import torchvision
6354
except ImportError:
6455
import warnings
65-
6656
warnings.warn('unable to load "torchvision" package')
6757
import pytorch_sphinx_theme
6858

69-
rst_epilog = """
59+
rst_epilog ="""
7060
.. |edit| image:: /_static/pencil-16.png
7161
:width: 16px
7262
:height: 16px
@@ -79,21 +69,21 @@
7969
# needs_sphinx = '1.0'
8070

8171
html_meta = {
82-
"description": "Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!",
83-
"keywords": "PyTorch, tutorials, Getting Started, deep learning, AI",
84-
"author": "PyTorch Contributors",
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'
8575
}
8676

8777
# Add any Sphinx extension module names here, as strings. They can be
8878
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
8979
# ones.
9080
extensions = [
91-
"sphinxcontrib.katex",
92-
"sphinx.ext.intersphinx",
93-
"sphinx_copybutton",
94-
"sphinx_gallery.gen_gallery",
95-
"sphinx_design",
96-
"sphinx_sitemap",
81+
'sphinxcontrib.katex',
82+
'sphinx.ext.intersphinx',
83+
'sphinx_copybutton',
84+
'sphinx_gallery.gen_gallery',
85+
'sphinx_design',
86+
'sphinx_sitemap'
9787
]
9888

9989
intersphinx_mapping = {
@@ -107,75 +97,63 @@
10797

10898
# -- Sphinx-gallery configuration --------------------------------------------
10999

110-
111100
def reset_seeds(gallery_conf, fname):
112101
torch.cuda.empty_cache()
113102
torch.backends.cudnn.deterministic = True
114103
torch.backends.cudnn.benchmark = False
115104
torch._dynamo.reset()
116105
torch.manual_seed(42)
117-
torch.cuda.manual_seed_all(42)
118106
torch.set_default_device(None)
119107
random.seed(10)
120108
numpy.random.seed(10)
121109
torch.set_grad_enabled(True)
122-
torch.set_default_dtype(torch.float32)
123-
torch.set_default_tensor_type(torch.FloatTensor)
124110

125-
# Clean up any global state without reloading
126-
if hasattr(torch, "_C"):
127-
if hasattr(torch._C, "_jit_clear_class_registry"):
128-
torch._C._jit_clear_class_registry()
111+
# Reset any patching from memory_format_tutorial
112+
if hasattr(torch, "old_attrs"):
113+
for (m, attrs) in torch.old_attrs.items():
114+
for (k, v) in attrs.items():
115+
setattr(m, k, v)
116+
delattr(torch, "old_attrs")
129117

130-
gc.collect()
131118

119+
gc.collect()
132120

133121
sphinx_gallery_conf = {
134-
"examples_dirs": [
135-
"beginner_source",
136-
"intermediate_source",
137-
"advanced_source",
138-
"recipes_source",
139-
"prototype_source",
140-
],
141-
"gallery_dirs": ["beginner", "intermediate", "advanced", "recipes", "prototype"],
142-
"filename_pattern": re.compile(SPHINX_SHOULD_RUN),
143-
"promote_jupyter_magic": True,
144-
"backreferences_dir": None,
145-
"first_notebook_cell": (
146-
"# For tips on running notebooks in Google Colab, see\n"
147-
"# https://pytorch.org/tutorials/beginner/colab\n"
148-
"%matplotlib inline"
149-
),
150-
"reset_modules": (reset_seeds),
151-
"ignore_pattern": r"_torch_export_nightly_tutorial.py",
152-
"pypandoc": {
153-
"extra_args": ["--mathjax", "--toc"],
154-
"filters": [".jenkins/custom_pandoc_filter.py"],
122+
'examples_dirs': ['beginner_source', 'intermediate_source',
123+
'advanced_source', 'recipes_source', 'prototype_source'],
124+
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],
125+
'filename_pattern': re.compile(SPHINX_SHOULD_RUN),
126+
'promote_jupyter_magic': True,
127+
'backreferences_dir': None,
128+
'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"
129+
"# https://pytorch.org/tutorials/beginner/colab\n"
130+
"%matplotlib inline"),
131+
'reset_modules': (reset_seeds),
132+
'ignore_pattern': r'_torch_export_nightly_tutorial.py',
133+
'pypandoc': {'extra_args': ['--mathjax', '--toc'],
134+
'filters': ['.jenkins/custom_pandoc_filter.py'],
155135
},
156136
}
157137

158-
html_baseurl = "https://pytorch.org/tutorials/" # needed for sphinx-sitemap
138+
html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap
159139
sitemap_locales = [None]
160140
sitemap_excludes = [
161141
"search.html",
162142
"genindex.html",
163143
]
164144
sitemap_url_scheme = "{link}"
165145

166-
if os.getenv("GALLERY_PATTERN"):
146+
if os.getenv('GALLERY_PATTERN'):
167147
# GALLERY_PATTERN is to be used when you want to work on a single
168148
# tutorial. Previously this was fed into filename_pattern, but
169149
# if you do that, you still end up parsing all of the other Python
170150
# files which takes a few seconds. This strategy is better, as
171151
# ignore_pattern also skips parsing.
172152
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
173153
# for a more detailed description of the issue.
174-
sphinx_gallery_conf["ignore_pattern"] = (
175-
r"/(?!" + re.escape(os.getenv("GALLERY_PATTERN")) + r")[^/]+$"
176-
)
154+
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
177155

178-
for i in range(len(sphinx_gallery_conf["examples_dirs"])):
156+
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
179157
gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i])
180158
source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])
181159

@@ -187,21 +165,21 @@ def reset_seeds(gallery_conf, fname):
187165
distutils.file_util.copy_file(f, gallery_subdir_path, update=True)
188166

189167
# Add any paths that contain templates here, relative to this directory.
190-
templates_path = ["_templates"]
168+
templates_path = ['_templates']
191169

192170
# The suffix(es) of source filenames.
193171
# You can specify multiple suffix as a list of string:
194172
#
195173
# source_suffix = ['.rst', '.md']
196-
source_suffix = ".rst"
174+
source_suffix = '.rst'
197175

198176
# The master toctree document.
199-
master_doc = "index"
177+
master_doc = 'index'
200178

201179
# General information about the project.
202-
project = "PyTorch Tutorials"
203-
copyright = "2024, PyTorch"
204-
author = "PyTorch contributors"
180+
project = 'PyTorch Tutorials'
181+
copyright = '2024, PyTorch'
182+
author = 'PyTorch contributors'
205183

206184
# The version info for the project you're documenting, acts as replacement for
207185
# |version| and |release|, also used in various other places throughout the
@@ -217,22 +195,17 @@ def reset_seeds(gallery_conf, fname):
217195
#
218196
# This is also used if you do content translation via gettext catalogs.
219197
# Usually you set "language" from the command line for these cases.
220-
language = "en"
198+
language = 'en'
221199

222200
# List of patterns, relative to source directory, that match files and
223201
# directories to ignore when looking for source files.
224202
# This patterns also effect to html_static_path and html_extra_path
225-
exclude_patterns = [
226-
"_build",
227-
"Thumbs.db",
228-
".DS_Store",
229-
"src/pytorch-sphinx-theme/docs*",
230-
]
231-
exclude_patterns += sphinx_gallery_conf["examples_dirs"]
232-
exclude_patterns += ["*/index.rst"]
203+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*']
204+
exclude_patterns += sphinx_gallery_conf['examples_dirs']
205+
exclude_patterns += ['*/index.rst']
233206

234207
# The name of the Pygments (syntax highlighting) style to use.
235-
pygments_style = "sphinx"
208+
pygments_style = 'sphinx'
236209

237210
# If true, `todo` and `todoList` produce output, else they produce nothing.
238211
todo_include_todos = False
@@ -260,7 +233,7 @@ def reset_seeds(gallery_conf, fname):
260233
# # Add any paths that contain custom static files (such as style sheets) here,
261234
# # relative to this directory. They are copied after the builtin static files,
262235
# # so a file named "default.css" will overwrite the builtin "default.css".
263-
html_static_path = ["_static"]
236+
html_static_path = ['_static']
264237

265238
# # Custom sidebar templates, maps document names to template names.
266239
# html_sidebars = {
@@ -269,23 +242,23 @@ def reset_seeds(gallery_conf, fname):
269242
# }
270243

271244

272-
html_theme = "pytorch_sphinx_theme"
245+
html_theme = 'pytorch_sphinx_theme'
273246
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
274-
html_logo = "_static/img/pytorch-logo-dark.svg"
247+
html_logo = '_static/img/pytorch-logo-dark.svg'
275248
html_theme_options = {
276-
"pytorch_project": "tutorials",
277-
"collapse_navigation": False,
278-
"display_version": True,
279-
"navigation_with_keys": True,
280-
"logo_only": False,
281-
"analytics_id": "GTM-T8XT4PS",
249+
'pytorch_project': 'tutorials',
250+
'collapse_navigation': False,
251+
'display_version': True,
252+
'navigation_with_keys': True,
253+
'logo_only': False,
254+
'analytics_id': 'GTM-T8XT4PS',
282255
}
283256

284257

285258
# -- Options for HTMLHelp output ------------------------------------------
286259

287260
# Output file base name for HTML help builder.
288-
htmlhelp_basename = "PyTorchTutorialsdoc"
261+
htmlhelp_basename = 'PyTorchTutorialsdoc'
289262

290263

291264
# -- Options for LaTeX output ---------------------------------------------
@@ -294,12 +267,15 @@ def reset_seeds(gallery_conf, fname):
294267
# The paper size ('letterpaper' or 'a4paper').
295268
#
296269
# 'papersize': 'letterpaper',
270+
297271
# The font size ('10pt', '11pt' or '12pt').
298272
#
299273
# 'pointsize': '10pt',
274+
300275
# Additional stuff for the LaTeX preamble.
301276
#
302277
# 'preamble': '',
278+
303279
# Latex figure (float) alignment
304280
#
305281
# 'figure_align': 'htbp',
@@ -309,21 +285,19 @@ def reset_seeds(gallery_conf, fname):
309285
# (source start file, target name, title,
310286
# author, documentclass [howto, manual, or own class]).
311287
latex_documents = [
312-
(
313-
master_doc,
314-
"PyTorchTutorials.tex",
315-
"PyTorch Tutorials",
316-
"Sasank, PyTorch contributors",
317-
"manual",
318-
),
288+
(master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials',
289+
'Sasank, PyTorch contributors', 'manual'),
319290
]
320291

321292

322293
# -- Options for manual page output ---------------------------------------
323294

324295
# One entry per manual page. List of tuples
325296
# (source start file, name, description, authors, manual section).
326-
man_pages = [(master_doc, "pytorchtutorials", "PyTorch Tutorials", [author], 1)]
297+
man_pages = [
298+
(master_doc, 'pytorchtutorials', 'PyTorch Tutorials',
299+
[author], 1)
300+
]
327301

328302

329303
# -- Options for Texinfo output -------------------------------------------
@@ -332,47 +306,40 @@ def reset_seeds(gallery_conf, fname):
332306
# (source start file, target name, title, author,
333307
# dir menu entry, description, category)
334308
texinfo_documents = [
335-
(
336-
master_doc,
337-
"PyTorchTutorials",
338-
"PyTorch Tutorials",
339-
author,
340-
"PyTorchTutorials",
341-
"One line description of project.",
342-
"Miscellaneous",
343-
),
309+
(master_doc, 'PyTorchTutorials', 'PyTorch Tutorials',
310+
author, 'PyTorchTutorials', 'One line description of project.',
311+
'Miscellaneous'),
344312
]
345313

346314
html_css_files = [
347-
"https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css",
348-
"css/custom.css",
349-
"css/custom2.css",
350-
]
315+
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
316+
'css/custom.css',
317+
'css/custom2.css'
318+
]
351319

352320
html_js_files = [
353321
"js/custom.js",
354322
]
355323

356-
357324
def setup(app):
358325
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
359326
# and can be moved outside of this function (and the setup(app) function
360327
# can be deleted).
361-
# html_css_files = [
328+
#html_css_files = [
362329
# 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
363330
# 'css/custom.css'
364-
# ]
331+
#]
365332
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
366333
# `add_stylesheet` (deprecated in 1.8).
367-
# add_css = getattr(app, 'add_css_file', app.add_stylesheet)
368-
# for css_file in html_css_files:
334+
#add_css = getattr(app, 'add_css_file', app.add_stylesheet)
335+
#for css_file in html_css_files:
369336
# add_css(css_file)
370337
# Custom CSS
371-
# app.add_stylesheet('css/pytorch_theme.css')
338+
#app.add_stylesheet('css/pytorch_theme.css')
372339
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')
373340
# Custom directives
374-
app.add_directive("includenodoc", IncludeDirective)
375-
app.add_directive("galleryitem", GalleryItemDirective)
376-
app.add_directive("customgalleryitem", CustomGalleryItemDirective)
377-
app.add_directive("customcarditem", CustomCardItemDirective)
378-
app.add_directive("customcalloutitem", CustomCalloutItemDirective)
341+
app.add_directive('includenodoc', IncludeDirective)
342+
app.add_directive('galleryitem', GalleryItemDirective)
343+
app.add_directive('customgalleryitem', CustomGalleryItemDirective)
344+
app.add_directive('customcarditem', CustomCardItemDirective)
345+
app.add_directive('customcalloutitem', CustomCalloutItemDirective)

0 commit comments

Comments
 (0)