💡 [REQUEST] - Clarification of requires_grad about beginner/nn_tutorial.html

オープン
#3,716 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

  • #3717 @FlightVin による — マージされずにクローズ

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
55/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python, pytorch
領域
documentation

調査の方向性

beginner/nn_tutorial.html のソースを開き、「Neural Net from Scratch without torch.nn」セクションを見つけます。重みとバイアスに関する既存のコメントを更新し、初期化の計算後まで重みに対する 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:

  1. weights initialization is split into two lines.
  2. bias initialization 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 set requires_grad=True inside torch.randn(), PyTorch records the division as a computational step. The resulting weights variable 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
Additional context
Image
主要言語
Python
スター
9.5k
フォーク
4.5k
平均マージ
1日 20時間
マージ済み PR(30日)
2

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytorch/tutorials のほかの issue

pytorch/tutorials の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。