プリンキピア

第3章回帰のための線形ニューラルネットワーク

3.5.3. Defining the Optimization Algorithm3.5.3 最適化アルゴリズムの定義

Minibatch SGD is a standard tool for optimizing neural networks and thus PyTorch supports it alongside a number of variations on this algorithm in the optim module. When we instantiate an SGD instance, we specify the parameters to optimize over, obtainable from our model via self.parameters(), and the learning rate (self.lr) required by our optimization algorithm.
英語のヒント
ミニバッチSGDはニューラルネットワークを最適化する標準的な道具なので、PyTorchはoptimモジュールで、このアルゴリズムのいくつもの変種とともにそれに対応している。SGDのインスタンスを作るときは、最適化の対象となるパラメータ(モデルからself.parameters()で得られる)と、最適化アルゴリズムが必要とする学習率(self.lr)を指定する。
@d2l.add_to_class(LinearRegression)  #@save
def configure_optimizers(self):
    return torch.optim.SGD(self.parameters(), self.lr)