Skip to content

Commit 4d3fd75

Browse files
Fixed: saving.md
1 parent 9b716fc commit 4d3fd75

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/src/saving.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,13 @@ revert to an older copy of the model if it starts to overfit.
118118
@save "model-$(now()).bson" model loss = testloss()
119119
```
120120

121-
Note that to resume a model's training, you might need to restore other stateful parts of your training loop. Possible examples are stateful optimizers (which usually utilize an `IdDict` to store their state, which is not automatically handled by `BSON`), and the randomness used to partition the original data into the training and validation sets.
121+
Note that to resume a model's training, you might need to restore other stateful parts of your training loop. Possible examples are stateful optimizers (which usually utilize an `IdDict` to store their state), and the randomness used to partition the original data into the training and validation sets.
122+
123+
You can store the optimiser state alongside the model, to resume training
124+
exactly where you left off; BSON is smart enough to cache values and insert links when saving, but only if it knows everything to be saved up front. (See [here](https://github.com/JuliaIO/BSON.jl/blob/3b4a2cebda0afae11aab310f0a4d12b6a5234160/src/write.jl#L71).) So models and optimizers must be saved together to have the latter work when restoring.
125+
126+
```julia
127+
opt = ADAM()
128+
@save "model-$(now()).bson" model opt
129+
```
130+

0 commit comments

Comments
 (0)