-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/migration' into bugfix/callback-state
- Loading branch information
Showing
5 changed files
with
55 additions
and
45 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,29 @@ | ||
import torch | ||
|
||
from pytorch_lightning.utilities.migration.base import Migration, get_version | ||
from pytorch_lightning.utilities.migration.base import Migration, upgrade_checkpoint | ||
from pytorch_lightning.utilities.migration.patch import pl_legacy_patch | ||
|
||
|
||
@Migration(requires="1.2.7") | ||
def upgrade_callback_names(checkpoint: dict) -> dict: | ||
if "callbacks" not in checkpoint: | ||
return checkpoint | ||
checkpoint["callbacks"] = reversed(checkpoint["callbacks"]) | ||
print(get_version(checkpoint)) | ||
@Migration(target="1.2.8") | ||
def upgrade_something_else(checkpoint: dict) -> dict: | ||
return checkpoint | ||
|
||
|
||
@Migration(requires="1.2.8") | ||
def upgrade_something_else(checkpoint: dict) -> dict: | ||
@Migration(target="1.2.9") | ||
def upgrade_callback_state_identifiers(checkpoint): | ||
if "callbacks" not in checkpoint: | ||
return | ||
callbacks = checkpoint["callbacks"] | ||
checkpoint["callbacks"] = dict((callback_type.__name__, state) for callback_type, state in callbacks.items()) | ||
return checkpoint | ||
|
||
|
||
if __name__ == "__main__": | ||
with pl_legacy_patch(): | ||
checkpoint = torch.load("gpus-default-legacy.ckpt") | ||
ckpt = torch.load("gpus-default-legacy.ckpt") | ||
# checkpoint = torch.load("example.ckpt") | ||
# checkpoint["pytorch-lightning_version"] = "1.2.6" | ||
# getattr() | ||
checkpoint = Migration.migrate(checkpoint) | ||
print(checkpoint) | ||
|
||
ckpt = upgrade_checkpoint(ckpt) | ||
from pprint import pprint | ||
pprint(ckpt) |