29
29
#
30
30
import os
31
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
32
+
33
+ sys .path .insert (0 , os .path .abspath ("." ))
34
+ sys .path .insert (0 , os .path .abspath ("./.jenkins" ))
35
+ import distutils .file_util
37
36
import gc
38
37
import glob
39
38
import random
40
- import shutil
41
- from custom_directives import IncludeDirective , GalleryItemDirective , CustomGalleryItemDirective , CustomCalloutItemDirective , CustomCardItemDirective
42
- import distutils .file_util
43
39
import re
44
- from get_sphinx_filenames import SPHINX_SHOULD_RUN
40
+ import shutil
41
+ from pathlib import Path
42
+
43
+ import numpy
45
44
import pandocfilters
46
- import pypandoc
47
45
import plotly .io as pio
48
- from pathlib import Path
49
- pio .renderers .default = 'sphinx_gallery'
46
+ 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"
50
59
51
60
52
61
try :
53
62
import torchvision
54
63
except ImportError :
55
64
import warnings
65
+
56
66
warnings .warn ('unable to load "torchvision" package' )
57
67
import pytorch_sphinx_theme
58
68
59
- rst_epilog = """
69
+ rst_epilog = """
60
70
.. |edit| image:: /_static/pencil-16.png
61
71
:width: 16px
62
72
:height: 16px
69
79
# needs_sphinx = '1.0'
70
80
71
81
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'
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" ,
75
85
}
76
86
77
87
# Add any Sphinx extension module names here, as strings. They can be
78
88
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
79
89
# ones.
80
90
extensions = [
81
- ' sphinxcontrib.katex' ,
82
- ' sphinx.ext.intersphinx' ,
83
- ' sphinx_copybutton' ,
84
- ' sphinx_gallery.gen_gallery' ,
85
- ' sphinx_design' ,
86
- ' sphinx_sitemap'
91
+ " sphinxcontrib.katex" ,
92
+ " sphinx.ext.intersphinx" ,
93
+ " sphinx_copybutton" ,
94
+ " sphinx_gallery.gen_gallery" ,
95
+ " sphinx_design" ,
96
+ " sphinx_sitemap" ,
87
97
]
88
98
89
99
98
108
99
109
# -- Sphinx-gallery configuration --------------------------------------------
100
110
111
+
101
112
def reset_seeds (gallery_conf , fname ):
102
113
torch .cuda .empty_cache ()
103
114
torch .manual_seed (42 )
104
115
torch .set_default_device (None )
105
116
random .seed (10 )
106
117
numpy .random .seed (10 )
107
118
gc .collect ()
108
- torch ._dynamo ()
119
+ torch ._dynamo . reset ()
109
120
torch ._inductor .clear_compile_cache ()
110
121
122
+
111
123
sphinx_gallery_conf = {
112
- 'examples_dirs' : ['beginner_source' , 'intermediate_source' ,
113
- 'advanced_source' , 'recipes_source' , 'prototype_source' ],
114
- 'gallery_dirs' : ['beginner' , 'intermediate' , 'advanced' , 'recipes' , 'prototype' ],
115
- 'filename_pattern' : re .compile (SPHINX_SHOULD_RUN ),
116
- 'promote_jupyter_magic' : True ,
117
- 'backreferences_dir' : None ,
118
- 'first_notebook_cell' : ("# For tips on running notebooks in Google Colab, see\n "
119
- "# https://pytorch.org/tutorials/beginner/colab\n "
120
- "%matplotlib inline" ),
121
- 'reset_modules' : (reset_seeds ),
122
- 'ignore_pattern' : r'_torch_export_nightly_tutorial.py' ,
123
- 'pypandoc' : {'extra_args' : ['--mathjax' , '--toc' ],
124
- 'filters' : ['.jenkins/custom_pandoc_filter.py' ],
124
+ "examples_dirs" : [
125
+ "beginner_source" ,
126
+ "intermediate_source" ,
127
+ "advanced_source" ,
128
+ "recipes_source" ,
129
+ "prototype_source" ,
130
+ ],
131
+ "gallery_dirs" : ["beginner" , "intermediate" , "advanced" , "recipes" , "prototype" ],
132
+ "filename_pattern" : re .compile (SPHINX_SHOULD_RUN ),
133
+ "promote_jupyter_magic" : True ,
134
+ "backreferences_dir" : None ,
135
+ "first_notebook_cell" : (
136
+ "# For tips on running notebooks in Google Colab, see\n "
137
+ "# https://pytorch.org/tutorials/beginner/colab\n "
138
+ "%matplotlib inline"
139
+ ),
140
+ "reset_modules" : (reset_seeds ),
141
+ "ignore_pattern" : r"_torch_export_nightly_tutorial.py" ,
142
+ "pypandoc" : {
143
+ "extra_args" : ["--mathjax" , "--toc" ],
144
+ "filters" : [".jenkins/custom_pandoc_filter.py" ],
125
145
},
126
146
}
127
147
128
- html_baseurl = ' https://pytorch.org/tutorials/' # needed for sphinx-sitemap
148
+ html_baseurl = " https://pytorch.org/tutorials/" # needed for sphinx-sitemap
129
149
sitemap_locales = [None ]
130
150
sitemap_excludes = [
131
151
"search.html" ,
132
152
"genindex.html" ,
133
153
]
134
154
sitemap_url_scheme = "{link}"
135
155
136
- if os .getenv (' GALLERY_PATTERN' ):
156
+ if os .getenv (" GALLERY_PATTERN" ):
137
157
# GALLERY_PATTERN is to be used when you want to work on a single
138
158
# tutorial. Previously this was fed into filename_pattern, but
139
159
# if you do that, you still end up parsing all of the other Python
140
160
# files which takes a few seconds. This strategy is better, as
141
161
# ignore_pattern also skips parsing.
142
162
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
143
163
# for a more detailed description of the issue.
144
- sphinx_gallery_conf ['ignore_pattern' ] = r'/(?!' + re .escape (os .getenv ('GALLERY_PATTERN' )) + r')[^/]+$'
164
+ sphinx_gallery_conf ["ignore_pattern" ] = (
165
+ r"/(?!" + re .escape (os .getenv ("GALLERY_PATTERN" )) + r")[^/]+$"
166
+ )
145
167
146
- for i in range (len (sphinx_gallery_conf [' examples_dirs' ])):
168
+ for i in range (len (sphinx_gallery_conf [" examples_dirs" ])):
147
169
gallery_dir = Path (sphinx_gallery_conf ["gallery_dirs" ][i ])
148
170
source_dir = Path (sphinx_gallery_conf ["examples_dirs" ][i ])
149
171
@@ -155,21 +177,21 @@ def reset_seeds(gallery_conf, fname):
155
177
distutils .file_util .copy_file (f , gallery_subdir_path , update = True )
156
178
157
179
# Add any paths that contain templates here, relative to this directory.
158
- templates_path = [' _templates' ]
180
+ templates_path = [" _templates" ]
159
181
160
182
# The suffix(es) of source filenames.
161
183
# You can specify multiple suffix as a list of string:
162
184
#
163
185
# source_suffix = ['.rst', '.md']
164
- source_suffix = ' .rst'
186
+ source_suffix = " .rst"
165
187
166
188
# The master toctree document.
167
- master_doc = ' index'
189
+ master_doc = " index"
168
190
169
191
# General information about the project.
170
- project = ' PyTorch Tutorials'
171
- copyright = ' 2024, PyTorch'
172
- author = ' PyTorch contributors'
192
+ project = " PyTorch Tutorials"
193
+ copyright = " 2024, PyTorch"
194
+ author = " PyTorch contributors"
173
195
174
196
# The version info for the project you're documenting, acts as replacement for
175
197
# |version| and |release|, also used in various other places throughout the
@@ -185,17 +207,22 @@ def reset_seeds(gallery_conf, fname):
185
207
#
186
208
# This is also used if you do content translation via gettext catalogs.
187
209
# Usually you set "language" from the command line for these cases.
188
- language = 'en'
210
+ language = "en"
189
211
190
212
# List of patterns, relative to source directory, that match files and
191
213
# directories to ignore when looking for source files.
192
214
# This patterns also effect to html_static_path and html_extra_path
193
- exclude_patterns = ['_build' , 'Thumbs.db' , '.DS_Store' , 'src/pytorch-sphinx-theme/docs*' ]
194
- exclude_patterns += sphinx_gallery_conf ['examples_dirs' ]
195
- exclude_patterns += ['*/index.rst' ]
215
+ exclude_patterns = [
216
+ "_build" ,
217
+ "Thumbs.db" ,
218
+ ".DS_Store" ,
219
+ "src/pytorch-sphinx-theme/docs*" ,
220
+ ]
221
+ exclude_patterns += sphinx_gallery_conf ["examples_dirs" ]
222
+ exclude_patterns += ["*/index.rst" ]
196
223
197
224
# The name of the Pygments (syntax highlighting) style to use.
198
- pygments_style = ' sphinx'
225
+ pygments_style = " sphinx"
199
226
200
227
# If true, `todo` and `todoList` produce output, else they produce nothing.
201
228
todo_include_todos = False
@@ -223,7 +250,7 @@ def reset_seeds(gallery_conf, fname):
223
250
# # Add any paths that contain custom static files (such as style sheets) here,
224
251
# # relative to this directory. They are copied after the builtin static files,
225
252
# # so a file named "default.css" will overwrite the builtin "default.css".
226
- html_static_path = [' _static' ]
253
+ html_static_path = [" _static" ]
227
254
228
255
# # Custom sidebar templates, maps document names to template names.
229
256
# html_sidebars = {
@@ -232,23 +259,23 @@ def reset_seeds(gallery_conf, fname):
232
259
# }
233
260
234
261
235
- html_theme = ' pytorch_sphinx_theme'
262
+ html_theme = " pytorch_sphinx_theme"
236
263
html_theme_path = [pytorch_sphinx_theme .get_html_theme_path ()]
237
- html_logo = ' _static/img/pytorch-logo-dark.svg'
264
+ html_logo = " _static/img/pytorch-logo-dark.svg"
238
265
html_theme_options = {
239
- ' pytorch_project' : ' tutorials' ,
240
- ' collapse_navigation' : False ,
241
- ' display_version' : True ,
242
- ' navigation_with_keys' : True ,
243
- ' logo_only' : False ,
244
- ' analytics_id' : ' GTM-T8XT4PS' ,
266
+ " pytorch_project" : " tutorials" ,
267
+ " collapse_navigation" : False ,
268
+ " display_version" : True ,
269
+ " navigation_with_keys" : True ,
270
+ " logo_only" : False ,
271
+ " analytics_id" : " GTM-T8XT4PS" ,
245
272
}
246
273
247
274
248
275
# -- Options for HTMLHelp output ------------------------------------------
249
276
250
277
# Output file base name for HTML help builder.
251
- htmlhelp_basename = ' PyTorchTutorialsdoc'
278
+ htmlhelp_basename = " PyTorchTutorialsdoc"
252
279
253
280
254
281
# -- Options for LaTeX output ---------------------------------------------
@@ -257,15 +284,12 @@ def reset_seeds(gallery_conf, fname):
257
284
# The paper size ('letterpaper' or 'a4paper').
258
285
#
259
286
# 'papersize': 'letterpaper',
260
-
261
287
# The font size ('10pt', '11pt' or '12pt').
262
288
#
263
289
# 'pointsize': '10pt',
264
-
265
290
# Additional stuff for the LaTeX preamble.
266
291
#
267
292
# 'preamble': '',
268
-
269
293
# Latex figure (float) alignment
270
294
#
271
295
# 'figure_align': 'htbp',
@@ -275,19 +299,21 @@ def reset_seeds(gallery_conf, fname):
275
299
# (source start file, target name, title,
276
300
# author, documentclass [howto, manual, or own class]).
277
301
latex_documents = [
278
- (master_doc , 'PyTorchTutorials.tex' , 'PyTorch Tutorials' ,
279
- 'Sasank, PyTorch contributors' , 'manual' ),
302
+ (
303
+ master_doc ,
304
+ "PyTorchTutorials.tex" ,
305
+ "PyTorch Tutorials" ,
306
+ "Sasank, PyTorch contributors" ,
307
+ "manual" ,
308
+ ),
280
309
]
281
310
282
311
283
312
# -- Options for manual page output ---------------------------------------
284
313
285
314
# One entry per manual page. List of tuples
286
315
# (source start file, name, description, authors, manual section).
287
- man_pages = [
288
- (master_doc , 'pytorchtutorials' , 'PyTorch Tutorials' ,
289
- [author ], 1 )
290
- ]
316
+ man_pages = [(master_doc , "pytorchtutorials" , "PyTorch Tutorials" , [author ], 1 )]
291
317
292
318
293
319
# -- Options for Texinfo output -------------------------------------------
@@ -296,40 +322,47 @@ def reset_seeds(gallery_conf, fname):
296
322
# (source start file, target name, title, author,
297
323
# dir menu entry, description, category)
298
324
texinfo_documents = [
299
- (master_doc , 'PyTorchTutorials' , 'PyTorch Tutorials' ,
300
- author , 'PyTorchTutorials' , 'One line description of project.' ,
301
- 'Miscellaneous' ),
325
+ (
326
+ master_doc ,
327
+ "PyTorchTutorials" ,
328
+ "PyTorch Tutorials" ,
329
+ author ,
330
+ "PyTorchTutorials" ,
331
+ "One line description of project." ,
332
+ "Miscellaneous" ,
333
+ ),
302
334
]
303
335
304
336
html_css_files = [
305
- ' https://cdn.jsdelivr.net/npm/[email protected] /dist/katex.min.css' ,
306
- ' css/custom.css' ,
307
- ' css/custom2.css'
308
- ]
337
+ " https://cdn.jsdelivr.net/npm/[email protected] /dist/katex.min.css" ,
338
+ " css/custom.css" ,
339
+ " css/custom2.css" ,
340
+ ]
309
341
310
342
html_js_files = [
311
343
"js/custom.js" ,
312
344
]
313
345
346
+
314
347
def setup (app ):
315
348
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
316
349
# and can be moved outside of this function (and the setup(app) function
317
350
# can be deleted).
318
- #html_css_files = [
351
+ # html_css_files = [
319
352
# 'https://cdn.jsdelivr.net/npm/[email protected] /dist/katex.min.css',
320
353
# 'css/custom.css'
321
- #]
354
+ # ]
322
355
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
323
356
# `add_stylesheet` (deprecated in 1.8).
324
- #add_css = getattr(app, 'add_css_file', app.add_stylesheet)
325
- #for css_file in html_css_files:
357
+ # add_css = getattr(app, 'add_css_file', app.add_stylesheet)
358
+ # for css_file in html_css_files:
326
359
# add_css(css_file)
327
360
# Custom CSS
328
- #app.add_stylesheet('css/pytorch_theme.css')
361
+ # app.add_stylesheet('css/pytorch_theme.css')
329
362
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')
330
363
# Custom directives
331
- app .add_directive (' includenodoc' , IncludeDirective )
332
- app .add_directive (' galleryitem' , GalleryItemDirective )
333
- app .add_directive (' customgalleryitem' , CustomGalleryItemDirective )
334
- app .add_directive (' customcarditem' , CustomCardItemDirective )
335
- app .add_directive (' customcalloutitem' , CustomCalloutItemDirective )
364
+ app .add_directive (" includenodoc" , IncludeDirective )
365
+ app .add_directive (" galleryitem" , GalleryItemDirective )
366
+ app .add_directive (" customgalleryitem" , CustomGalleryItemDirective )
367
+ app .add_directive (" customcarditem" , CustomCardItemDirective )
368
+ app .add_directive (" customcalloutitem" , CustomCalloutItemDirective )
0 commit comments