-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add readme. migrate_ckpt also returns list of done migrations
- Loading branch information
Showing
3 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# migrate-ckpt | ||
|
||
```python | ||
import torch | ||
from migrate_ckpt import Migration, migrate_ckpt | ||
|
||
|
||
def update_some_keys_callback(ckpt): | ||
""" | ||
Define a callback that takes a checkpoints and updates it. | ||
""" | ||
ckpt["some_keys"] = ckpt["some_other_keys"] | ||
del ckpt["some_other_keys"] | ||
return ckpt | ||
|
||
|
||
# List a set of migrations. Whenever you update your model architecture, | ||
# you should add one that updates the model starting from the previous | ||
# state (output of the previous migration) | ||
model_migrations = [ | ||
Migration("Update some keys", update_some_keys_callback), | ||
] | ||
|
||
# Will only perform new migrations. | ||
# done_migrations returns the list of migration objects that were executed. | ||
ckpt, done_migrations = migrate_ckpt( | ||
torch.load("/path/to/some/checkpoint.ckpt"), | ||
model_migrations, | ||
) | ||
|
||
# This has no effect, the model was already migrated. | ||
ckpt_2, _ = migrate_ckpt(ckpt, model_migrations) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters