-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override checkpointing hooks to exclude backbone while saving checkpo…
…ints (#724)
- Loading branch information
Showing
4 changed files
with
61 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Checkpointing related utilities and helper functions.""" | ||
|
||
from typing import Any, Dict | ||
|
||
|
||
def submodule_state_dict(state_dict: Dict[str, Any], submodule_key: str) -> Dict[str, Any]: | ||
"""Get the state dict of a specific submodule. | ||
Args: | ||
state_dict: The state dict to extract the submodule from. | ||
submodule_key: The key of the submodule to extract. | ||
Returns: | ||
The subset of the state dict corresponding to the specified submodule. | ||
""" | ||
submodule_key = submodule_key if submodule_key.endswith(".") else submodule_key + "." | ||
return { | ||
module: weights | ||
for module, weights in state_dict.items() | ||
if module.startswith(submodule_key) | ||
} |
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