Skip to content

Commit 9ec847f

Browse files
committed
Add DPO correctness integration test and respect dpo.max_prompt_length in train_dpo.py
1 parent 32ee21e commit 9ec847f

3 files changed

Lines changed: 511 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,4 @@ gha-creds-*.json
155155

156156
# vscode workspace
157157
maxtext.code-workspace
158+
maxtext_output/

src/maxtext/trainers/post_train/dpo/train_dpo.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
)
5050
from maxtext.configs import pyconfig
5151
from maxtext.configs.types import MaxTextConfig
52+
from maxtext.input_pipeline import tokenizer
5253
from maxtext.optimizers import optimizers
5354
from maxtext.trainers.post_train.dpo import hooks
5455
from maxtext.utils import max_logging
@@ -90,7 +91,7 @@ def get_tunix_config(mt_config: MaxTextConfig) -> DPOTrainingConfig:
9091
set_profile_options=set_profile_options,
9192
)
9293

93-
max_prompt_length = mt_config.max_target_length // 2
94+
max_prompt_length = mt_config.dpo.max_prompt_length or (mt_config.max_target_length // 2)
9495
return DPOTrainingConfig(
9596
eval_every_n_steps=mt_config.eval_interval,
9697
max_steps=mt_config.steps,
@@ -113,7 +114,18 @@ def setup_trainer_state(mt_config, goodput_recorder=None):
113114
tunix_config = get_tunix_config(mt_config)
114115

115116
with maybe_record_goodput(goodput_recorder, GoodputEvent.TPU_INIT):
116-
model, mesh = model_creation_utils.from_pretrained(mt_config, wrap_with_tunix_adapter=True)
117+
tok = tokenizer.build_tokenizer(
118+
mt_config.tokenizer_path,
119+
mt_config.tokenizer_type,
120+
False,
121+
False,
122+
mt_config.hf_access_token,
123+
)
124+
model, mesh = model_creation_utils.from_pretrained(
125+
mt_config,
126+
wrap_with_tunix_adapter=True,
127+
tokenizer_pad_id=tok.pad_id,
128+
)
117129

118130
learning_rate_schedule = maxtext_utils.create_learning_rate_schedule(mt_config)
119131
# pass in model for muon

0 commit comments

Comments
 (0)