-
Notifications
You must be signed in to change notification settings - Fork 3.6k
add legacy load utility #9166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add legacy load utility #9166
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
89131c2
class name as key
awaelchli 63fb983
string state identifier
awaelchli 7dc218a
add legacy state loading
awaelchli 04b588b
update test
awaelchli bb11e28
update tests
awaelchli 271360c
Merge branch 'master' into bugfix/callback-state
awaelchli 20b66f0
Merge branch 'master' into bugfix/callback-state
awaelchli f585a28
Merge branch 'master' into bugfix/callback-state
awaelchli e1d518b
Merge branch 'master' into bugfix/callback-state
awaelchli 880066b
Merge branch 'master' into bugfix/callback-state
awaelchli 0259ecb
flake8
awaelchli d56e5e4
add test
awaelchli 24a2cc8
Merge branch 'master' into bugfix/callback-state
awaelchli 81b5e36
Merge branch 'master' into bugfix/callback-state
carmocca 72ba440
Apply suggestions from code review
awaelchli 79d8568
improve test
awaelchli d9ea8c1
flake
awaelchli 98f7fe6
Merge branch 'master' into bugfix/callback-state
awaelchli 68f571c
Merge branch 'master' into bugfix/callback-state
awaelchli 0851f0d
fix merge
awaelchli 82d5658
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 334fd4a
use qualname
awaelchli 090b169
Merge remote-tracking branch 'origin/bugfix/callback-state' into bugf…
awaelchli f144fd1
rename state_id
awaelchli 6154986
fix diff
awaelchli 17459fe
suboptimal
awaelchli f84d047
clean up
awaelchli d4dc3b3
migrate checkpoint on load
awaelchli 2620069
update legacy patching
awaelchli 97cba29
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d1365a1
reset
awaelchli 3caf982
Merge branch 'master' into feature/migration-utils
awaelchli 4b2f70c
apply black
awaelchli f23b57b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a1bed7e
reset branch
awaelchli 60a9ca6
reset branch
awaelchli 9c011a9
add docs
awaelchli 314cc33
add docs and licence
awaelchli ade1bbd
remove obsolete warning
awaelchli fcdce4f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b7ffa17
Merge branch 'master' into feature/callback-state/migration-utils
awaelchli 900e415
update legacy load
awaelchli 5250006
Merge branch 'master' into feature/callback-state/migration-utils
awaelchli e177bf1
reset branch
awaelchli d8d96c0
add tests
awaelchli 30203ba
update load from checkpoint call
awaelchli 0babb5c
rm notebooks
awaelchli 2db2719
reset notebook
awaelchli 3d29350
Update pytorch_lightning/utilities/argparse.py
awaelchli 9cc44fe
update changelog
awaelchli 5e48576
remove test for 1.4 deprecation
awaelchli ffffd81
Merge branch 'master' into feature/callback-state/legacy
awaelchli a7cea9e
update changelog
awaelchli 493d018
add assert to prevent "unused import" complaint
awaelchli ba8af7a
Merge branch 'master' into feature/callback-state/legacy
awaelchli 7d7d401
Merge branch 'master' into feature/callback-state/legacy
Borda 3578e6f
Merge branch 'master' into feature/callback-state/legacy
awaelchli bf1fc8a
Merge branch 'master' into feature/callback-state/legacy
awaelchli bed8808
update changelog
awaelchli a4a8eb4
rm notebook
awaelchli 20ab34a
update notebook
awaelchli dd4532a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fae11ff
move context manager to _load_and_validate method
awaelchli 3e43cb1
Merge remote-tracking branch 'origin/feature/callback-state/legacy' i…
awaelchli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright The PyTorch Lightning team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
from types import ModuleType | ||
|
||
import pytorch_lightning.utilities.argparse | ||
|
||
|
||
class pl_legacy_patch: | ||
"""Registers legacy artifacts (classes, methods, etc.) that were removed but still need to be included for | ||
unpickling old checkpoints. The following patches apply. | ||
|
||
1. ``pytorch_lightning.utilities.argparse._gpus_arg_default``: Applies to all checkpoints saved prior to | ||
version 1.2.8. See: https://github.com/PyTorchLightning/pytorch-lightning/pull/6898 | ||
2. ``pytorch_lightning.utilities.argparse_utils``: A module that was deprecated in 1.2 and removed in 1.4, | ||
but still needs to be available for import for legacy checkpoints. | ||
|
||
Example: | ||
|
||
with pl_legacy_patch(): | ||
torch.load("path/to/legacy/checkpoint.ckpt") | ||
""" | ||
|
||
def __enter__(self): | ||
# `pl.utilities.argparse_utils` was renamed to `pl.utilities.argparse` | ||
awaelchli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
legacy_argparse_module = ModuleType("pytorch_lightning.utilities.argparse_utils") | ||
sys.modules["pytorch_lightning.utilities.argparse_utils"] = legacy_argparse_module | ||
|
||
# `_gpus_arg_default` used to be imported from these locations | ||
legacy_argparse_module._gpus_arg_default = lambda x: x | ||
pytorch_lightning.utilities.argparse._gpus_arg_default = lambda x: x | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, exc_traceback): | ||
if hasattr(pytorch_lightning.utilities.argparse, "_gpus_arg_default"): | ||
delattr(pytorch_lightning.utilities.argparse, "_gpus_arg_default") | ||
del sys.modules["pytorch_lightning.utilities.argparse_utils"] |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright The PyTorch Lightning team. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import sys | ||
|
||
import pytorch_lightning | ||
from pytorch_lightning.utilities.migration import pl_legacy_patch | ||
|
||
|
||
def test_patch_legacy_argparse_utils(): | ||
with pl_legacy_patch(): | ||
from pytorch_lightning.utilities import argparse_utils | ||
|
||
assert callable(argparse_utils._gpus_arg_default) | ||
assert "pytorch_lightning.utilities.argparse_utils" in sys.modules | ||
|
||
assert "pytorch_lightning.utilities.argparse_utils" not in sys.modules | ||
|
||
|
||
def test_patch_legacy_gpus_arg_default(): | ||
with pl_legacy_patch(): | ||
from pytorch_lightning.utilities.argparse import _gpus_arg_default | ||
|
||
assert callable(_gpus_arg_default) | ||
assert not hasattr(pytorch_lightning.utilities.argparse, "_gpus_arg_default") | ||
assert not hasattr(pytorch_lightning.utilities.argparse, "_gpus_arg_default") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.