Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/main/conf.py
Views: 710
#!/usr/bin/env python31# -*- coding: utf-8 -*-2#3# PyTorch Tutorials documentation build configuration file, created by4# sphinx-quickstart on Wed Mar 8 22:38:10 2017.5#6# This file is execfile()d with the current directory set to its7# containing dir.8#9# Note that not all possible configuration values are present in this10# autogenerated file.11#12# All configuration values have a default; values that are commented out13# serve to show the default.14#1516# Because the sphinx gallery might take a long time, you can control specific17# files that generate the results using `GALLERY_PATTERN` environment variable,18# For example to run only `neural_style_transfer_tutorial.py`:19# GALLERY_PATTERN="neural_style_transfer_tutorial.py" make html20# or21# GALLERY_PATTERN="neural_style_transfer_tutorial.py" sphinx-build . _build22#23# GALLERY_PATTERN variable respects regular expressions.2425# If extensions (or modules to document with autodoc) are in another directory,26# add these directories to sys.path here. If the directory is relative to the27# documentation root, use os.path.abspath to make it absolute, like shown here.28#29import os30import sys31sys.path.insert(0, os.path.abspath('.'))32sys.path.insert(0, os.path.abspath('./.jenkins'))33import pytorch_sphinx_theme34import torch35import numpy36import gc37import glob38import random39import shutil40from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective41import distutils.file_util42import re43from get_sphinx_filenames import SPHINX_SHOULD_RUN44import pandocfilters45import pypandoc46import plotly.io as pio47from pathlib import Path48pio.renderers.default = 'sphinx_gallery'495051try:52import torchvision53except ImportError:54import warnings55warnings.warn('unable to load "torchvision" package')56import pytorch_sphinx_theme5758rst_epilog ="""59.. |edit| image:: /_static/pencil-16.png60:width: 16px61:height: 16px62"""6364# -- General configuration ------------------------------------------------6566# If your documentation needs a minimal Sphinx version, state it here.67#68# needs_sphinx = '1.0'6970html_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}7576# Add any Sphinx extension module names here, as strings. They can be77# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom78# ones.79extensions = [80'sphinxcontrib.katex',81'sphinx.ext.intersphinx',82'sphinx_copybutton',83'sphinx_gallery.gen_gallery',84'sphinx_design',85'sphinx_sitemap'86]8788intersphinx_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}9697# -- Sphinx-gallery configuration --------------------------------------------9899def reset_seeds(gallery_conf, fname):100torch.cuda.empty_cache()101torch.manual_seed(42)102torch.set_default_device(None)103random.seed(10)104numpy.random.seed(10)105gc.collect()106107sphinx_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}123124html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap125sitemap_locales = [None]126sitemap_excludes = [127"search.html",128"genindex.html",129]130sitemap_url_scheme = "{link}"131132if os.getenv('GALLERY_PATTERN'):133# GALLERY_PATTERN is to be used when you want to work on a single134# tutorial. Previously this was fed into filename_pattern, but135# if you do that, you still end up parsing all of the other Python136# files which takes a few seconds. This strategy is better, as137# ignore_pattern also skips parsing.138# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721139# for a more detailed description of the issue.140sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'141142for i in range(len(sphinx_gallery_conf['examples_dirs'])):143gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i])144source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])145146# Copy rst files from source dir to gallery dir147for f in source_dir.rglob("*.rst"):148f_dir = Path(f).parent149gallery_subdir_path = gallery_dir / f_dir.relative_to(source_dir)150gallery_subdir_path.mkdir(parents=True, exist_ok=True)151distutils.file_util.copy_file(f, gallery_subdir_path, update=True)152153# Add any paths that contain templates here, relative to this directory.154templates_path = ['_templates']155156# The suffix(es) of source filenames.157# You can specify multiple suffix as a list of string:158#159# source_suffix = ['.rst', '.md']160source_suffix = '.rst'161162# The master toctree document.163master_doc = 'index'164165# General information about the project.166project = 'PyTorch Tutorials'167copyright = '2024, PyTorch'168author = 'PyTorch contributors'169170# The version info for the project you're documenting, acts as replacement for171# |version| and |release|, also used in various other places throughout the172# built documents.173#174# The short X.Y version.175version = str(torch.__version__)176# The full version, including alpha/beta/rc tags.177release = str(torch.__version__)178179# The language for content autogenerated by Sphinx. Refer to documentation180# for a list of supported languages.181#182# This is also used if you do content translation via gettext catalogs.183# Usually you set "language" from the command line for these cases.184language = 'en'185186# List of patterns, relative to source directory, that match files and187# directories to ignore when looking for source files.188# This patterns also effect to html_static_path and html_extra_path189exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*']190exclude_patterns += sphinx_gallery_conf['examples_dirs']191exclude_patterns += ['*/index.rst']192193# The name of the Pygments (syntax highlighting) style to use.194pygments_style = 'sphinx'195196# If true, `todo` and `todoList` produce output, else they produce nothing.197todo_include_todos = False198199200# -- Options for HTML output ----------------------------------------------201202# The theme to use for HTML and HTML Help pages. See the documentation for203# a list of builtin themes.204#205# html_theme = 'alabaster'206207# # Theme options are theme-specific and customize the look and feel of a theme208# # further. For a list of options available for each theme, see the209# # documentation.210# #211212# html_theme_options = {213# 'page_width': '1000px',214# 'fixed_sidebar': True,215# 'code_font_size': '0.87em',216# 'sidebar_includehidden': True217# }218219# # Add any paths that contain custom static files (such as style sheets) here,220# # relative to this directory. They are copied after the builtin static files,221# # so a file named "default.css" will overwrite the builtin "default.css".222html_static_path = ['_static']223224# # Custom sidebar templates, maps document names to template names.225# html_sidebars = {226# 'index': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html'],227# '**': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html']228# }229230231html_theme = 'pytorch_sphinx_theme'232html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]233html_logo = '_static/img/pytorch-logo-dark.svg'234html_theme_options = {235'pytorch_project': 'tutorials',236'collapse_navigation': False,237'display_version': True,238'navigation_with_keys': True,239'logo_only': False,240'analytics_id': 'GTM-T8XT4PS',241}242243244# -- Options for HTMLHelp output ------------------------------------------245246# Output file base name for HTML help builder.247htmlhelp_basename = 'PyTorchTutorialsdoc'248249250# -- Options for LaTeX output ---------------------------------------------251252latex_elements = {253# The paper size ('letterpaper' or 'a4paper').254#255# 'papersize': 'letterpaper',256257# The font size ('10pt', '11pt' or '12pt').258#259# 'pointsize': '10pt',260261# Additional stuff for the LaTeX preamble.262#263# 'preamble': '',264265# Latex figure (float) alignment266#267# 'figure_align': 'htbp',268}269270# Grouping the document tree into LaTeX files. List of tuples271# (source start file, target name, title,272# author, documentclass [howto, manual, or own class]).273latex_documents = [274(master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials',275'Sasank, PyTorch contributors', 'manual'),276]277278279# -- Options for manual page output ---------------------------------------280281# One entry per manual page. List of tuples282# (source start file, name, description, authors, manual section).283man_pages = [284(master_doc, 'pytorchtutorials', 'PyTorch Tutorials',285[author], 1)286]287288289# -- Options for Texinfo output -------------------------------------------290291# Grouping the document tree into Texinfo files. List of tuples292# (source start file, target name, title, author,293# dir menu entry, description, category)294texinfo_documents = [295(master_doc, 'PyTorchTutorials', 'PyTorch Tutorials',296author, 'PyTorchTutorials', 'One line description of project.',297'Miscellaneous'),298]299300html_css_files = [301'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',302'css/custom.css',303'css/custom2.css'304]305306html_js_files = [307"js/custom.js",308]309310def setup(app):311# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value312# and can be moved outside of this function (and the setup(app) function313# can be deleted).314#html_css_files = [315# 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',316# 'css/custom.css'317#]318# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is319# `add_stylesheet` (deprecated in 1.8).320#add_css = getattr(app, 'add_css_file', app.add_stylesheet)321#for css_file in html_css_files:322# add_css(css_file)323# Custom CSS324#app.add_stylesheet('css/pytorch_theme.css')325# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')326# Custom directives327app.add_directive('includenodoc', IncludeDirective)328app.add_directive('galleryitem', GalleryItemDirective)329app.add_directive('customgalleryitem', CustomGalleryItemDirective)330app.add_directive('customcarditem', CustomCardItemDirective)331app.add_directive('customcalloutitem', CustomCalloutItemDirective)332333334