-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[AIR] Raise ValueError
if TorchCheckpoint
can't serialize model
#27998
Closed
Closed
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a4472e2
Add `TorchCheckpoint.from_state_dict`
bveeramani 45edb90
Address review comments
bveeramani 565a811
Merge branch 'bveeramani/torch-checkpoint-state-dict' into bveeramani…
bveeramani 4323571
Add `ValueError`
bveeramani 818462b
Fix stuff
bveeramani f0422ea
Merge branch 'bveeramani/torch-checkpoint-state-dict' into bveeramani…
bveeramani 8600fe4
Update test_torch_checkpoint.py
bveeramani 504bc0f
Update torch_checkpoint.py
bveeramani 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 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
import torch | ||
|
||
from ray.train.torch import TorchCheckpoint | ||
|
||
|
||
def test_from_state_dict(): | ||
model = torch.nn.Linear(1, 1) | ||
expected_state_dict = model.state_dict() | ||
checkpoint = TorchCheckpoint.from_state_dict(expected_state_dict) | ||
actual_state_dict = checkpoint.get_model(torch.nn.Linear(1, 1)).state_dict() | ||
assert actual_state_dict == expected_state_dict | ||
|
||
|
||
def test_from_model_value_error(): | ||
class StubModel(torch.nn.Module): | ||
__module__ = "__main__" | ||
|
||
def forward(x): | ||
return x | ||
|
||
model = StubModel() | ||
with pytest.raises(ValueError): | ||
TorchCheckpoint.from_model(model) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
sys.exit(pytest.main(["-v", "-x", __file__])) |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test makes assumptions about the implementation of
from_model
, but I wasn't sure how else to test it.