第6章構築者のための手引き
6.6. File I/O6.6 ファイルの入出力
So far we have discussed how to process data and how to build, train, and test deep learning models. However, at some point we will hopefully be happy enough with the learned models that we will want to save the results for later use in various contexts (perhaps even to make predictions in deployment). Additionally, when running a long training process, the best practice is to periodically save intermediate results (checkpointing) to ensure that we do not lose several days’ worth of computation if we trip over the power cord of our server. Thus it is time to learn how to load and store both individual weight vectors and entire models. This section addresses both issues.
英語のヒント
ここまで、データを処理する方法と、深層学習のモデルを作り、訓練し、テストする方法を論じてきた。しかし、いずれは学習したモデルに十分満足して、さまざまな文脈で後で使うために(ことによると実運用で予測をするためにさえ)結果を保存したくなるだろう。さらに、長い訓練の過程を走らせるときには、中間の結果を定期的に保存する(チェックポイントを作る)のが最善のやり方である。そうすれば、サーバーの電源コードにつまずいても、何日分もの計算を失わずに済む。そこで、個々の重みベクトルとモデル全体の両方を読み込み、保存する方法を学ぶ時が来た。この節では、その両方の問題を扱う。
import torch
from torch import nn
from torch.nn import functional as F