Skip to content

Commit d9f5e6e

Browse files
Merge pull request #4547 from AI-Hypercomputer:zxhe/eval_start_step
PiperOrigin-RevId: 952443710
2 parents c6085b4 + d2f0052 commit d9f5e6e

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
@@ -984,6 +984,7 @@ decode_sampling_nucleus_p: -1 # set if you're doing nucleus / top-p
984984
decode_sampling_top_k: 0 # set if you're doing top-k
985985
decode_sampling_temperature: 1.
986986

987+
eval_start_step: 0 # start eval after train step is >= eval_start_step
987988
eval_interval: -1 # the specific number of train step between eval_step
988989
eval_steps: -1 # run this number of steps for eval, recommend setting this to prevent error due to running out of evel data
989990
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
@@ -1585,6 +1585,10 @@ class TrainingLoop(BaseModel):
15851585
description="Total number of training steps. -1 defaults to learning_rate_schedule_steps.",
15861586
)
15871587
log_period: int = Field(100, description="Frequency (in steps) to log metrics and flush Tensorboard.")
1588+
eval_start_step: int = Field(
1589+
0,
1590+
description="Start evaluation after training step is >= eval_start_step.",
1591+
)
15881592
eval_interval: int = Field(
15891593
-1,
15901594
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
@@ -674,6 +674,7 @@ def training_loop_iteration(
674674
eval_interval = immutable_data["eval_interval"]
675675
eval_steps = immutable_data["eval_steps"]
676676
start_step = immutable_data["start_step"]
677+
eval_start_step = immutable_data["eval_start_step"]
677678

678679
# HLO dump config
679680
dump_hlo = immutable_data["dump_hlo"]
@@ -717,7 +718,7 @@ def training_loop_iteration(
717718
all_host_upload=dump_hlo_upload_all,
718719
)
719720

720-
if eval_interval > 0 and step > start_step and (step + 1) % eval_interval == 0:
721+
if eval_interval > 0 and step >= start_step and step >= eval_start_step and (step + 1) % eval_interval == 0:
721722
assert eval_data_iterator
722723
# Explicitly reset the eval iterator and counters before starting the eval loop
723724
eval_data_iterator.reset()
@@ -871,6 +872,7 @@ def train_loop(config, recorder, state=None):
871872
"steps": config.steps,
872873
"eval_interval": config.eval_interval,
873874
"eval_steps": config.eval_steps,
875+
"eval_start_step": config.eval_start_step,
874876
"save_checkpoint_on_completion": config.save_checkpoint_on_completion,
875877
"start_step": start_step,
876878
"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)