From fb9be239f4baccfa240d495918747fdbe010124e Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Thu, 20 Mar 2025 14:58:29 -0700 Subject: [PATCH 01/24] Add new theme --- .ci/docker/requirements.txt | 7 ++- conf.py | 88 ++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/.ci/docker/requirements.txt b/.ci/docker/requirements.txt index 89dd788ae70..32f5e2709b3 100644 --- a/.ci/docker/requirements.txt +++ b/.ci/docker/requirements.txt @@ -1,7 +1,7 @@ # --extra-index-url https://download.pytorch.org/whl/cu117/index.html # Use this to run/publish tutorials against the latest binaries during the RC stage. Comment out after the release. Each release verify the correct cuda version. # Refer to ./jenkins/build.sh for tutorial build instructions -sphinx==5.0.0 +sphinx==5.3.0 sphinx-gallery==0.11.1 sphinx_design docutils==0.16 @@ -40,12 +40,11 @@ onnxscript onnxruntime evaluate accelerate>=0.20.1 - +sphinxcontrib-mermaid==1.0.0 importlib-metadata==6.8.0 # PyTorch Theme --e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme - +-e git+https://github.com/pytorch/pytorch_sphinx_theme.git@pytorch_sphinx_theme2#egg=pytorch_sphinx_theme2 ipython sphinxcontrib.katex diff --git a/conf.py b/conf.py index a12a05d21c2..b5b997fae2e 100644 --- a/conf.py +++ b/conf.py @@ -31,7 +31,10 @@ import sys sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('./.jenkins')) -import pytorch_sphinx_theme +import pytorch_sphinx_theme2 + +html_theme = "pytorch_sphinx_theme2" +html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()] import torch import numpy import gc @@ -84,6 +87,14 @@ 'sphinx_gallery.gen_gallery', 'sphinx_design', 'sphinx_sitemap' + 'sphinxcontrib.mermaid', + 'myst_parser' +] + +myst_enable_extensions = [ + "colon_fence", + "deflist", + "html_image", ] intersphinx_mapping = { @@ -130,6 +141,81 @@ def reset_seeds(gallery_conf, fname): ] sitemap_url_scheme = "{link}" +html_theme_options = { + "navigation_with_keys": False, + "analytics_id": "GTM-T8XT4PS", + "pytorch_project": "tutorials", + "logo": { + "text": "Home", + }, + "language_bindings_links": [ + { + "url": "https://pytorch.org/docs/stable/cpp_index.html", + "name": "C++", + }, + { + "url": "https://pytorch.org/javadoc/", + "name": "Javadoc", + }, + { + "url": "https://github.com/pytorch/multipy", + "name": "torch.multiply", + }, + ], + "external_links": [ + { + "name": "Tutorials", + "url": "https://pytorch.org/tutorials/", + }, + ], + "icon_links": [ + { + "name": "X", + "url": "https://x.com/PyTorch", + "icon": "fa-brands fa-x-twitter", + }, + { + "name": "GitHub", + "url": "https://github.com/pytorch/pytorch", + "icon": "fa-brands fa-github", + }, + { + "name": "Discourse", + "url": "https://dev-discuss.pytorch.org/", + "icon": "fa-brands fa-discourse", + }, + { + "name": "PyPi", + "url": "https://pypi.org/project/torch/", + "icon": "fa-brands fa-python", + }, + ], + "use_edit_page_button": True, + "logo": { + "text": "Home", + }, +} + +theme_variables = pytorch_sphinx_theme2.get_theme_variables() + +html_context = { + "theme_variables": theme_variables, + "display_github": True, + "github_url": "https://github.com", + "github_user": "pytorch", + "github_repo": "pytorch", + "feedback_url": "https://github.com/pytorch/tutorials", + "github_version": "main", + "doc_path": "docs/source", + "library_links": theme_variables.get("library_links", []), + "icon_links": theme_variables.get("icon_links", []), + "community_links": theme_variables.get("community_links", []), + "pytorch_project": "docs", + "language_bindings_links": html_theme_options.get("language_bindings_links", []), +} + + + 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 From 28caa7cab96878fe9ed56345170b198732230b14 Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Fri, 21 Mar 2025 08:29:52 -0700 Subject: [PATCH 02/24] Add new theme --- _templates/layout.html | 224 ---------------------- conf.py | 2 +- sg_execution_times.rst | 421 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 422 insertions(+), 225 deletions(-) delete mode 100644 _templates/layout.html create mode 100644 sg_execution_times.rst diff --git a/_templates/layout.html b/_templates/layout.html deleted file mode 100644 index d6946eab087..00000000000 --- a/_templates/layout.html +++ /dev/null @@ -1,224 +0,0 @@ -{% extends "!layout.html" %} - - -{% block menu %} - {% if 'singlehtml' not in builder %} - {% set global_toc = toctree(collapse=theme_collapse_navigation|tobool, - includehidden=theme_includehidden|tobool, - titles_only=True) %} - {% endif %} - {% if global_toc %} - {{ global_toc }} - {% else %} - -
{{ toc }}
- {% endif %} -{% endblock %} - - - -{%- block content %} -{{ super() }} - -{%- endblock %} - -{% block sidebartitle %} - - {% if theme_display_version %} - {%- set nav_version = version %} - {% if READTHEDOCS and current_version %} - {%- set nav_version = current_version %} - {% endif %} - {% if nav_version %} -
- {{ nav_version }} -
- {% endif %} - {% endif %} - - - -
- - -
- - -{% endblock %} - -{% block footer %} -{{ super() }} - - - - - - - - -//temporarily add a link to survey - - -{% endblock %} diff --git a/conf.py b/conf.py index b5b997fae2e..ee04e9a7e85 100644 --- a/conf.py +++ b/conf.py @@ -86,7 +86,7 @@ 'sphinx_copybutton', 'sphinx_gallery.gen_gallery', 'sphinx_design', - 'sphinx_sitemap' + 'sphinx_sitemap', 'sphinxcontrib.mermaid', 'myst_parser' ] diff --git a/sg_execution_times.rst b/sg_execution_times.rst new file mode 100644 index 00000000000..08aef2dc3e9 --- /dev/null +++ b/sg_execution_times.rst @@ -0,0 +1,421 @@ + +:orphan: + +.. _sphx_glr_sg_execution_times: + + +Computation times +================= +**00:00.000** total execution time for 129 files **from all galleries**: + +.. container:: + + .. raw:: html + + + + + + + + .. list-table:: + :header-rows: 1 + :class: table table-striped sg-datatable + + * - Example + - Time + - Mem (MB) + * - :ref:`sphx_glr_advanced_coding_ddpg.py` (``advanced_source/coding_ddpg.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_dynamic_quantization_tutorial.py` (``advanced_source/dynamic_quantization_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_neural_style_tutorial.py` (``advanced_source/neural_style_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_numpy_extensions_tutorial.py` (``advanced_source/numpy_extensions_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_pendulum.py` (``advanced_source/pendulum.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_python_custom_ops.py` (``advanced_source/python_custom_ops.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_semi_structured_sparse.py` (``advanced_source/semi_structured_sparse.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_super_resolution_with_onnxruntime.py` (``advanced_source/super_resolution_with_onnxruntime.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_advanced_usb_semisup_learn.py` (``advanced_source/usb_semisup_learn.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_Intro_to_TorchScript_tutorial.py` (``beginner_source/Intro_to_TorchScript_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_autogradqs_tutorial.py` (``beginner_source/basics/autogradqs_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_buildmodel_tutorial.py` (``beginner_source/basics/buildmodel_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_data_tutorial.py` (``beginner_source/basics/data_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_intro.py` (``beginner_source/basics/intro.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_optimization_tutorial.py` (``beginner_source/basics/optimization_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_quickstart_tutorial.py` (``beginner_source/basics/quickstart_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_saveloadrun_tutorial.py` (``beginner_source/basics/saveloadrun_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_tensorqs_tutorial.py` (``beginner_source/basics/tensorqs_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_basics_transforms_tutorial.py` (``beginner_source/basics/transforms_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_blitz_autograd_tutorial.py` (``beginner_source/blitz/autograd_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_blitz_cifar10_tutorial.py` (``beginner_source/blitz/cifar10_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_blitz_data_parallel_tutorial.py` (``beginner_source/blitz/data_parallel_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_blitz_neural_networks_tutorial.py` (``beginner_source/blitz/neural_networks_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_blitz_tensor_tutorial.py` (``beginner_source/blitz/tensor_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_chatbot_tutorial.py` (``beginner_source/chatbot_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_data_loading_tutorial.py` (``beginner_source/data_loading_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_dcgan_faces_tutorial.py` (``beginner_source/dcgan_faces_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_deploy_seq2seq_hybrid_frontend_tutorial.py` (``beginner_source/deploy_seq2seq_hybrid_frontend_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_autograd_polynomial_autograd.py` (``beginner_source/examples_autograd/polynomial_autograd.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_autograd_polynomial_custom_function.py` (``beginner_source/examples_autograd/polynomial_custom_function.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_nn_dynamic_net.py` (``beginner_source/examples_nn/dynamic_net.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_nn_polynomial_module.py` (``beginner_source/examples_nn/polynomial_module.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_nn_polynomial_nn.py` (``beginner_source/examples_nn/polynomial_nn.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_nn_polynomial_optim.py` (``beginner_source/examples_nn/polynomial_optim.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_tensor_polynomial_numpy.py` (``beginner_source/examples_tensor/polynomial_numpy.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_examples_tensor_polynomial_tensor.py` (``beginner_source/examples_tensor/polynomial_tensor.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_fgsm_tutorial.py` (``beginner_source/fgsm_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_flava_finetuning_tutorial.py` (``beginner_source/flava_finetuning_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_hybrid_frontend_learning_hybrid_frontend_through_example_tutorial.py` (``beginner_source/hybrid_frontend/learning_hybrid_frontend_through_example_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_hyperparameter_tuning_tutorial.py` (``beginner_source/hyperparameter_tuning_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_autogradyt_tutorial.py` (``beginner_source/introyt/autogradyt_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_captumyt.py` (``beginner_source/introyt/captumyt.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_introyt1_tutorial.py` (``beginner_source/introyt/introyt1_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_introyt_index.py` (``beginner_source/introyt/introyt_index.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_modelsyt_tutorial.py` (``beginner_source/introyt/modelsyt_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_tensorboardyt_tutorial.py` (``beginner_source/introyt/tensorboardyt_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_tensors_deeper_tutorial.py` (``beginner_source/introyt/tensors_deeper_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_introyt_trainingyt.py` (``beginner_source/introyt/trainingyt.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_knowledge_distillation_tutorial.py` (``beginner_source/knowledge_distillation_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_nlp_advanced_tutorial.py` (``beginner_source/nlp/advanced_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_nlp_deep_learning_tutorial.py` (``beginner_source/nlp/deep_learning_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_nlp_pytorch_tutorial.py` (``beginner_source/nlp/pytorch_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_nlp_sequence_models_tutorial.py` (``beginner_source/nlp/sequence_models_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_nlp_word_embeddings_tutorial.py` (``beginner_source/nlp/word_embeddings_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_nn_tutorial.py` (``beginner_source/nn_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_onnx_export_control_flow_model_to_onnx_tutorial.py` (``beginner_source/onnx/export_control_flow_model_to_onnx_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_onnx_export_simple_model_to_onnx_tutorial.py` (``beginner_source/onnx/export_simple_model_to_onnx_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_onnx_intro_onnx.py` (``beginner_source/onnx/intro_onnx.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_onnx_onnx_registry_tutorial.py` (``beginner_source/onnx/onnx_registry_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_profiler.py` (``beginner_source/profiler.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_saving_loading_models.py` (``beginner_source/saving_loading_models.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_template_tutorial.py` (``beginner_source/template_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_transfer_learning_tutorial.py` (``beginner_source/transfer_learning_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_beginner_vt_tutorial.py` (``beginner_source/vt_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_autograd_saved_tensors_hooks_tutorial.py` (``intermediate_source/autograd_saved_tensors_hooks_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_ax_multiobjective_nas_tutorial.py` (``intermediate_source/ax_multiobjective_nas_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_char_rnn_classification_tutorial.py` (``intermediate_source/char_rnn_classification_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_char_rnn_generation_tutorial.py` (``intermediate_source/char_rnn_generation_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_custom_function_conv_bn_tutorial.py` (``intermediate_source/custom_function_conv_bn_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_dqn_with_rnn_tutorial.py` (``intermediate_source/dqn_with_rnn_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_ensembling.py` (``intermediate_source/ensembling.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_flask_rest_api_tutorial.py` (``intermediate_source/flask_rest_api_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_forward_ad_usage.py` (``intermediate_source/forward_ad_usage.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_fx_conv_bn_fuser.py` (``intermediate_source/fx_conv_bn_fuser.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_fx_profiling_tutorial.py` (``intermediate_source/fx_profiling_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_inductor_debug_cpu.py` (``intermediate_source/inductor_debug_cpu.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_jacobians_hessians.py` (``intermediate_source/jacobians_hessians.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_mario_rl_tutorial.py` (``intermediate_source/mario_rl_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_memory_format_tutorial.py` (``intermediate_source/memory_format_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_mnist_train_nas.py` (``intermediate_source/mnist_train_nas.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_neural_tangent_kernels.py` (``intermediate_source/neural_tangent_kernels.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_optimizer_step_in_backward_tutorial.py` (``intermediate_source/optimizer_step_in_backward_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_parametrizations.py` (``intermediate_source/parametrizations.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_per_sample_grads.py` (``intermediate_source/per_sample_grads.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_pinmem_nonblock.py` (``intermediate_source/pinmem_nonblock.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_pruning_tutorial.py` (``intermediate_source/pruning_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_reinforcement_ppo.py` (``intermediate_source/reinforcement_ppo.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_reinforcement_q_learning.py` (``intermediate_source/reinforcement_q_learning.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_scaled_dot_product_attention_tutorial.py` (``intermediate_source/scaled_dot_product_attention_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_seq2seq_translation_tutorial.py` (``intermediate_source/seq2seq_translation_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_spatial_transformer_tutorial.py` (``intermediate_source/spatial_transformer_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_tensorboard_profiler_tutorial.py` (``intermediate_source/tensorboard_profiler_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_torch_compile_tutorial.py` (``intermediate_source/torch_compile_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_torch_export_tutorial.py` (``intermediate_source/torch_export_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_torchrec_intro_tutorial.py` (``intermediate_source/torchrec_intro_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_torchvision_tutorial.py` (``intermediate_source/torchvision_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_intermediate_transformer_building_blocks.py` (``intermediate_source/transformer_building_blocks.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_fx_graph_mode_ptq_dynamic.py` (``prototype_source/fx_graph_mode_ptq_dynamic.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_gpu_quantization_torchao_tutorial.py` (``prototype_source/gpu_quantization_torchao_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_maskedtensor_adagrad.py` (``prototype_source/maskedtensor_adagrad.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_maskedtensor_advanced_semantics.py` (``prototype_source/maskedtensor_advanced_semantics.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_maskedtensor_overview.py` (``prototype_source/maskedtensor_overview.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_maskedtensor_sparsity.py` (``prototype_source/maskedtensor_sparsity.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_nestedtensor.py` (``prototype_source/nestedtensor.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_numeric_suite_tutorial.py` (``prototype_source/numeric_suite_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_torchscript_freezing.py` (``prototype_source/torchscript_freezing.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_prototype_vmap_recipe.py` (``prototype_source/vmap_recipe.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_compiling_optimizer_lr_scheduler.py` (``recipes_source/compiling_optimizer_lr_scheduler.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_Captum_Recipe.py` (``recipes_source/recipes/Captum_Recipe.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_amp_recipe.py` (``recipes_source/recipes/amp_recipe.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_benchmark.py` (``recipes_source/recipes/benchmark.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_changing_default_device.py` (``recipes_source/recipes/changing_default_device.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_defining_a_neural_network.py` (``recipes_source/recipes/defining_a_neural_network.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_dynamic_quantization.py` (``recipes_source/recipes/dynamic_quantization.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_module_load_state_dict_tips.py` (``recipes_source/recipes/module_load_state_dict_tips.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_profiler_recipe.py` (``recipes_source/recipes/profiler_recipe.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_reasoning_about_shapes.py` (``recipes_source/recipes/reasoning_about_shapes.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_swap_tensors.py` (``recipes_source/recipes/swap_tensors.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_tensorboard_with_pytorch.py` (``recipes_source/recipes/tensorboard_with_pytorch.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_timer_quick_start.py` (``recipes_source/recipes/timer_quick_start.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_tuning_guide.py` (``recipes_source/recipes/tuning_guide.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_warmstarting_model_using_parameters_from_a_different_model.py` (``recipes_source/recipes/warmstarting_model_using_parameters_from_a_different_model.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_what_is_state_dict.py` (``recipes_source/recipes/what_is_state_dict.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_recipes_zeroing_out_gradients.py` (``recipes_source/recipes/zeroing_out_gradients.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_regional_compilation.py` (``recipes_source/regional_compilation.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_torch_compile_user_defined_triton_kernel_tutorial.py` (``recipes_source/torch_compile_user_defined_triton_kernel_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_torch_compiler_set_stance_tutorial.py` (``recipes_source/torch_compiler_set_stance_tutorial.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_torch_export_aoti_python.py` (``recipes_source/torch_export_aoti_python.py``) + - 00:00.000 + - 0.0 + * - :ref:`sphx_glr_recipes_torch_logs.py` (``recipes_source/torch_logs.py``) + - 00:00.000 + - 0.0 From b790ea58a347cbf41feeee0cf05f34e3af8ec92c Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Tue, 25 Mar 2025 19:44:21 -0700 Subject: [PATCH 03/24] Update --- .jenkins/insert_last_verified.py | 13 +- _static/js/custom.js | 52 ------- beginner_source/index.rst | 40 +++++ conf.py | 260 +++++++++++++++---------------- domains.rst | 61 ++++++++ index.rst | 212 +------------------------ performance.rst | 119 ++++++++++++++ 7 files changed, 363 insertions(+), 394 deletions(-) delete mode 100644 _static/js/custom.js create mode 100644 beginner_source/index.rst create mode 100644 domains.rst create mode 100644 performance.rst diff --git a/.jenkins/insert_last_verified.py b/.jenkins/insert_last_verified.py index b43ef8de8e8..c612d696952 100644 --- a/.jenkins/insert_last_verified.py +++ b/.jenkins/insert_last_verified.py @@ -6,7 +6,6 @@ from bs4 import BeautifulSoup - json_file_path = "tutorials-review-data.json" # paths to skip from the post-processing script @@ -31,6 +30,7 @@ "": "", # root dir for index.rst } + def get_git_log_date(file_path, git_log_args): try: result = subprocess.run( @@ -46,13 +46,17 @@ def get_git_log_date(file_path, git_log_args): pass raise ValueError(f"Could not find date for {file_path}") + def get_creation_date(file_path): - return get_git_log_date(file_path, ["--diff-filter=A", "--format=%aD"]).strftime("%b %d, %Y") + return get_git_log_date(file_path, ["--diff-filter=A", "--format=%aD"]).strftime( + "%b %d, %Y" + ) def get_last_updated_date(file_path): return get_git_log_date(file_path, ["-1", "--format=%aD"]).strftime("%b %d, %Y") + # Try to find the source file with the given base path and the extensions .rst and .py def find_source_file(base_path): for ext in [".rst", ".py"]: @@ -63,7 +67,7 @@ def find_source_file(base_path): # Function to process a JSON file and insert the "Last Verified" information into the HTML files -def process_json_file(build_dir , json_file_path): +def process_json_file(build_dir, json_file_path): with open(json_file_path, "r", encoding="utf-8") as json_file: json_data = json.load(json_file) @@ -148,7 +152,7 @@ def main(): exit(1) build_dir = sys.argv[1] print(f"Build directory: {build_dir}") - process_json_file(build_dir , json_file_path) + process_json_file(build_dir, json_file_path) print( "Finished processing JSON file. Please check the output for any warnings. " "Pages like `nlp/index.html` are generated only during the full `make docs` " @@ -156,5 +160,6 @@ def main(): "can be ignored." ) + if __name__ == "__main__": main() diff --git a/_static/js/custom.js b/_static/js/custom.js deleted file mode 100644 index 3e6c7fb8312..00000000000 --- a/_static/js/custom.js +++ /dev/null @@ -1,52 +0,0 @@ -document.addEventListener("DOMContentLoaded", function() { - // Select all
  • elements with the class "toctree-l1" - var toctreeItems = document.querySelectorAll('li.toctree-l1'); - - toctreeItems.forEach(function(item) { - // Find the link within the item - var link = item.querySelector('a'); - var nestedList = item.querySelector('ul'); - - if (link && nestedList) { - // Create a span element for the "[+]" or "[-]" sign - var expandSign = document.createElement('span'); - expandSign.style.cursor = 'pointer'; // Make it look clickable - - // Use the link text as a unique key for localStorage - var sectionKey = 'section_' + link.textContent.trim().replace(/\s+/g, '_'); - - // Retrieve the saved state from localStorage - var isExpanded = localStorage.getItem(sectionKey); - - // If no state is saved, default to expanded for "Learn the Basics" and collapsed for others - if (isExpanded === null) { - isExpanded = (link.textContent.trim() === 'Learn the Basics') ? 'true' : 'false'; - localStorage.setItem(sectionKey, isExpanded); - } - - if (isExpanded === 'true') { - nestedList.style.display = 'block'; // Expand the section - expandSign.textContent = '[-] '; // Show "[-]" since it's expanded - } else { - nestedList.style.display = 'none'; // Collapse the section - expandSign.textContent = '[+] '; // Show "[+]" since it's collapsed - } - - // Add a click event to toggle the nested list - expandSign.addEventListener('click', function() { - if (nestedList.style.display === 'none') { - nestedList.style.display = 'block'; - expandSign.textContent = '[-] '; // Change to "[-]" when expanded - localStorage.setItem(sectionKey, 'true'); // Save state - } else { - nestedList.style.display = 'none'; - expandSign.textContent = '[+] '; // Change back to "[+]" when collapsed - localStorage.setItem(sectionKey, 'false'); // Save state - } - }); - - // Insert the sign before the link - link.parentNode.insertBefore(expandSign, link); - } - }); -}); diff --git a/beginner_source/index.rst b/beginner_source/index.rst new file mode 100644 index 00000000000..7691082f24f --- /dev/null +++ b/beginner_source/index.rst @@ -0,0 +1,40 @@ +:orphan: + +Intro +===== + +This is a collection of beginner-friendly resources to help you get +started with PyTorch. These tutorials cover fundamental concepts, +basic operations, and essential workflows to build a solid foundation +for your deep learning journey. Perfect for newcomers looking to +understand PyTorch's core functionality through step-by-step guidance. + +.. toctree:: + :maxdepth: 1 + :hidden: + :includehidden: + :caption: Learn the Basics + + beginner/basics/intro + + +.. toctree:: + :maxdepth: 1 + :hidden: + :includehidden: + :caption: Introduction to PyTorch - YouTube Series + + beginner/introyt/introyt_index + +.. toctree:: + :maxdepth: 1 + :hidden: + :includehidden: + :caption: Learning PyTorch + + beginner/deep_learning_60min_blitz + beginner/pytorch_with_examples + beginner/nn_tutorial + intermediate/nlp_from_scratch_index + intermediate/tensorboard_tutorial + intermediate/pinmem_nonblock diff --git a/conf.py b/conf.py index ee04e9a7e85..56f7ab54732 100644 --- a/conf.py +++ b/conf.py @@ -14,7 +14,7 @@ # serve to show the default. # -# Because the sphinx gallery might take a long time, you can control specific +# Bxcause the sphinx gallery might take a long time, you can control specific # files that generate the results using `GALLERY_PATTERN` environment variable, # For example to run only `neural_style_transfer_tutorial.py`: # GALLERY_PATTERN="neural_style_transfer_tutorial.py" make html @@ -29,37 +29,46 @@ # import os import sys -sys.path.insert(0, os.path.abspath('.')) -sys.path.insert(0, os.path.abspath('./.jenkins')) + +sys.path.insert(0, os.path.abspath(".")) +sys.path.insert(0, os.path.abspath("./.jenkins")) import pytorch_sphinx_theme2 html_theme = "pytorch_sphinx_theme2" html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()] -import torch -import numpy +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 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 @@ -72,23 +81,22 @@ # 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.mermaid', - 'myst_parser' + "sphinxcontrib.katex", + "sphinx.ext.intersphinx", + "sphinx_copybutton", + "sphinx_gallery.gen_gallery", + "sphinx_design", + "sphinx_sitemap", + "sphinxcontrib.mermaid", ] myst_enable_extensions = [ @@ -99,8 +107,8 @@ intersphinx_mapping = { "torch": ("https://pytorch.org/docs/stable/", None), - "tensordict": ("https://pytorch.github.io/tensordict/", None), - "torchrl": ("https://pytorch.org/rl/", None), + "tensordict": ("https://pytorch.github.io/tensordict/stable", None), + "torchrl": ("https://pytorch.org/rl/stable", None), "torchaudio": ("https://pytorch.org/audio/stable/", None), "torchtext": ("https://pytorch.org/text/stable/", None), "torchvision": ("https://pytorch.org/vision/stable/", None), @@ -108,6 +116,7 @@ # -- Sphinx-gallery configuration -------------------------------------------- + def reset_seeds(gallery_conf, fname): torch.cuda.empty_cache() torch.manual_seed(42) @@ -116,24 +125,33 @@ def reset_seeds(gallery_conf, fname): numpy.random.seed(10) gc.collect() + 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", @@ -162,12 +180,6 @@ def reset_seeds(gallery_conf, fname): "name": "torch.multiply", }, ], - "external_links": [ - { - "name": "Tutorials", - "url": "https://pytorch.org/tutorials/", - }, - ], "icon_links": [ { "name": "X", @@ -215,8 +227,7 @@ def reset_seeds(gallery_conf, fname): } - -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 @@ -224,9 +235,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]) @@ -238,21 +251,24 @@ 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", + os.path.join(os.path.dirname(pytorch_sphinx_theme2.__file__), "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 @@ -268,17 +284,31 @@ 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*", + # "**/huggingface_hub/templates/**", +] +exclude_patterns += sphinx_gallery_conf["examples_dirs"] +exclude_patterns += ["*/index.rst"] + + +# Handling for HuggingFace Hub jinja templates +def handle_jinja_templates(app, docname, source): + if "huggingface_hub/templates" in docname: + # Replace Jinja templates with quoted strings + source[0] = re.sub(r"(\{\{.*?\}\})", r'"\1"', source[0]) + # 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 @@ -306,7 +336,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 = { @@ -315,62 +345,49 @@ def reset_seeds(gallery_conf, fname): # } -html_theme = 'pytorch_sphinx_theme' -html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()] -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', -} - - # -- Options for HTMLHelp output ------------------------------------------ # Output file base name for HTML help builder. -htmlhelp_basename = 'PyTorchTutorialsdoc' +# htmlhelp_basename = 'PyTorchTutorialsdoc' # -- Options for LaTeX output --------------------------------------------- -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', +# latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +# +# 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', +# The font size ('10pt', '11pt' or '12pt'). +# +# 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', +# Additional stuff for the LaTeX preamble. +# +# 'preamble': '', - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', -} +# Latex figure (float) alignment +# +# 'figure_align': 'htbp', +# } # Grouping the document tree into LaTeX files. List of tuples # (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'), -] +# latex_documents = [ +# (master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials', +# 'Sasank, PyTorch contributors', 'manual'), +# ] # -- Options for manual page output --------------------------------------- # 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 ------------------------------------------- @@ -378,41 +395,22 @@ def reset_seeds(gallery_conf, fname): # Grouping the document tree into Texinfo files. List of tuples # (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'), -] +# texinfo_documents = [ +# (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' - ] - -html_js_files = [ - "js/custom.js", + "https://cdn.jsdelivr.net/npm/katex@0.10.0-beta/dist/katex.min.css", ] + 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 = [ - # '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(css_file) - # Custom CSS - #app.add_stylesheet('css/pytorch_theme.css') - # app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato') + app.connect("source-read", handle_jinja_templates) # 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) diff --git a/domains.rst b/domains.rst new file mode 100644 index 00000000000..4798f7e19b8 --- /dev/null +++ b/domains.rst @@ -0,0 +1,61 @@ +:orphan: + +Domains +======= + +This section contains specialized tutorials focused on applying +PyTorch to specific application areas. These guides demonstrate +how to use domain-specific libraries like torchvision, torchaudio, and +others. This section is for developers looking to implement PyTorch +in particular fields of deep learning. + +.. toctree:: + :maxdepth: 1 + :includehidden: + :hidden: + :caption: Image and Video + + intermediate/torchvision_tutorial + beginner/transfer_learning_tutorial + beginner/fgsm_tutorial + beginner/dcgan_faces_tutorial + intermediate/spatial_transformer_tutorial + beginner/vt_tutorial + intermediate/tiatoolbox_tutorial + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Audio + + beginner/audio_io_tutorial + beginner/audio_resampling_tutorial + beginner/audio_data_augmentation_tutorial + beginner/audio_feature_extractions_tutorial + beginner/audio_feature_augmentation_tutorial + beginner/audio_datasets_tutorial + intermediate/speech_recognition_pipeline_tutorial + intermediate/speech_command_classification_with_torchaudio_tutorial + intermediate/text_to_speech_with_torchaudio + intermediate/forced_alignment_with_torchaudio_tutorial + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Reinforcement Learning + + intermediate/reinforcement_q_learning + intermediate/reinforcement_ppo + intermediate/mario_rl_tutorial + advanced/pendulum + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Recommendation Systems + + intermediate/torchrec_intro_tutorial + advanced/sharding diff --git a/index.rst b/index.rst index 155b63a006d..778d81f7bce 100644 --- a/index.rst +++ b/index.rst @@ -921,228 +921,26 @@ Additional Resources .. Page TOC .. ----------------------------------------- .. toctree:: + :glob: :maxdepth: 1 :hidden: - :includehidden: - :caption: PyTorch Recipes - See All Recipes - See All Prototype Recipes + beginner/intro -.. toctree:: - :hidden: - :includehidden: - :caption: Introduction to PyTorch - - beginner/basics/intro - beginner/introyt/introyt_index .. toctree:: + :glob: :maxdepth: 1 :hidden: - :includehidden: - :caption: Learning PyTorch - - beginner/deep_learning_60min_blitz - beginner/pytorch_with_examples - beginner/nn_tutorial - intermediate/nlp_from_scratch_index - intermediate/tensorboard_tutorial - intermediate/pinmem_nonblock .. toctree:: :maxdepth: 1 - :includehidden: :hidden: - :caption: Image and Video - intermediate/torchvision_tutorial - beginner/transfer_learning_tutorial - beginner/fgsm_tutorial - beginner/dcgan_faces_tutorial - intermediate/spatial_transformer_tutorial - beginner/vt_tutorial - intermediate/tiatoolbox_tutorial - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Audio - - beginner/audio_io_tutorial - beginner/audio_resampling_tutorial - beginner/audio_data_augmentation_tutorial - beginner/audio_feature_extractions_tutorial - beginner/audio_feature_augmentation_tutorial - beginner/audio_datasets_tutorial - intermediate/speech_recognition_pipeline_tutorial - intermediate/speech_command_classification_with_torchaudio_tutorial - intermediate/text_to_speech_with_torchaudio - intermediate/forced_alignment_with_torchaudio_tutorial + domains .. toctree:: :maxdepth: 1 - :includehidden: - :hidden: - :caption: Backends - - beginner/onnx/intro_onnx - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Reinforcement Learning - - intermediate/reinforcement_q_learning - intermediate/reinforcement_ppo - intermediate/mario_rl_tutorial - advanced/pendulum - -.. toctree:: - :maxdepth: 1 - :includehidden: - :hidden: - :caption: Deploying PyTorch Models in Production - - beginner/onnx/intro_onnx - intermediate/flask_rest_api_tutorial - beginner/Intro_to_TorchScript_tutorial - advanced/cpp_export - advanced/super_resolution_with_onnxruntime - intermediate/realtime_rpi - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Profiling PyTorch - - beginner/profiler - beginner/hta_intro_tutorial - beginner/hta_trace_diff_tutorial - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Code Transforms with FX - - intermediate/fx_conv_bn_fuser - intermediate/fx_profiling_tutorial - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Frontend APIs - - intermediate/memory_format_tutorial - intermediate/forward_ad_usage - intermediate/jacobians_hessians - intermediate/ensembling - intermediate/per_sample_grads - intermediate/neural_tangent_kernels.py - advanced/cpp_frontend - advanced/torch-script-parallelism - advanced/cpp_autograd - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Extending PyTorch - - advanced/custom_ops_landing_page - advanced/python_custom_ops - advanced/cpp_custom_ops - intermediate/custom_function_double_backward_tutorial - intermediate/custom_function_conv_bn_tutorial - advanced/cpp_extension - advanced/torch_script_custom_ops - advanced/torch_script_custom_classes - advanced/dispatcher - advanced/extend_dispatcher - advanced/privateuseone - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Model Optimization - - beginner/profiler - intermediate/tensorboard_profiler_tutorial - beginner/hyperparameter_tuning_tutorial - beginner/vt_tutorial - intermediate/parametrizations - intermediate/pruning_tutorial - advanced/dynamic_quantization_tutorial - intermediate/dynamic_quantization_bert_tutorial - intermediate/quantized_transfer_learning_tutorial - advanced/static_quantization_tutorial - intermediate/torchserve_with_ipex - intermediate/torchserve_with_ipex_2 - intermediate/nvfuser_intro_tutorial - intermediate/ax_multiobjective_nas_tutorial - intermediate/torch_compile_tutorial - intermediate/compiled_autograd_tutorial - intermediate/inductor_debug_cpu - intermediate/scaled_dot_product_attention_tutorial - beginner/knowledge_distillation_tutorial - - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Parallel and Distributed Training - - distributed/home - beginner/dist_overview - beginner/ddp_series_intro - intermediate/model_parallel_tutorial - intermediate/ddp_tutorial - intermediate/dist_tuto - intermediate/FSDP_tutorial - intermediate/FSDP_advanced_tutorial - intermediate/TCPStore_libuv_backend - intermediate/TP_tutorial - intermediate/pipelining_tutorial - intermediate/process_group_cpp_extension_tutorial - intermediate/rpc_tutorial - intermediate/rpc_param_server_tutorial - intermediate/rpc_async_execution - advanced/rpc_ddp_tutorial - advanced/generic_join - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Edge with ExecuTorch - - Exporting to ExecuTorch Tutorial - Running an ExecuTorch Model in C++ Tutorial < https://pytorch.org/executorch/stable/running-a-model-cpp-tutorial.html> - Using the ExecuTorch SDK to Profile a Model - Building an ExecuTorch iOS Demo App - Building an ExecuTorch Android Demo App - Lowering a Model as a Delegate - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Recommendation Systems - - intermediate/torchrec_intro_tutorial - advanced/sharding - -.. toctree:: - :maxdepth: 2 - :includehidden: :hidden: - :caption: Multimodality - beginner/flava_finetuning_tutorial + performance diff --git a/performance.rst b/performance.rst new file mode 100644 index 00000000000..a3407878969 --- /dev/null +++ b/performance.rst @@ -0,0 +1,119 @@ +:orphan: + +Performance +=========== + +.. toctree:: + :maxdepth: 1 + :includehidden: + :hidden: + :caption: Deploying PyTorch Models in Production + + beginner/onnx/intro_onnx + intermediate/flask_rest_api_tutorial + beginner/Intro_to_TorchScript_tutorial + advanced/cpp_export + advanced/super_resolution_with_onnxruntime + intermediate/realtime_rpi + +.. toctree:: + :maxdepth: 1 + :includehidden: + :hidden: + :caption: Backends + + beginner/onnx/intro_onnx + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Profiling PyTorch + + beginner/profiler + beginner/hta_intro_tutorial + beginner/hta_trace_diff_tutorial + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Frontend APIs + + intermediate/memory_format_tutorial + intermediate/forward_ad_usage + intermediate/jacobians_hessians + intermediate/ensembling + intermediate/per_sample_grads + intermediate/neural_tangent_kernels.py + advanced/cpp_frontend + advanced/torch-script-parallelism + advanced/cpp_autograd + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Extending PyTorch + + advanced/custom_ops_landing_page + advanced/python_custom_ops + advanced/cpp_custom_ops + intermediate/custom_function_double_backward_tutorial + intermediate/custom_function_conv_bn_tutorial + advanced/cpp_extension + advanced/torch_script_custom_ops + advanced/torch_script_custom_classes + advanced/dispatcher + advanced/extend_dispatcher + advanced/privateuseone + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Model Optimization + + beginner/profiler + intermediate/tensorboard_profiler_tutorial + beginner/hyperparameter_tuning_tutorial + beginner/vt_tutorial + intermediate/parametrizations + intermediate/pruning_tutorial + advanced/dynamic_quantization_tutorial + intermediate/dynamic_quantization_bert_tutorial + intermediate/quantized_transfer_learning_tutorial + advanced/static_quantization_tutorial + intermediate/torchserve_with_ipex + intermediate/torchserve_with_ipex_2 + intermediate/nvfuser_intro_tutorial + intermediate/ax_multiobjective_nas_tutorial + intermediate/torch_compile_tutorial + intermediate/compiled_autograd_tutorial + intermediate/inductor_debug_cpu + intermediate/scaled_dot_product_attention_tutorial + beginner/knowledge_distillation_tutorial + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Parallel and Distributed Training + + distributed/home + beginner/dist_overview + beginner/ddp_series_intro + intermediate/model_parallel_tutorial + intermediate/ddp_tutorial + intermediate/dist_tuto + intermediate/FSDP_tutorial + intermediate/FSDP_advanced_tutorial + intermediate/TCPStore_libuv_backend + intermediate/TP_tutorial + intermediate/pipelining_tutorial + intermediate/process_group_cpp_extension_tutorial + intermediate/rpc_tutorial + intermediate/rpc_param_server_tutorial + intermediate/rpc_async_execution + advanced/rpc_ddp_tutorial + advanced/generic_join From 838cd7d2d237c545759d1346bdc98a86f95d5c4e Mon Sep 17 00:00:00 2001 From: Svetlana Karslioglu Date: Mon, 31 Mar 2025 09:30:31 -0700 Subject: [PATCH 04/24] Add new theme --- add-cards.py | 121 ++++++++ beginner_source/{index.rst => intro.rst} | 16 +- conf.py | 30 +- custom_directives.py | 350 ----------------------- deployment.rst | 29 ++ distributed.rst | 6 + extension.rst | 43 +++ index.rst | 20 +- optimization.rst | 47 +++ performance.rst | 119 -------- prototype_source/prototype_index.rst | 3 - recipes_source/recipes_index.rst | 3 - 12 files changed, 273 insertions(+), 514 deletions(-) create mode 100644 add-cards.py rename beginner_source/{index.rst => intro.rst} (71%) delete mode 100644 custom_directives.py create mode 100644 deployment.rst create mode 100644 distributed.rst create mode 100644 extension.rst create mode 100644 optimization.rst delete mode 100644 performance.rst diff --git a/add-cards.py b/add-cards.py new file mode 100644 index 00000000000..8eaa55c08a2 --- /dev/null +++ b/add-cards.py @@ -0,0 +1,121 @@ +import os + +import sphinx.addnodes + +from docutils import nodes +from docutils.parsers.rst import Directive +from sphinx.util import logging +from sphinx.util.docutils import SphinxDirective + + +logger = logging.getLogger(__name__) + + +class AddCardsDirective(SphinxDirective): + """ + Directive to automatically add cards based on toctree entries. + """ + + has_content = False + required_arguments = 0 + optional_arguments = 0 + final_argument_whitespace = False + option_spec = {} + + def run(self): + env = self.env + toctrees = env.tocs.get(env.docname, None) + + if not toctrees: + logger.warning(f"No toctrees found in document {env.docname}") + return [] + + # Find all toctrees in the document + all_cards_container = nodes.container() + all_cards_container["classes"] = ["all-tutorial-cards"] + + # Process each toctree + for toctreenode in toctrees.traverse(addnodes.toctree): + # Get caption + caption = toctreenode.get("caption", "") + + # Create section container + section_container = nodes.container() + section_container["classes"] = ["tutorial-section"] + + # Add section title if caption exists + if caption: + title_node = nodes.paragraph() + title_node["classes"] = ["tutorial-section-title"] + title_node += nodes.Text(caption) + section_container += title_node + + # Create cards container + cards_container = nodes.container() + cards_container["classes"] = ["tutorial-cards-container"] + + # Find all entries in this toctree + for entry in toctreenode["entries"]: + doc_name = entry[1] + title = env.titles.get(doc_name, nodes.title()).astext() or doc_name + + # Try to get description from the document + description = "" + doc_path = os.path.join(self.env.srcdir, doc_name + ".rst") + if os.path.exists(doc_path): + try: + with open(doc_path, "r") as f: + content = f.read() + # Extract first paragraph after title as description + lines = content.split("\n") + for i, line in enumerate(lines): + if i > 2 and line.strip() and not line.startswith(".."): + description = line.strip() + break + except Exception as e: + logger.warning(f"Error reading {doc_path}: {e}") + + # Create card + card = nodes.container() + card["classes"] = ["tutorial-card"] + + # Add link + card_link = nodes.reference("", "") + card_link["refuri"] = entry["refuri"] + card_link["classes"] = ["card-link"] + + # Add title + title_node = nodes.paragraph() + title_node["classes"] = ["card-title"] + title_node += nodes.Text(title) + card_link += title_node + + # Add description if available + if description: + desc_node = nodes.paragraph() + desc_node["classes"] = ["card-description"] + desc_node += nodes.Text( + description[:100] + "..." + if len(description) > 100 + else description + ) + card_link += desc_node + + card += card_link + cards_container += card + + section_container += cards_container + all_cards_container += section_container + + return [all_cards_container] + + +def setup(app): + app.add_directive("add-cards", AddCardsDirective) + app.add_css_file("tutorial_cards.css") + + return { + "version": "0.1", + "parallel_read_safe": True, + "parallel_write_safe": True, + } diff --git a/beginner_source/index.rst b/beginner_source/intro.rst similarity index 71% rename from beginner_source/index.rst rename to beginner_source/intro.rst index 7691082f24f..192421eace3 100644 --- a/beginner_source/index.rst +++ b/beginner_source/intro.rst @@ -15,7 +15,7 @@ understand PyTorch's core functionality through step-by-step guidance. :includehidden: :caption: Learn the Basics - beginner/basics/intro + basics/intro .. toctree:: @@ -24,7 +24,7 @@ understand PyTorch's core functionality through step-by-step guidance. :includehidden: :caption: Introduction to PyTorch - YouTube Series - beginner/introyt/introyt_index + introyt/introyt_index .. toctree:: :maxdepth: 1 @@ -32,9 +32,9 @@ understand PyTorch's core functionality through step-by-step guidance. :includehidden: :caption: Learning PyTorch - beginner/deep_learning_60min_blitz - beginner/pytorch_with_examples - beginner/nn_tutorial - intermediate/nlp_from_scratch_index - intermediate/tensorboard_tutorial - intermediate/pinmem_nonblock + deep_learning_60min_blitz + pytorch_with_examples + nn_tutorial + nlp_from_scratch_index + tensorboard_tutorial + pinmem_nonblock diff --git a/conf.py b/conf.py index 56f7ab54732..27528f42339 100644 --- a/conf.py +++ b/conf.py @@ -50,13 +50,6 @@ import pypandoc import torch -from custom_directives import ( - CustomCalloutItemDirective, - CustomCardItemDirective, - CustomGalleryItemDirective, - GalleryItemDirective, - IncludeDirective, -) from get_sphinx_filenames import SPHINX_SHOULD_RUN pio.renderers.default = "sphinx_gallery" @@ -97,6 +90,8 @@ "sphinx_design", "sphinx_sitemap", "sphinxcontrib.mermaid", + "add-cards", + "pytorch_sphinx_theme2" ] myst_enable_extensions = [ @@ -166,20 +161,6 @@ def reset_seeds(gallery_conf, fname): "logo": { "text": "Home", }, - "language_bindings_links": [ - { - "url": "https://pytorch.org/docs/stable/cpp_index.html", - "name": "C++", - }, - { - "url": "https://pytorch.org/javadoc/", - "name": "Javadoc", - }, - { - "url": "https://github.com/pytorch/multipy", - "name": "torch.multiply", - }, - ], "icon_links": [ { "name": "X", @@ -205,6 +186,7 @@ def reset_seeds(gallery_conf, fname): "use_edit_page_button": True, "logo": { "text": "Home", + "header_links_before_dropdown": 9, }, } @@ -408,9 +390,3 @@ def handle_jinja_templates(app, docname, source): def setup(app): app.connect("source-read", handle_jinja_templates) - # 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) diff --git a/custom_directives.py b/custom_directives.py deleted file mode 100644 index 388aa262e6e..00000000000 --- a/custom_directives.py +++ /dev/null @@ -1,350 +0,0 @@ -from docutils.parsers.rst import Directive, directives -from docutils.statemachine import StringList -from docutils import nodes -import re -import os -import sphinx_gallery - -try: - FileNotFoundError -except NameError: - FileNotFoundError = IOError - - -class IncludeDirective(Directive): - """Include source file without docstring at the top of file. - - Implementation just replaces the first docstring found in file - with '' once. - - Example usage: - - .. includenodoc:: /beginner/examples_tensor/two_layer_net_tensor.py - - """ - - # defines the parameter the directive expects - # directives.unchanged means you get the raw value from RST - required_arguments = 1 - optional_arguments = 0 - final_argument_whitespace = True - has_content = False - add_index = False - - docstring_pattern = r'"""(?P(?:.|[\r\n])*?)"""\n' - docstring_regex = re.compile(docstring_pattern) - - def run(self): - document = self.state.document - env = document.settings.env - rel_filename, filename = env.relfn2path(self.arguments[0]) - - try: - text = open(filename).read() - text_no_docstring = self.docstring_regex.sub('', text, count=1) - - code_block = nodes.literal_block(text=text_no_docstring) - return [code_block] - except FileNotFoundError as e: - print(e) - return [] - - -class GalleryItemDirective(Directive): - """ - Create a sphinx gallery thumbnail for insertion anywhere in docs. - - Optionally, you can specify the custom figure and intro/tooltip for the - thumbnail. - - Example usage: - - .. galleryitem:: intermediate/char_rnn_generation_tutorial.py - :figure: _static/img/char_rnn_generation.png - :intro: Put your custom intro here. - - If figure is specified, a thumbnail will be made out of it and stored in - _static/thumbs. Therefore, consider _static/thumbs as a 'built' directory. - """ - - required_arguments = 1 - optional_arguments = 0 - final_argument_whitespace = True - option_spec = {'figure': directives.unchanged, - 'intro': directives.unchanged} - has_content = False - add_index = False - - def run(self): - args = self.arguments - fname = args[-1] - - env = self.state.document.settings.env - fname, abs_fname = env.relfn2path(fname) - basename = os.path.basename(fname) - dirname = os.path.dirname(fname) - - try: - if 'intro' in self.options: - intro = self.options['intro'][:195] + '...' - else: - _, blocks = sphinx_gallery.gen_rst.split_code_and_text_blocks(abs_fname) - intro, _ = sphinx_gallery.gen_rst.extract_intro_and_title(abs_fname, blocks[0][1]) - - thumbnail_rst = '' - #sphinx_gallery.backreferences._thumbnail_div( - # dirname, basename, intro) - - if 'figure' in self.options: - rel_figname, figname = env.relfn2path(self.options['figure']) - save_figname = os.path.join('_static/thumbs/', - os.path.basename(figname)) - - try: - os.makedirs('_static/thumbs') - except OSError: - pass - - sphinx_gallery.gen_rst.scale_image(figname, save_figname, - 400, 280) - # replace figure in rst with simple regex - thumbnail_rst = re.sub(r'..\sfigure::\s.*\.png', - '.. figure:: /{}'.format(save_figname), - thumbnail_rst) - - thumbnail = StringList(thumbnail_rst.split('\n')) - thumb = nodes.paragraph() - self.state.nested_parse(thumbnail, self.content_offset, thumb) - - return [thumb] - except FileNotFoundError as e: - print(e) - return [] - - -GALLERY_TEMPLATE = """ -.. raw:: html - -
    - -.. only:: html - - .. figure:: {thumbnail} - - {description} - -.. raw:: html - -
    -""" - - -class CustomGalleryItemDirective(Directive): - """Create a sphinx gallery style thumbnail. - - tooltip and figure are self explanatory. Description could be a link to - a document like in below example. - - Example usage: - - .. customgalleryitem:: - :tooltip: I am writing this tutorial to focus specifically on NLP for people who have never written code in any deep learning framework - :figure: /_static/img/thumbnails/babel.jpg - :description: :doc:`/beginner/deep_learning_nlp_tutorial` - - If figure is specified, a thumbnail will be made out of it and stored in - _static/thumbs. Therefore, consider _static/thumbs as a 'built' directory. - """ - - required_arguments = 0 - optional_arguments = 0 - final_argument_whitespace = True - option_spec = {'tooltip': directives.unchanged, - 'figure': directives.unchanged, - 'description': directives.unchanged} - - has_content = False - add_index = False - - def run(self): - try: - if 'tooltip' in self.options: - tooltip = self.options['tooltip'][:195] + '...' - else: - raise ValueError('tooltip not found') - - if 'figure' in self.options: - env = self.state.document.settings.env - rel_figname, figname = env.relfn2path(self.options['figure']) - thumbnail = os.path.join('_static/thumbs/', os.path.basename(figname)) - - try: - os.makedirs('_static/thumbs') - except FileExistsError: - pass - - sphinx_gallery.gen_rst.scale_image(figname, thumbnail, 400, 280) - else: - thumbnail = '_static/img/thumbnails/default.png' - - if 'description' in self.options: - description = self.options['description'] - else: - raise ValueError('description not doc found') - - except FileNotFoundError as e: - print(e) - return [] - except ValueError as e: - print(e) - raise - return [] - - thumbnail_rst = GALLERY_TEMPLATE.format(tooltip=tooltip, - thumbnail=thumbnail, - description=description) - thumbnail = StringList(thumbnail_rst.split('\n')) - thumb = nodes.paragraph() - self.state.nested_parse(thumbnail, self.content_offset, thumb) - return [thumb] - - -class CustomCardItemDirective(Directive): - option_spec = {'header': directives.unchanged, - 'image': directives.unchanged, - 'link': directives.unchanged, - 'card_description': directives.unchanged, - 'tags': directives.unchanged} - - def run(self): - try: - if 'header' in self.options: - header = self.options['header'] - else: - raise ValueError('header not doc found') - - if 'image' in self.options: - image = "" - else: - image = '_static/img/thumbnails/default.png' - - if 'link' in self.options: - link = self.options['link'] - else: - link = '' - - if 'card_description' in self.options: - card_description = self.options['card_description'] - else: - card_description = '' - - if 'tags' in self.options: - tags = self.options['tags'] - else: - tags = '' - - except FileNotFoundError as e: - print(e) - return [] - except ValueError as e: - print(e) - raise - return [] - - card_rst = CARD_TEMPLATE.format(header=header, - image=image, - link=link, - card_description=card_description, - tags=tags) - card_list = StringList(card_rst.split('\n')) - card = nodes.paragraph() - self.state.nested_parse(card_list, self.content_offset, card) - return [card] - - -CARD_TEMPLATE = """ -.. raw:: html - - -""" - -class CustomCalloutItemDirective(Directive): - option_spec = {'header': directives.unchanged, - 'description': directives.unchanged, - 'button_link': directives.unchanged, - 'button_text': directives.unchanged} - - def run(self): - try: - if 'description' in self.options: - description = self.options['description'] - else: - description = '' - - if 'header' in self.options: - header = self.options['header'] - else: - raise ValueError('header not doc found') - - if 'button_link' in self.options: - button_link = self.options['button_link'] - else: - button_link = '' - - if 'button_text' in self.options: - button_text = self.options['button_text'] - else: - button_text = '' - - except FileNotFoundError as e: - print(e) - return [] - except ValueError as e: - print(e) - raise - return [] - - callout_rst = CALLOUT_TEMPLATE.format(description=description, - header=header, - button_link=button_link, - button_text=button_text) - callout_list = StringList(callout_rst.split('\n')) - callout = nodes.paragraph() - self.state.nested_parse(callout_list, self.content_offset, callout) - return [callout] - -CALLOUT_TEMPLATE = """ -.. raw:: html - -
    -
    -

    {header}

    -

    {description}

    - {button_text} -
    -
    -""" diff --git a/deployment.rst b/deployment.rst new file mode 100644 index 00000000000..5fc148cf4c2 --- /dev/null +++ b/deployment.rst @@ -0,0 +1,29 @@ +:orphan: + +Deployment +========== + +This section covers topics realted to the deployment of PyTorch +models in production environments. It includes tutorials on using +ONNX, Flask REST APIs, TorchScript, and more advanced topics like C++ export and ONNX Runtime. + +.. toctree:: + :maxdepth: 1 + :includehidden: + :hidden: + :caption: Deploying PyTorch Models in Production + + intermediate/flask_rest_api_tutorial + beginner/Intro_to_TorchScript_tutorial + advanced/cpp_export + advanced/super_resolution_with_onnxruntime + intermediate/realtime_rpi + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Backends + + beginner/onnx/intro_onnx + diff --git a/distributed.rst b/distributed.rst new file mode 100644 index 00000000000..6d88fc8c761 --- /dev/null +++ b/distributed.rst @@ -0,0 +1,6 @@ +Distributed +=========== + +.. raw:: html + + diff --git a/extension.rst b/extension.rst new file mode 100644 index 00000000000..6b62542e365 --- /dev/null +++ b/extension.rst @@ -0,0 +1,43 @@ +:orphan: + +Extension +========= + +This section provides insights into extending PyTorch's capabilities. +It covers custom operations, frontend APIs, and advanced topics like +C++ extensions and dispatcher usage. + + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Frontend APIs + + intermediate/memory_format_tutorial + intermediate/forward_ad_usage + intermediate/jacobians_hessians + intermediate/ensembling + intermediate/per_sample_grads + intermediate/neural_tangent_kernels.py + advanced/cpp_frontend + advanced/torch-script-parallelism + advanced/cpp_autograd + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Extending PyTorch + + advanced/custom_ops_landing_page + advanced/python_custom_ops + advanced/cpp_custom_ops + intermediate/custom_function_double_backward_tutorial + intermediate/custom_function_conv_bn_tutorial + advanced/cpp_extension + advanced/torch_script_custom_ops + advanced/torch_script_custom_classes + advanced/dispatcher + advanced/extend_dispatcher + advanced/privateuseone diff --git a/index.rst b/index.rst index 778d81f7bce..81733848fa7 100644 --- a/index.rst +++ b/index.rst @@ -927,20 +927,32 @@ Additional Resources beginner/intro - .. toctree:: - :glob: :maxdepth: 1 :hidden: + domains + +.. toctree:: + :maxdepth: 2 + :hidden: + + deployment + +.. toctree:: 1 + :hidden: + :maxdepth: 2 + + optimization + .. toctree:: :maxdepth: 1 :hidden: - domains + extension .. toctree:: :maxdepth: 1 :hidden: - performance + distributed diff --git a/optimization.rst b/optimization.rst new file mode 100644 index 00000000000..bf46673ebab --- /dev/null +++ b/optimization.rst @@ -0,0 +1,47 @@ +:orphan: + +Optimization +============ + +Focused on enhancing model performance, this section includes +tutorials on profiling, hyperparameter tuning, quantization, +and other techniques to optimize PyTorch models for better efficiency +and speed. + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Profiling PyTorch + + beginner/profiler + beginner/hta_intro_tutorial + beginner/hta_trace_diff_tutorial + +.. toctree:: + :maxdepth: 2 + :includehidden: + :hidden: + :caption: Model Optimization + + beginner/profiler + intermediate/tensorboard_profiler_tutorial + beginner/hyperparameter_tuning_tutorial + beginner/vt_tutorial + intermediate/parametrizations + intermediate/pruning_tutorial + advanced/dynamic_quantization_tutorial + intermediate/dynamic_quantization_bert_tutorial + intermediate/quantized_transfer_learning_tutorial + advanced/static_quantization_tutorial + intermediate/torchserve_with_ipex + intermediate/torchserve_with_ipex_2 + intermediate/nvfuser_intro_tutorial + intermediate/ax_multiobjective_nas_tutorial + intermediate/torch_compile_tutorial + intermediate/compiled_autograd_tutorial + intermediate/inductor_debug_cpu + intermediate/scaled_dot_product_attention_tutorial + beginner/knowledge_distillation_tutorial + +.. add-cards:: diff --git a/performance.rst b/performance.rst deleted file mode 100644 index a3407878969..00000000000 --- a/performance.rst +++ /dev/null @@ -1,119 +0,0 @@ -:orphan: - -Performance -=========== - -.. toctree:: - :maxdepth: 1 - :includehidden: - :hidden: - :caption: Deploying PyTorch Models in Production - - beginner/onnx/intro_onnx - intermediate/flask_rest_api_tutorial - beginner/Intro_to_TorchScript_tutorial - advanced/cpp_export - advanced/super_resolution_with_onnxruntime - intermediate/realtime_rpi - -.. toctree:: - :maxdepth: 1 - :includehidden: - :hidden: - :caption: Backends - - beginner/onnx/intro_onnx - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Profiling PyTorch - - beginner/profiler - beginner/hta_intro_tutorial - beginner/hta_trace_diff_tutorial - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Frontend APIs - - intermediate/memory_format_tutorial - intermediate/forward_ad_usage - intermediate/jacobians_hessians - intermediate/ensembling - intermediate/per_sample_grads - intermediate/neural_tangent_kernels.py - advanced/cpp_frontend - advanced/torch-script-parallelism - advanced/cpp_autograd - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Extending PyTorch - - advanced/custom_ops_landing_page - advanced/python_custom_ops - advanced/cpp_custom_ops - intermediate/custom_function_double_backward_tutorial - intermediate/custom_function_conv_bn_tutorial - advanced/cpp_extension - advanced/torch_script_custom_ops - advanced/torch_script_custom_classes - advanced/dispatcher - advanced/extend_dispatcher - advanced/privateuseone - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Model Optimization - - beginner/profiler - intermediate/tensorboard_profiler_tutorial - beginner/hyperparameter_tuning_tutorial - beginner/vt_tutorial - intermediate/parametrizations - intermediate/pruning_tutorial - advanced/dynamic_quantization_tutorial - intermediate/dynamic_quantization_bert_tutorial - intermediate/quantized_transfer_learning_tutorial - advanced/static_quantization_tutorial - intermediate/torchserve_with_ipex - intermediate/torchserve_with_ipex_2 - intermediate/nvfuser_intro_tutorial - intermediate/ax_multiobjective_nas_tutorial - intermediate/torch_compile_tutorial - intermediate/compiled_autograd_tutorial - intermediate/inductor_debug_cpu - intermediate/scaled_dot_product_attention_tutorial - beginner/knowledge_distillation_tutorial - -.. toctree:: - :maxdepth: 2 - :includehidden: - :hidden: - :caption: Parallel and Distributed Training - - distributed/home - beginner/dist_overview - beginner/ddp_series_intro - intermediate/model_parallel_tutorial - intermediate/ddp_tutorial - intermediate/dist_tuto - intermediate/FSDP_tutorial - intermediate/FSDP_advanced_tutorial - intermediate/TCPStore_libuv_backend - intermediate/TP_tutorial - intermediate/pipelining_tutorial - intermediate/process_group_cpp_extension_tutorial - intermediate/rpc_tutorial - intermediate/rpc_param_server_tutorial - intermediate/rpc_async_execution - advanced/rpc_ddp_tutorial - advanced/generic_join diff --git a/prototype_source/prototype_index.rst b/prototype_source/prototype_index.rst index 927f5f694b8..50eaccad0ba 100644 --- a/prototype_source/prototype_index.rst +++ b/prototype_source/prototype_index.rst @@ -7,9 +7,6 @@ Prototype features are not available as part of binary distributions like PyPI o .. raw:: html - - -
    - -