Skip to content
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

Fix backwards compatibility tests, raise error for torch version mismatch #3252

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion composer/utils/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,16 @@ def load_sharded_checkpoint(
# 1. Load metadata first for backwards compatability check
# We need to check if the "optimizers" is at the root of the state dict to determine
# how to load the optimizer state.
metadata = storage_reader.read_metadata()
try:
metadata = storage_reader.read_metadata()
except AttributeError as e:
if '_MEM_FORMAT_ENCODING' in str(e):
raise ValueError(
'Unable to read checkpoint metadata. The checkpoint was likely saved with a '
'newer version of torch. Upgrade your torch version to load this checkpoint.',
)
else:
raise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhh this is a bug right? You need to have raise e?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also do raise like this to reraise the error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah
Screenshot 2024-05-06 at 2 38 43 PM

# Retrieve all top-level keys of the metadata.
top_level_keys = [v[0] for v in metadata.planner_data.values()]
optimizers_at_root = 'optimizers' in top_level_keys
Expand Down
3 changes: 3 additions & 0 deletions tests/trainer/test_fsdp_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ def test_fsdp_load_old_checkpoint(
if composer_version == '0.18.1' and state_dict_type == 'full' and precision == 'amp_bf16' and sharding_strategy == 'FULL_SHARD':
pytest.skip('TODO: This checkpoint is missing')

if composer_version in ['0.22.0'] and version.parse(torch.__version__) < version.parse('2.3.0'):
pytest.skip('Current torch version is older than torch version that checkpoint was written with.')

if composer_version in ['0.13.5', '0.14.0', '0.14.1', '0.15.1']:
rank = 0 if state_dict_type == 'full' else '{rank}'

Expand Down
Loading