diff --git a/.ci/docker/requirements.txt b/.ci/docker/requirements.txt index 0e95c62c6b..e6802cb045 100644 --- a/.ci/docker/requirements.txt +++ b/.ci/docker/requirements.txt @@ -14,7 +14,7 @@ tqdm==4.66.1 numpy==1.24.4 matplotlib librosa -torch==2.6 +torch==2.7 torchvision torchdata networkx @@ -67,7 +67,7 @@ iopath pygame==2.6.0 pycocotools semilearn==0.3.2 -torchao==0.5.0 +torchao==0.10.0 segment_anything==1.0 torchrec==1.1.0; platform_system == "Linux" -fbgemm-gpu==1.1.0; platform_system == "Linux" +fbgemm-gpu==1.2.0; platform_system == "Linux" diff --git a/.jenkins/build.sh b/.jenkins/build.sh index 8786859d7d..87bf454568 100755 --- a/.jenkins/build.sh +++ b/.jenkins/build.sh @@ -23,11 +23,11 @@ sudo apt-get install -y pandoc # Nightly - pip install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html # Install 2.5 to merge all 2.4 PRs - uncomment to install nightly binaries (update the version as needed). # sudo pip uninstall -y torch torchvision torchaudio torchtext torchdata -# sudo pip3 install torch==2.6.0 torchvision --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu124 +# sudo pip3 install torch==2.7.0 torchvision --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu124 # sudo pip uninstall -y fbgemm-gpu torchrec # sudo pip3 install fbgemm-gpu==1.1.0 torchrec==1.0.0 --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu124 -sudo pip uninstall -y torch torchvision torchaudio torchtext torchdata torchrl tensordict -pip3 install torch==2.7.0 torchvision torchaudio --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu126 +# sudo pip uninstall -y torch torchvision torchaudio torchtext torchdata torchrl tensordict +# pip3 install torch==2.7.0 torchvision torchaudio --no-cache-dir --index-url https://download.pytorch.org/whl/test/cu126 #sudo pip uninstall -y fbgemm-gpu # Install two language tokenizers for Translation with TorchText tutorial python -m spacy download en_core_web_sm diff --git a/.jenkins/validate_tutorials_built.py b/.jenkins/validate_tutorials_built.py index 3ed1e0c028..6a54bf8c47 100644 --- a/.jenkins/validate_tutorials_built.py +++ b/.jenkins/validate_tutorials_built.py @@ -51,14 +51,8 @@ "intermediate_source/text_to_speech_with_torchaudio", "intermediate_source/tensorboard_profiler_tutorial", # reenable after 2.0 release. "advanced_source/semi_structured_sparse", # reenable after 3303 is fixed. - "intermediate_source/mario_rl_tutorial", # reenable after 3302 is fixed - "intermediate_source/reinforcement_ppo", # reenable after 3302 is fixed - "intermediate_source/pinmem_nonblock", # reenable after 3302 is fixed - "intermediate_source/dqn_with_rnn_tutorial", # reenable after 3302 is fixed - "advanced_source/pendulum", # reenable after 3302 is fixed - "advanced_source/coding_ddpg", # reenable after 3302 is fixed - "intermediate_source/torchrec_intro_tutorial", # reenable after 3302 is fixed - "recipes_source/recipes/reasoning_about_shapes" # reenable after 3326 is fixed + "recipes_source/recipes/reasoning_about_shapes", # reenable after 3326 is fixed + "intermediate_source/torchrec_intro_tutorial" # reenable after torchrec releases 1.2.0 ] def tutorial_source_dirs() -> List[Path]: diff --git a/conf.py b/conf.py index a12a05d21c..c775ddca6d 100644 --- a/conf.py +++ b/conf.py @@ -29,34 +29,44 @@ # import os import sys -sys.path.insert(0, os.path.abspath('.')) -sys.path.insert(0, os.path.abspath('./.jenkins')) -import pytorch_sphinx_theme -import torch -import numpy + +sys.path.insert(0, os.path.abspath(".")) +sys.path.insert(0, os.path.abspath("./.jenkins")) +import distutils.file_util import gc import glob import random -import shutil -from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective -import distutils.file_util import re -from get_sphinx_filenames import SPHINX_SHOULD_RUN +import shutil +from pathlib import Path + +import numpy import pandocfilters -import pypandoc import plotly.io as pio -from pathlib import Path -pio.renderers.default = 'sphinx_gallery' +import pypandoc +import pytorch_sphinx_theme +import torch +from custom_directives import ( + CustomCalloutItemDirective, + CustomCardItemDirective, + CustomGalleryItemDirective, + GalleryItemDirective, + IncludeDirective, +) +from get_sphinx_filenames import SPHINX_SHOULD_RUN + +pio.renderers.default = "sphinx_gallery" try: import torchvision except ImportError: import warnings + warnings.warn('unable to load "torchvision" package') import pytorch_sphinx_theme -rst_epilog =""" +rst_epilog = """ .. |edit| image:: /_static/pencil-16.png :width: 16px :height: 16px @@ -69,23 +79,24 @@ # needs_sphinx = '1.0' html_meta = { - 'description': 'Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!', - 'keywords': 'PyTorch, tutorials, Getting Started, deep learning, AI', - 'author': 'PyTorch Contributors' + "description": "Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!", + "keywords": "PyTorch, tutorials, Getting Started, deep learning, AI", + "author": "PyTorch Contributors", } # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinxcontrib.katex', - 'sphinx.ext.intersphinx', - 'sphinx_copybutton', - 'sphinx_gallery.gen_gallery', - 'sphinx_design', - 'sphinx_sitemap' + "sphinxcontrib.katex", + "sphinx.ext.intersphinx", + "sphinx_copybutton", + "sphinx_gallery.gen_gallery", + "sphinx_design", + "sphinx_sitemap", ] + intersphinx_mapping = { "torch": ("https://pytorch.org/docs/stable/", None), "tensordict": ("https://pytorch.github.io/tensordict/", None), @@ -97,32 +108,51 @@ # -- Sphinx-gallery configuration -------------------------------------------- + def reset_seeds(gallery_conf, fname): + global torch torch.cuda.empty_cache() + if torch.cuda.is_available(): + torch.cuda.reset_peak_memory_stats() torch.manual_seed(42) torch.set_default_device(None) random.seed(10) numpy.random.seed(10) gc.collect() + torch._dynamo.reset() + import torch._inductor + from torch._inductor.codecache import CppCodeCache, PyCodeCache + + PyCodeCache.cache_clear(purge=True) + CppCodeCache.cache_clear() + sphinx_gallery_conf = { - 'examples_dirs': ['beginner_source', 'intermediate_source', - 'advanced_source', 'recipes_source', 'prototype_source'], - 'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'], - 'filename_pattern': re.compile(SPHINX_SHOULD_RUN), - 'promote_jupyter_magic': True, - 'backreferences_dir': None, - 'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n" - "# https://pytorch.org/tutorials/beginner/colab\n" - "%matplotlib inline"), - 'reset_modules': (reset_seeds), - 'ignore_pattern': r'_torch_export_nightly_tutorial.py', - 'pypandoc': {'extra_args': ['--mathjax', '--toc'], - 'filters': ['.jenkins/custom_pandoc_filter.py'], + "examples_dirs": [ + "beginner_source", + "intermediate_source", + "advanced_source", + "recipes_source", + "prototype_source", + ], + "gallery_dirs": ["beginner", "intermediate", "advanced", "recipes", "prototype"], + "filename_pattern": re.compile(SPHINX_SHOULD_RUN), + "promote_jupyter_magic": True, + "backreferences_dir": None, + "first_notebook_cell": ( + "# For tips on running notebooks in Google Colab, see\n" + "# https://pytorch.org/tutorials/beginner/colab\n" + "%matplotlib inline" + ), + "reset_modules": (reset_seeds), + "ignore_pattern": r"_torch_export_nightly_tutorial.py", + "pypandoc": { + "extra_args": ["--mathjax", "--toc"], + "filters": [".jenkins/custom_pandoc_filter.py"], }, } -html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap +html_baseurl = "https://pytorch.org/tutorials/" # needed for sphinx-sitemap sitemap_locales = [None] sitemap_excludes = [ "search.html", @@ -130,7 +160,7 @@ def reset_seeds(gallery_conf, fname): ] sitemap_url_scheme = "{link}" -if os.getenv('GALLERY_PATTERN'): +if os.getenv("GALLERY_PATTERN"): # GALLERY_PATTERN is to be used when you want to work on a single # tutorial. Previously this was fed into filename_pattern, but # if you do that, you still end up parsing all of the other Python @@ -138,9 +168,11 @@ def reset_seeds(gallery_conf, fname): # ignore_pattern also skips parsing. # See https://github.com/sphinx-gallery/sphinx-gallery/issues/721 # for a more detailed description of the issue. - sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$' + sphinx_gallery_conf["ignore_pattern"] = ( + r"/(?!" + re.escape(os.getenv("GALLERY_PATTERN")) + r")[^/]+$" + ) -for i in range(len(sphinx_gallery_conf['examples_dirs'])): +for i in range(len(sphinx_gallery_conf["examples_dirs"])): gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i]) source_dir = Path(sphinx_gallery_conf["examples_dirs"][i]) @@ -152,21 +184,21 @@ def reset_seeds(gallery_conf, fname): distutils.file_util.copy_file(f, gallery_subdir_path, update=True) # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'PyTorch Tutorials' -copyright = '2024, PyTorch' -author = 'PyTorch contributors' +project = "PyTorch Tutorials" +copyright = "2024, PyTorch" +author = "PyTorch contributors" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -182,17 +214,22 @@ def reset_seeds(gallery_conf, fname): # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'en' +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*'] -exclude_patterns += sphinx_gallery_conf['examples_dirs'] -exclude_patterns += ['*/index.rst'] +exclude_patterns = [ + "_build", + "Thumbs.db", + ".DS_Store", + "src/pytorch-sphinx-theme/docs*", +] +exclude_patterns += sphinx_gallery_conf["examples_dirs"] +exclude_patterns += ["*/index.rst"] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -220,7 +257,7 @@ def reset_seeds(gallery_conf, fname): # # Add any paths that contain custom static files (such as style sheets) here, # # relative to this directory. They are copied after the builtin static files, # # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # # Custom sidebar templates, maps document names to template names. # html_sidebars = { @@ -229,23 +266,23 @@ def reset_seeds(gallery_conf, fname): # } -html_theme = 'pytorch_sphinx_theme' +html_theme = "pytorch_sphinx_theme" html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()] -html_logo = '_static/img/pytorch-logo-dark.svg' +html_logo = "_static/img/pytorch-logo-dark.svg" html_theme_options = { - 'pytorch_project': 'tutorials', - 'collapse_navigation': False, - 'display_version': True, - 'navigation_with_keys': True, - 'logo_only': False, - 'analytics_id': 'GTM-T8XT4PS', + "pytorch_project": "tutorials", + "collapse_navigation": False, + "display_version": True, + "navigation_with_keys": True, + "logo_only": False, + "analytics_id": "GTM-T8XT4PS", } # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. -htmlhelp_basename = 'PyTorchTutorialsdoc' +htmlhelp_basename = "PyTorchTutorialsdoc" # -- Options for LaTeX output --------------------------------------------- @@ -254,15 +291,12 @@ def reset_seeds(gallery_conf, fname): # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -272,8 +306,13 @@ def reset_seeds(gallery_conf, fname): # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials', - 'Sasank, PyTorch contributors', 'manual'), + ( + master_doc, + "PyTorchTutorials.tex", + "PyTorch Tutorials", + "Sasank, PyTorch contributors", + "manual", + ), ] @@ -281,10 +320,7 @@ def reset_seeds(gallery_conf, fname): # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [ - (master_doc, 'pytorchtutorials', 'PyTorch Tutorials', - [author], 1) -] +man_pages = [(master_doc, "pytorchtutorials", "PyTorch Tutorials", [author], 1)] # -- Options for Texinfo output ------------------------------------------- @@ -293,40 +329,47 @@ def reset_seeds(gallery_conf, fname): # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'PyTorchTutorials', 'PyTorch Tutorials', - author, 'PyTorchTutorials', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "PyTorchTutorials", + "PyTorch Tutorials", + author, + "PyTorchTutorials", + "One line description of project.", + "Miscellaneous", + ), ] html_css_files = [ - 'https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css', - 'css/custom.css', - 'css/custom2.css' - ] + "https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css", + "css/custom.css", + "css/custom2.css", +] html_js_files = [ "js/custom.js", ] + def setup(app): # NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value # and can be moved outside of this function (and the setup(app) function # can be deleted). - #html_css_files = [ + # html_css_files = [ # 'https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css', # 'css/custom.css' - #] + # ] # In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is # `add_stylesheet` (deprecated in 1.8). - #add_css = getattr(app, 'add_css_file', app.add_stylesheet) - #for css_file in html_css_files: + # add_css = getattr(app, 'add_css_file', app.add_stylesheet) + # for css_file in html_css_files: # add_css(css_file) # Custom CSS - #app.add_stylesheet('css/pytorch_theme.css') + # app.add_stylesheet('css/pytorch_theme.css') # app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato') # Custom directives - app.add_directive('includenodoc', IncludeDirective) - app.add_directive('galleryitem', GalleryItemDirective) - app.add_directive('customgalleryitem', CustomGalleryItemDirective) - app.add_directive('customcarditem', CustomCardItemDirective) - app.add_directive('customcalloutitem', CustomCalloutItemDirective) + app.add_directive("includenodoc", IncludeDirective) + app.add_directive("galleryitem", GalleryItemDirective) + app.add_directive("customgalleryitem", CustomGalleryItemDirective) + app.add_directive("customcarditem", CustomCardItemDirective) + app.add_directive("customcalloutitem", CustomCalloutItemDirective)