-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add to trainer and callback API (#35)
- Loading branch information
Showing
9 changed files
with
140 additions
and
39 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
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,32 @@ | ||
import json | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import Any, Dict, Optional | ||
|
||
from olmo_core.aliases import PathOrStr | ||
from olmo_core.distributed.utils import get_rank | ||
|
||
from .callback import Callback | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@dataclass | ||
class ConfigSaverCallback(Callback): | ||
""" | ||
A callback that writes an arbitrary JSON-serializable config dictionary to every checkpoint | ||
directory written during training. | ||
""" | ||
|
||
config: Optional[Dict[str, Any]] = None | ||
fname: str = "config.json" | ||
|
||
def post_checkpoint_saved(self, path: PathOrStr): | ||
if get_rank() != 0: | ||
return | ||
|
||
if self.config is None: | ||
log.warning(f"Config not set on {self.__class__.__name__}, doing nothing") | ||
return | ||
|
||
self.trainer.write_file(self.fname, json.dumps(self.config), dir=path) |
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