Skip to content

Commit

Permalink
Add the option to process params with a custom function before writin…
Browse files Browse the repository at this point in the history
…g them.

PiperOrigin-RevId: 662889423
  • Loading branch information
The kauldron Authors committed Aug 16, 2024
1 parent cf84bbc commit 628e8ea
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
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

0 comments on commit 628e8ea

Please sign in to comment.