From ca19641c60031373ebed53482f673701bc15a5bd Mon Sep 17 00:00:00 2001 From: Jiannan Wang Date: Mon, 29 Sep 2025 10:27:48 -0700 Subject: [PATCH 1/4] remove empty example section --- beginner_source/pytorch_with_examples.rst | 74 ----------------------- 1 file changed, 74 deletions(-) diff --git a/beginner_source/pytorch_with_examples.rst b/beginner_source/pytorch_with_examples.rst index e5642dfa139..fb415577641 100644 --- a/beginner_source/pytorch_with_examples.rst +++ b/beginner_source/pytorch_with_examples.rst @@ -22,10 +22,6 @@ as our running example. The network will have four parameters, and will be train gradient descent to fit random data by minimizing the Euclidean distance between the network output and the true output. -.. note:: - You can browse the individual examples at the - :ref:`end of this page `. - .. contents:: Table of Contents :local: @@ -215,73 +211,3 @@ times when defining the forward pass. We can easily implement this model as a Module subclass: .. includenodoc:: /beginner/examples_nn/dynamic_net.py - - -.. _examples-download: - -Examples -~~~~~~~~ - -You can browse the above examples here. - -Tensors -------- - -.. toctree:: - :maxdepth: 2 - :hidden: - - /beginner/examples_tensor/polynomial_numpy - /beginner/examples_tensor/polynomial_tensor - -.. galleryitem:: /beginner/examples_tensor/polynomial_numpy.py - -.. galleryitem:: /beginner/examples_tensor/polynomial_tensor.py - -.. raw:: html - -
- -Autograd --------- - -.. toctree:: - :maxdepth: 2 - :hidden: - - /beginner/examples_autograd/polynomial_autograd - /beginner/examples_autograd/polynomial_custom_function - - -.. galleryitem:: /beginner/examples_autograd/polynomial_autograd.py - -.. galleryitem:: /beginner/examples_autograd/polynomial_custom_function.py - -.. raw:: html - -
- -``nn`` module --------------- - -.. toctree:: - :maxdepth: 2 - :hidden: - - /beginner/examples_nn/polynomial_nn - /beginner/examples_nn/polynomial_optim - /beginner/examples_nn/polynomial_module - /beginner/examples_nn/dynamic_net - - -.. galleryitem:: /beginner/examples_nn/polynomial_nn.py - -.. galleryitem:: /beginner/examples_nn/polynomial_optim.py - -.. galleryitem:: /beginner/examples_nn/polynomial_module.py - -.. galleryitem:: /beginner/examples_nn/dynamic_net.py - -.. raw:: html - -
From 46e64639c568a61de51e58455a2ac9c7364bfb68 Mon Sep 17 00:00:00 2001 From: Jiannan Wang Date: Mon, 29 Sep 2025 10:41:45 -0700 Subject: [PATCH 2/4] Add prerequisite. --- beginner_source/pytorch_with_examples.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/beginner_source/pytorch_with_examples.rst b/beginner_source/pytorch_with_examples.rst index fb415577641..2e1c099b9d4 100644 --- a/beginner_source/pytorch_with_examples.rst +++ b/beginner_source/pytorch_with_examples.rst @@ -22,6 +22,12 @@ as our running example. The network will have four parameters, and will be train gradient descent to fit random data by minimizing the Euclidean distance between the network output and the true output. +To run the tutorials below, make sure you have the `torch`_ +and `numpy`_ packages installed. + +.. _torch: https://github.com/pytorch/pytorch +.. _numpy: https://github.com/numpy/numpy + .. contents:: Table of Contents :local: From 5409cd393df3da405ee7273725a4f79df171be2b Mon Sep 17 00:00:00 2001 From: Jiannan Wang Date: Mon, 29 Sep 2025 11:05:18 -0700 Subject: [PATCH 3/4] Revert pytorch_with_examples and remove :hidden: --- beginner_source/pytorch_with_examples.rst | 73 +++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/beginner_source/pytorch_with_examples.rst b/beginner_source/pytorch_with_examples.rst index 2e1c099b9d4..d65a959b957 100644 --- a/beginner_source/pytorch_with_examples.rst +++ b/beginner_source/pytorch_with_examples.rst @@ -22,6 +22,10 @@ as our running example. The network will have four parameters, and will be train gradient descent to fit random data by minimizing the Euclidean distance between the network output and the true output. +.. note:: + You can browse the individual examples at the + :ref:`end of this page `. + To run the tutorials below, make sure you have the `torch`_ and `numpy`_ packages installed. @@ -217,3 +221,72 @@ times when defining the forward pass. We can easily implement this model as a Module subclass: .. includenodoc:: /beginner/examples_nn/dynamic_net.py + + + + +.. _examples-download: + +Examples +~~~~~~~~ + +You can browse the above examples here. + +Tensors +------- + +.. toctree:: + :maxdepth: 2 + + /beginner/examples_tensor/polynomial_numpy + /beginner/examples_tensor/polynomial_tensor + +.. galleryitem:: /beginner/examples_tensor/polynomial_numpy.py + +.. galleryitem:: /beginner/examples_tensor/polynomial_tensor.py + +.. raw:: html + +
+ +Autograd +-------- + +.. toctree:: + :maxdepth: 2 + + /beginner/examples_autograd/polynomial_autograd + /beginner/examples_autograd/polynomial_custom_function + + +.. galleryitem:: /beginner/examples_autograd/polynomial_autograd.py + +.. galleryitem:: /beginner/examples_autograd/polynomial_custom_function.py + +.. raw:: html + +
+ +``nn`` module +-------------- + +.. toctree:: + :maxdepth: 2 + + /beginner/examples_nn/polynomial_nn + /beginner/examples_nn/polynomial_optim + /beginner/examples_nn/polynomial_module + /beginner/examples_nn/dynamic_net + + +.. galleryitem:: /beginner/examples_nn/polynomial_nn.py + +.. galleryitem:: /beginner/examples_nn/polynomial_optim.py + +.. galleryitem:: /beginner/examples_nn/polynomial_module.py + +.. galleryitem:: /beginner/examples_nn/dynamic_net.py + +.. raw:: html + +
\ No newline at end of file From ade91f7100eff9839df1d6a228d5ecdfd8bb9480 Mon Sep 17 00:00:00 2001 From: Jiannan Wang Date: Mon, 29 Sep 2025 14:12:14 -0700 Subject: [PATCH 4/4] fix `pi` to `\pi` --- beginner_source/examples_nn/polynomial_nn.py | 2 +- beginner_source/examples_nn/polynomial_optim.py | 2 +- beginner_source/examples_tensor/polynomial_numpy.py | 2 +- beginner_source/examples_tensor/polynomial_tensor.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/beginner_source/examples_nn/polynomial_nn.py b/beginner_source/examples_nn/polynomial_nn.py index ad6ba22f193..70e281ed365 100755 --- a/beginner_source/examples_nn/polynomial_nn.py +++ b/beginner_source/examples_nn/polynomial_nn.py @@ -4,7 +4,7 @@ ----------- A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi` -to :math:`pi` by minimizing squared Euclidean distance. +to :math:`\pi` by minimizing squared Euclidean distance. This implementation uses the nn package from PyTorch to build the network. PyTorch autograd makes it easy to define computational graphs and take gradients, diff --git a/beginner_source/examples_nn/polynomial_optim.py b/beginner_source/examples_nn/polynomial_optim.py index 434fb6624b3..c0d4896c8f2 100755 --- a/beginner_source/examples_nn/polynomial_optim.py +++ b/beginner_source/examples_nn/polynomial_optim.py @@ -4,7 +4,7 @@ -------------- A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi` -to :math:`pi` by minimizing squared Euclidean distance. +to :math:`\pi` by minimizing squared Euclidean distance. This implementation uses the nn package from PyTorch to build the network. diff --git a/beginner_source/examples_tensor/polynomial_numpy.py b/beginner_source/examples_tensor/polynomial_numpy.py index a1a378e50ed..059ec286ee4 100755 --- a/beginner_source/examples_tensor/polynomial_numpy.py +++ b/beginner_source/examples_tensor/polynomial_numpy.py @@ -4,7 +4,7 @@ -------------- A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi` -to :math:`pi` by minimizing squared Euclidean distance. +to :math:`\pi` by minimizing squared Euclidean distance. This implementation uses numpy to manually compute the forward pass, loss, and backward pass. diff --git a/beginner_source/examples_tensor/polynomial_tensor.py b/beginner_source/examples_tensor/polynomial_tensor.py index 1e35b0f24bd..260cf8d2849 100755 --- a/beginner_source/examples_tensor/polynomial_tensor.py +++ b/beginner_source/examples_tensor/polynomial_tensor.py @@ -4,7 +4,7 @@ ---------------- A third order polynomial, trained to predict :math:`y=\sin(x)` from :math:`-\pi` -to :math:`pi` by minimizing squared Euclidean distance. +to :math:`\pi` by minimizing squared Euclidean distance. This implementation uses PyTorch tensors to manually compute the forward pass, loss, and backward pass.