Skip to content

Commit d2f0052

Browse files
committed
Add eval_start_step flag to configure initial evaluation delay
1 parent c7a5a39 commit d2f0052

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/maxtext/configs/base.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,7 @@ decode_sampling_nucleus_p: -1 # set if you're doing nucleus / top-p
983983
decode_sampling_top_k: 0 # set if you're doing top-k
984984
decode_sampling_temperature: 1.
985985

986+
eval_start_step: 0 # start eval after train step is >= eval_start_step
986987
eval_interval: -1 # the specific number of train step between eval_step
987988
eval_steps: -1 # run this number of steps for eval, recommend setting this to prevent error due to running out of evel data
988989
target_eval_loss: 0. # early stop once reaching target eval_loss

src/maxtext/configs/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,10 @@ class TrainingLoop(BaseModel):
15731573
description="Total number of training steps. -1 defaults to learning_rate_schedule_steps.",
15741574
)
15751575
log_period: int = Field(100, description="Frequency (in steps) to log metrics and flush Tensorboard.")
1576+
eval_start_step: int = Field(
1577+
0,
1578+
description="Start evaluation after training step is >= eval_start_step.",
1579+
)
15761580
eval_interval: int = Field(
15771581
-1,
15781582
description="Run evaluation every N training steps. -1 disables interval-based evaluation.",

src/maxtext/trainers/pre_train/train.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def training_loop_iteration(
669669
eval_interval = immutable_data["eval_interval"]
670670
eval_steps = immutable_data["eval_steps"]
671671
start_step = immutable_data["start_step"]
672+
eval_start_step = immutable_data["eval_start_step"]
672673

673674
# HLO dump config
674675
dump_hlo = immutable_data["dump_hlo"]
@@ -712,7 +713,7 @@ def training_loop_iteration(
712713
all_host_upload=dump_hlo_upload_all,
713714
)
714715

715-
if eval_interval > 0 and step > start_step and (step + 1) % eval_interval == 0:
716+
if eval_interval > 0 and step >= start_step and step >= eval_start_step and (step + 1) % eval_interval == 0:
716717
assert eval_data_iterator
717718
# Explicitly reset the eval iterator and counters before starting the eval loop
718719
eval_data_iterator.reset()
@@ -863,6 +864,7 @@ def train_loop(config, recorder, state=None):
863864
"steps": config.steps,
864865
"eval_interval": config.eval_interval,
865866
"eval_steps": config.eval_steps,
867+
"eval_start_step": config.eval_start_step,
866868
"save_checkpoint_on_completion": config.save_checkpoint_on_completion,
867869
"start_step": start_step,
868870
"dump_hlo": config.dump_hlo,

tests/unit/pyconfig_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,21 @@ def test_local_sa_flags_explicit_override(self):
317317
self.assertEqual(config.local_sa_v_layout, "SEQ_MINOR")
318318
self.assertFalse(config.local_use_splash_scheduler)
319319

320+
def test_eval_start_step_config(self):
321+
"""Verifies that eval_start_step defaults to 0 and can be overridden via pyconfig."""
322+
config_default = pyconfig.initialize(
323+
[os.path.join(MAXTEXT_PKG_DIR, "train.py"), get_test_config_path()],
324+
skip_jax_distributed_system=True,
325+
)
326+
self.assertEqual(config_default.eval_start_step, 0)
327+
328+
config_override = pyconfig.initialize(
329+
[os.path.join(MAXTEXT_PKG_DIR, "train.py"), get_test_config_path()],
330+
skip_jax_distributed_system=True,
331+
eval_start_step=50,
332+
)
333+
self.assertEqual(config_override.eval_start_step, 50)
334+
320335

321336
if __name__ == "__main__":
322337
unittest.main()

0 commit comments

Comments
 (0)