Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

💡 [REQUEST] - Tutorial: Visualizing the Mathematics Behind Neural Network Training

未关闭
#3,907 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
文档
描述清晰度
基本清楚
活跃度
冷清
技术栈
python, pytorch

调研方向

从 beginner_source/ 开始,比较 autogradqs_tutorial.py、autograd_tutorial.py 和 buildmodel_tutorial.py,以确定剩余的教学空缺。构建一个可在 CPU 上运行的教程,涵盖提议的六个部分,包括可观察的矩阵运算、梯度、grad_fn 以及优化器的变化。当数学步骤可以在代码中追踪并验证时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

🚀 Describe the improvement or the new tutorial

A beginner-friendly tutorial that traces the mathematical operations inside a PyTorch training loop — connecting linear algebra to torch.nn.Linear, the chain rule to torch.autograd.backward(), and gradient descent to torch.optim — with runnable code that makes each step observable and verifiable.

Why this is needed:
Many learners use autograd as a black box. Existing tutorials explain the API (how to call .backward(), how to access .grad) but do not trace what is happening mathematically at each step. This tutorial bridges that gap by making the math visible through code:

  1. Print a weight matrix, verify it matches x @ W.T + b
  2. Call .backward(), then manually verify the gradient using the chain rule
  3. Walk the grad_fn graph to see the operations autograd recorded
  4. Compare parameters before and after optimizer.step() to see gradient descent in action

Proposed structure:

  1. Linear Algebra — what nn.Linear computes, verified with manual matrix multiplication
  2. Activation Functions — why nonlinearity matters, visualizing ReLU gradients
  3. The Chain Rule — what backward() computes, manually verifying gradients
  4. The Computational Graph — inspecting grad_fn to trace operations
  5. Gradient Descent — what optimizer.step() does, before/after comparison
  6. Putting It Together — forward, backward, step mapped to three branches of mathematics

This approach has been validated in practice: I presented this material at Grace Hopper Celebration 2025 ("The Math Behind the Magic: Understanding the Role of Mathematics in Deep Learning"). Talk materials: https://github.com/AddyM/Math_behind_ML

Difficulty level: Beginner
Target location: beginner_source/

I am happy to write and submit this tutorial as a PR.

Existing tutorials on this topic
  1. autogradqs_tutorial.py — covers autograd API usage (requires_grad, backward, grad). Focuses on how to use autograd, not what it computes mathematically.
    https://pytorch.org/tutorials/beginner/basics/autogradqs_tutorial.html

  2. autograd_tutorial.py — conceptual overview of automatic differentiation and computational graphs. Does not include manual verification of gradients or tracing the chain rule step by step.
    https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html

  3. buildmodel_tutorial.py — covers nn.Module and model building. Does not connect layer operations to their underlying linear algebra.
    https://pytorch.org/tutorials/beginner/basics/buildmodel_tutorial.html

Additional context

PyTorch's eager execution model makes the mathematics of deep learning observable in a way static graph frameworks do not allow. This tutorial leans into that strength — every intermediate result is printable, every gradient is inspectable, every operation in the computational graph is traceable.
No GPU required — the entire tutorial runs on CPU, making it accessible to all learners.
References:

GHC 2025 talk materials: https://github.com/AddyM/Math_behind_ML
PyTorch Discuss thread on this approach: https://discuss.pytorch.org/ (search: "Building a PyTorch curriculum that teaches math through code")

主要语言
Python
星标
9.3k
派生
4.4k
平均合并
1 天 21 小时
30 天内合并 PR
4

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pytorch/tutorials 的其他 Issue

查看 pytorch/tutorials 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。