29
29
#
30
30
import os
31
31
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
36
37
import gc
37
38
import glob
38
39
import random
39
- import re
40
40
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
44
45
import pandocfilters
45
- import plotly .io as pio
46
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"
47
+ import plotly .io as pio
48
+ from pathlib import Path
49
+ pio .renderers .default = 'sphinx_gallery'
59
50
60
51
61
52
try :
62
53
import torchvision
63
54
except ImportError :
64
55
import warnings
65
-
66
56
warnings .warn ('unable to load "torchvision" package' )
67
57
import pytorch_sphinx_theme
68
58
69
- rst_epilog = """
59
+ rst_epilog = """
70
60
.. |edit| image:: /_static/pencil-16.png
71
61
:width: 16px
72
62
:height: 16px
79
69
# needs_sphinx = '1.0'
80
70
81
71
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'
85
75
}
86
76
87
77
# Add any Sphinx extension module names here, as strings. They can be
88
78
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
89
79
# ones.
90
80
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'
97
87
]
98
88
99
89
intersphinx_mapping = {
107
97
108
98
# -- Sphinx-gallery configuration --------------------------------------------
109
99
110
-
111
100
def reset_seeds (gallery_conf , fname ):
112
101
torch .cuda .empty_cache ()
113
102
torch .backends .cudnn .deterministic = True
114
103
torch .backends .cudnn .benchmark = False
115
104
torch ._dynamo .reset ()
116
105
torch .manual_seed (42 )
117
- torch .cuda .manual_seed_all (42 )
118
106
torch .set_default_device (None )
119
107
random .seed (10 )
120
108
numpy .random .seed (10 )
121
109
torch .set_grad_enabled (True )
122
- torch .set_default_dtype (torch .float32 )
123
- torch .set_default_tensor_type (torch .FloatTensor )
124
110
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" )
129
117
130
- gc .collect ()
131
118
119
+ gc .collect ()
132
120
133
121
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' ],
155
135
},
156
136
}
157
137
158
- html_baseurl = " https://pytorch.org/tutorials/" # needed for sphinx-sitemap
138
+ html_baseurl = ' https://pytorch.org/tutorials/' # needed for sphinx-sitemap
159
139
sitemap_locales = [None ]
160
140
sitemap_excludes = [
161
141
"search.html" ,
162
142
"genindex.html" ,
163
143
]
164
144
sitemap_url_scheme = "{link}"
165
145
166
- if os .getenv (" GALLERY_PATTERN" ):
146
+ if os .getenv (' GALLERY_PATTERN' ):
167
147
# GALLERY_PATTERN is to be used when you want to work on a single
168
148
# tutorial. Previously this was fed into filename_pattern, but
169
149
# if you do that, you still end up parsing all of the other Python
170
150
# files which takes a few seconds. This strategy is better, as
171
151
# ignore_pattern also skips parsing.
172
152
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
173
153
# 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')[^/]+$'
177
155
178
- for i in range (len (sphinx_gallery_conf [" examples_dirs" ])):
156
+ for i in range (len (sphinx_gallery_conf [' examples_dirs' ])):
179
157
gallery_dir = Path (sphinx_gallery_conf ["gallery_dirs" ][i ])
180
158
source_dir = Path (sphinx_gallery_conf ["examples_dirs" ][i ])
181
159
@@ -187,21 +165,21 @@ def reset_seeds(gallery_conf, fname):
187
165
distutils .file_util .copy_file (f , gallery_subdir_path , update = True )
188
166
189
167
# Add any paths that contain templates here, relative to this directory.
190
- templates_path = [" _templates" ]
168
+ templates_path = [' _templates' ]
191
169
192
170
# The suffix(es) of source filenames.
193
171
# You can specify multiple suffix as a list of string:
194
172
#
195
173
# source_suffix = ['.rst', '.md']
196
- source_suffix = " .rst"
174
+ source_suffix = ' .rst'
197
175
198
176
# The master toctree document.
199
- master_doc = " index"
177
+ master_doc = ' index'
200
178
201
179
# 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'
205
183
206
184
# The version info for the project you're documenting, acts as replacement for
207
185
# |version| and |release|, also used in various other places throughout the
@@ -217,22 +195,17 @@ def reset_seeds(gallery_conf, fname):
217
195
#
218
196
# This is also used if you do content translation via gettext catalogs.
219
197
# Usually you set "language" from the command line for these cases.
220
- language = "en"
198
+ language = 'en'
221
199
222
200
# List of patterns, relative to source directory, that match files and
223
201
# directories to ignore when looking for source files.
224
202
# 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' ]
233
206
234
207
# The name of the Pygments (syntax highlighting) style to use.
235
- pygments_style = " sphinx"
208
+ pygments_style = ' sphinx'
236
209
237
210
# If true, `todo` and `todoList` produce output, else they produce nothing.
238
211
todo_include_todos = False
@@ -260,7 +233,7 @@ def reset_seeds(gallery_conf, fname):
260
233
# # Add any paths that contain custom static files (such as style sheets) here,
261
234
# # relative to this directory. They are copied after the builtin static files,
262
235
# # so a file named "default.css" will overwrite the builtin "default.css".
263
- html_static_path = [" _static" ]
236
+ html_static_path = [' _static' ]
264
237
265
238
# # Custom sidebar templates, maps document names to template names.
266
239
# html_sidebars = {
@@ -269,23 +242,23 @@ def reset_seeds(gallery_conf, fname):
269
242
# }
270
243
271
244
272
- html_theme = " pytorch_sphinx_theme"
245
+ html_theme = ' pytorch_sphinx_theme'
273
246
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'
275
248
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' ,
282
255
}
283
256
284
257
285
258
# -- Options for HTMLHelp output ------------------------------------------
286
259
287
260
# Output file base name for HTML help builder.
288
- htmlhelp_basename = " PyTorchTutorialsdoc"
261
+ htmlhelp_basename = ' PyTorchTutorialsdoc'
289
262
290
263
291
264
# -- Options for LaTeX output ---------------------------------------------
@@ -294,12 +267,15 @@ def reset_seeds(gallery_conf, fname):
294
267
# The paper size ('letterpaper' or 'a4paper').
295
268
#
296
269
# 'papersize': 'letterpaper',
270
+
297
271
# The font size ('10pt', '11pt' or '12pt').
298
272
#
299
273
# 'pointsize': '10pt',
274
+
300
275
# Additional stuff for the LaTeX preamble.
301
276
#
302
277
# 'preamble': '',
278
+
303
279
# Latex figure (float) alignment
304
280
#
305
281
# 'figure_align': 'htbp',
@@ -309,21 +285,19 @@ def reset_seeds(gallery_conf, fname):
309
285
# (source start file, target name, title,
310
286
# author, documentclass [howto, manual, or own class]).
311
287
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' ),
319
290
]
320
291
321
292
322
293
# -- Options for manual page output ---------------------------------------
323
294
324
295
# One entry per manual page. List of tuples
325
296
# (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
+ ]
327
301
328
302
329
303
# -- Options for Texinfo output -------------------------------------------
@@ -332,47 +306,40 @@ def reset_seeds(gallery_conf, fname):
332
306
# (source start file, target name, title, author,
333
307
# dir menu entry, description, category)
334
308
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' ),
344
312
]
345
313
346
314
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
+ ]
351
319
352
320
html_js_files = [
353
321
"js/custom.js" ,
354
322
]
355
323
356
-
357
324
def setup (app ):
358
325
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
359
326
# and can be moved outside of this function (and the setup(app) function
360
327
# can be deleted).
361
- # html_css_files = [
328
+ #html_css_files = [
362
329
# 'https://cdn.jsdelivr.net/npm/[email protected] /dist/katex.min.css',
363
330
# 'css/custom.css'
364
- # ]
331
+ #]
365
332
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
366
333
# `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:
369
336
# add_css(css_file)
370
337
# Custom CSS
371
- # app.add_stylesheet('css/pytorch_theme.css')
338
+ #app.add_stylesheet('css/pytorch_theme.css')
372
339
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')
373
340
# 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