CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/main/conf.py
Views: 492
#!/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 pio47pio.renderers.default = 'sphinx_gallery'484950try:51import torchvision52except ImportError:53import warnings54warnings.warn('unable to load "torchvision" package')55import pytorch_sphinx_theme5657rst_epilog ="""58.. |edit| image:: /_static/pencil-16.png59:width: 16px60:height: 16px61"""6263# -- General configuration ------------------------------------------------6465# If your documentation needs a minimal Sphinx version, state it here.66#67# needs_sphinx = '1.0'6869html_meta = {70'description': 'Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!',71'keywords': 'PyTorch, tutorials, Getting Started, deep learning, AI',72'author': 'PyTorch Contributors'73}7475# Add any Sphinx extension module names here, as strings. They can be76# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom77# ones.78extensions = [79'sphinxcontrib.katex',80'sphinx.ext.intersphinx',81'sphinx_copybutton',82'sphinx_gallery.gen_gallery',83'sphinx_design',84'sphinx_sitemap'85]8687intersphinx_mapping = {88"torch": ("https://pytorch.org/docs/stable/", None),89"tensordict": ("https://pytorch.github.io/tensordict/", None),90"torchrl": ("https://pytorch.org/rl/", None),91"torchaudio": ("https://pytorch.org/audio/stable/", None),92"torchtext": ("https://pytorch.org/text/stable/", None),93"torchvision": ("https://pytorch.org/vision/stable/", None),94}9596# -- Sphinx-gallery configuration --------------------------------------------9798def reset_seeds(gallery_conf, fname):99torch.cuda.empty_cache()100torch.manual_seed(42)101torch.set_default_device(None)102random.seed(10)103numpy.random.seed(10)104gc.collect()105106sphinx_gallery_conf = {107'examples_dirs': ['beginner_source', 'intermediate_source',108'advanced_source', 'recipes_source', 'prototype_source'],109'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],110'filename_pattern': re.compile(SPHINX_SHOULD_RUN),111'promote_jupyter_magic': True,112'backreferences_dir': None,113'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"114"# https://pytorch.org/tutorials/beginner/colab\n"115"%matplotlib inline"),116'reset_modules': (reset_seeds),117'ignore_pattern': r'_torch_export_nightly_tutorial.py',118'pypandoc': {'extra_args': ['--mathjax', '--toc'],119'filters': ['.jenkins/custom_pandoc_filter.py'],120},121}122123html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap124sitemap_locales = [None]125sitemap_excludes = [126"search.html",127"genindex.html",128]129sitemap_url_scheme = "{link}"130131if os.getenv('GALLERY_PATTERN'):132# GALLERY_PATTERN is to be used when you want to work on a single133# tutorial. Previously this was fed into filename_pattern, but134# if you do that, you still end up parsing all of the other Python135# files which takes a few seconds. This strategy is better, as136# ignore_pattern also skips parsing.137# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721138# for a more detailed description of the issue.139sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'140141for i in range(len(sphinx_gallery_conf['examples_dirs'])):142gallery_dir = sphinx_gallery_conf['gallery_dirs'][i]143source_dir = sphinx_gallery_conf['examples_dirs'][i]144# Create gallery dirs if it doesn't exist145try:146os.mkdir(gallery_dir)147except OSError:148pass149150# Copy rst files from source dir to gallery dir151for f in glob.glob(os.path.join(source_dir, '*.rst')):152distutils.file_util.copy_file(f, gallery_dir, update=True)153154155# Add any paths that contain templates here, relative to this directory.156157158templates_path = ['_templates']159160# The suffix(es) of source filenames.161# You can specify multiple suffix as a list of string:162#163# source_suffix = ['.rst', '.md']164source_suffix = '.rst'165166# The master toctree document.167master_doc = 'index'168169# General information about the project.170project = 'PyTorch Tutorials'171copyright = '2024, PyTorch'172author = 'PyTorch contributors'173174# The version info for the project you're documenting, acts as replacement for175# |version| and |release|, also used in various other places throughout the176# built documents.177#178# The short X.Y version.179version = str(torch.__version__)180# The full version, including alpha/beta/rc tags.181release = str(torch.__version__)182183# The language for content autogenerated by Sphinx. Refer to documentation184# for a list of supported languages.185#186# This is also used if you do content translation via gettext catalogs.187# Usually you set "language" from the command line for these cases.188language = 'en'189190# List of patterns, relative to source directory, that match files and191# directories to ignore when looking for source files.192# This patterns also effect to html_static_path and html_extra_path193exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*']194exclude_patterns += sphinx_gallery_conf['examples_dirs']195exclude_patterns += ['*/index.rst']196197# The name of the Pygments (syntax highlighting) style to use.198pygments_style = 'sphinx'199200# If true, `todo` and `todoList` produce output, else they produce nothing.201todo_include_todos = False202203204# -- Options for HTML output ----------------------------------------------205206# The theme to use for HTML and HTML Help pages. See the documentation for207# a list of builtin themes.208#209# html_theme = 'alabaster'210211# # Theme options are theme-specific and customize the look and feel of a theme212# # further. For a list of options available for each theme, see the213# # documentation.214# #215216# html_theme_options = {217# 'page_width': '1000px',218# 'fixed_sidebar': True,219# 'code_font_size': '0.87em',220# 'sidebar_includehidden': True221# }222223# # Add any paths that contain custom static files (such as style sheets) here,224# # relative to this directory. They are copied after the builtin static files,225# # so a file named "default.css" will overwrite the builtin "default.css".226html_static_path = ['_static']227228# # Custom sidebar templates, maps document names to template names.229# html_sidebars = {230# 'index': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html'],231# '**': ['sidebarlogo.html', 'globaltoc.html', 'searchbox.html', 'sourcelink.html']232# }233234235html_theme = 'pytorch_sphinx_theme'236html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]237html_logo = '_static/img/pytorch-logo-dark.svg'238html_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',245}246247248# -- Options for HTMLHelp output ------------------------------------------249250# Output file base name for HTML help builder.251htmlhelp_basename = 'PyTorchTutorialsdoc'252253254# -- Options for LaTeX output ---------------------------------------------255256latex_elements = {257# The paper size ('letterpaper' or 'a4paper').258#259# 'papersize': 'letterpaper',260261# The font size ('10pt', '11pt' or '12pt').262#263# 'pointsize': '10pt',264265# Additional stuff for the LaTeX preamble.266#267# 'preamble': '',268269# Latex figure (float) alignment270#271# 'figure_align': 'htbp',272}273274# Grouping the document tree into LaTeX files. List of tuples275# (source start file, target name, title,276# author, documentclass [howto, manual, or own class]).277latex_documents = [278(master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials',279'Sasank, PyTorch contributors', 'manual'),280]281282283# -- Options for manual page output ---------------------------------------284285# One entry per manual page. List of tuples286# (source start file, name, description, authors, manual section).287man_pages = [288(master_doc, 'pytorchtutorials', 'PyTorch Tutorials',289[author], 1)290]291292293# -- Options for Texinfo output -------------------------------------------294295# Grouping the document tree into Texinfo files. List of tuples296# (source start file, target name, title, author,297# dir menu entry, description, category)298texinfo_documents = [299(master_doc, 'PyTorchTutorials', 'PyTorch Tutorials',300author, 'PyTorchTutorials', 'One line description of project.',301'Miscellaneous'),302]303304html_css_files = [305'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',306'css/custom.css',307'css/custom2.css'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