Skip to content

Commit

Permalink
Fixed: saving.md
Browse files Browse the repository at this point in the history
  • Loading branch information
NightMachinery committed Dec 12, 2021
1 parent 9b716fc commit d238cc3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/src/saving.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ revert to an older copy of the model if it starts to overfit.
@save "model-$(now()).bson" model loss = testloss()
```

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.
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.

You can store the optimiser state alongside the model, to resume training
exactly where you left off; BSON is smart enough to cache values and insert links when saving, but only 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.

```julia
opt = ADAM()
@save "model-$(now()).bson" model opt
```

0 comments on commit d238cc3

Please sign in to comment.