💡 [REQUEST] - Tutorial: Visualizing the Mathematics Behind Neural Network Training
还没有人认领这个 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:
- Print a weight matrix, verify it matches x @ W.T + b
- Call .backward(), then manually verify the gradient using the chain rule
- Walk the grad_fn graph to see the operations autograd recorded
- Compare parameters before and after optimizer.step() to see gradient descent in action
Proposed structure:
- Linear Algebra — what nn.Linear computes, verified with manual matrix multiplication
- Activation Functions — why nonlinearity matters, visualizing ReLU gradients
- The Chain Rule — what backward() computes, manually verifying gradients
- The Computational Graph — inspecting grad_fn to trace operations
- Gradient Descent — what optimizer.step() does, before/after comparison
- 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
-
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 -
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 -
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pytorch/tutorials 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 70/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
难度 1/5 1 小时以内 新手友好度 78/100
-
难度 1/5 1 小时以内 新手友好度 78/100
查看 pytorch/tutorials 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
stephrobert/dsoxlab#238 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 75/100
sublimehq/package_control#1780 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 70/100
nwg-piotr/nwg-displays#145 ·