💡 [REQUEST] - Clarification of requires_grad about beginner/nn_tutorial.html
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
- #3717 來自 @FlightVin —— 已關閉,未合併
評估
- 難度
- 1/5
- 預估耗時
- 1 小時以內
- 新手友好度
- 55/100
- Issue 類型
- 文件
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
研究方向
開啟 beginner/nn_tutorial.html 的原始碼,找到「Neural Net from Scratch without torch.nn」區段。更新 weights 和 bias 附近現有的註解,說明為什麼要在完成初始化計算後才為 weights 設定 requires_grad;當轉譯後的教學清楚說明 leaf 與 non-leaf 的區別時,即完成此項工作。
由索引模型根據 Issue 內容生成。
描述
🚀 Describe the improvement or the new tutorial
It was challenging for me to initially grasp why requires_grad was done after weights, but in the same line as bias under https://docs.pytorch.org/tutorials/beginner/nn_tutorial.html#neural-net-from-scratch-without-torch-nn
At first glance, the code looks inconsistent:
weightsinitialization is split into two lines.biasinitialization is done in one line.
The Logic Gap
The tutorial currently explains that we do it, but not exactly why the distinction exists between these two specific variables.
- The Bias is created using a factory function (
torch.zeros) with no subsequent mathematical operations. It is born as a "Leaf Node" (a source parameter). - The Weights involve a mathematical operation (
/ math.sqrt(...)). If we setrequires_grad=Trueinsidetorch.randn(), PyTorch records the division as a computational step. The resultingweightsvariable becomes a non-leaf node (a calculated outcome), which the optimizer cannot update.
Proposed Improvement
I propose modifying the comment block to explicitly mention that requires_grad must be deferred until after the initialization math is complete to preserve the tensor as a trainable parameter (Leaf Node).
Existing tutorials on this topic
- https://docs.pytorch.org/tutorials/beginner/nn_tutorial.html
- https://docs.pytorch.org/tutorials/beginner/nn_tutorial.html#neural-net-from-scratch-without-torch-nn
Additional context
- 主要語言
- Python
- 星號
- 9.5k
- 分支
- 4.5k
- 平均合併
- 1 天 20 小時
- 30 天內合併 PR
- 2
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
pytorch/tutorials 的其他 Issue
-
module: vulkan
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 2 天內回覆
-
Feedback about Datasets & DataLoaders可能已有人在做 @hippi345 於 47 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 62/100
維護者通常 2 天內回覆
-
💡 [REQUEST] - Add model.eval() after loading the mdoel可能已有人在做 @Justee21 於 71 天前認領。 未關閉
難度 1/5 1 小時以內 新手友好度 78/100
維護者通常 2 天內回覆
-
[BUG] Captum tutorial fails when visualize_image_attr() receives None for original_image可能已有人在做 @manjirisharma 於 41 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 70/100
pytorch/tutorials#3963 · 1 則留言 ·
維護者通常 2 天內回覆
-
[BUG] - Incorrect ResNet18 preprocessing in Captum tutorial可能已有人在做 @austxu 於 130 天前認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 2 天內回覆
查看 pytorch/tutorials 的全部 Issue
相似的 Issue
-
intake mcp-intake needs-human-review priority:high type:bug
難度 2/5 1-3 小時 新手友好度 77/100
Ikalus1988/MisakaNet#6081 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
521xueweihan/HelloGitHub#4655 ·
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount due可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 79/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 79/100
developmentseed/titiler-covjson#164 ·
維護者通常 1 天內回覆
-
area/install bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆