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

Add the option to process params with a custom function before writing them. #803

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion kauldron/train/train_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def train_impl(
# `NoopWriter`, the second one is mandatory in order to re-load the model
# for evals/inference.
writer.write_config(trainer.raw_cfg)
writer.write_param_overview(initial_step, state.params)
writer.write_param_overview(initial_step, trainer.process_params_for_writing(state.params))
writer.write_element_spec(initial_step, ds_iter.element_spec)
writer.write_context_structure(initial_step, trainer)

Expand Down
6 changes: 5 additions & 1 deletion kauldron/train/trainer_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import dataclasses
import functools
import typing
from typing import Any, Optional, Self
from typing import Any, Callable, Optional, Self

from etils import edc
from etils import epath
Expand Down Expand Up @@ -237,6 +237,10 @@ class Trainer(config_util.BaseConfig):
default=None, repr=False
)

process_params_for_writing: Callable[[Any], Any] = dataclasses.field(
default=lambda x: x, repr=False
)

def __post_init__(self):
# It's convenient to set `cfg.evals = None` to disable evaluation
for name, default_factory in {
Expand Down