-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- create partition manager object - make MAP compatible - migrate to Orbax checkpointing - refactor predictive
- Loading branch information
1 parent
404840e
commit 4444907
Showing
78 changed files
with
3,479 additions
and
1,725 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,42 @@ | ||
import os | ||
from typing import Optional | ||
|
||
from flax.training import checkpoints | ||
|
||
from fortuna.calib_model.state import CalibState | ||
from fortuna.training.mixin import WithCheckpointingMixin | ||
from fortuna.training.mixins.checkpointing import WithCheckpointingMixin | ||
from fortuna.typing import ( | ||
OptaxOptimizer, | ||
Path, | ||
) | ||
|
||
# from flax.training import checkpoints | ||
|
||
class WithCalibCheckpointingMixin(WithCheckpointingMixin): | ||
def restore_checkpoint( | ||
self, | ||
restore_checkpoint_path: Path, | ||
optimizer: Optional[OptaxOptimizer] = None, | ||
prefix: str = "checkpoint_", | ||
**kwargs, | ||
) -> CalibState: | ||
if not os.path.isdir(restore_checkpoint_path) and not os.path.isfile( | ||
restore_checkpoint_path | ||
): | ||
raise ValueError( | ||
f"`restore_checkpoint_path={restore_checkpoint_path}` was not found." | ||
) | ||
d = checkpoints.restore_checkpoint( | ||
ckpt_dir=str(restore_checkpoint_path), | ||
target=None, | ||
step=None, | ||
prefix=prefix, | ||
parallel=True, | ||
) | ||
if d is None: | ||
raise ValueError( | ||
f"No checkpoint was found in `restore_checkpoint_path={restore_checkpoint_path}`." | ||
) | ||
|
||
return CalibState.init_from_dict(d, optimizer, **kwargs) | ||
|
||
class WithCalibCheckpointingMixin(WithCheckpointingMixin): | ||
pass | ||
# def restore_checkpoint( | ||
# self, | ||
# restore_checkpoint_dir: Path, | ||
# optimizer: Optional[OptaxOptimizer] = None, | ||
# prefix: str = "", | ||
# **kwargs, | ||
# ) -> CalibState: | ||
# if not os.path.isdir(restore_checkpoint_dir) and not os.path.isfile( | ||
# restore_checkpoint_dir | ||
# ): | ||
# raise ValueError( | ||
# f"`restore_checkpoint_dir={restore_checkpoint_dir}` was not found." | ||
# ) | ||
# d = checkpoints.restore_checkpoint( | ||
# ckpt_dir=str(restore_checkpoint_dir), | ||
# target=None, | ||
# step=None, | ||
# prefix=prefix, | ||
# parallel=True, | ||
# ) | ||
# if d is None: | ||
# raise ValueError( | ||
# f"No checkpoint was found in `restore_checkpoint_dir={restore_checkpoint_dir}`." | ||
# ) | ||
# | ||
# return CalibState.init_from_dict(d, optimizer, **kwargs) |
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
Oops, something went wrong.