Skip to content

Commit bec4612

Browse files
committed
fix dpo continue training setting.
1 parent da43914 commit bec4612

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎erniekit/train/dpo/workflow.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,15 @@ def run_dpo(
270270
model_class = Ernie4_5_MoeForCausalLMPipe
271271
else:
272272
model_class = Ernie4_5_MoeForCausalLM
273-
if model_args.continue_training and finetuning_args.weight_quantize_algo is not None:
273+
274+
if model_args.continue_training:
274275
model = model_class.from_pretrained(model_args.model_name_or_path, config=config)
275276
# for DPO save
276277
if not finetuning_args.reference_free and not model_args.lora:
277-
ref_model = model_class._from_config(config, dtype=dtype)
278+
# (LiuTing): config.moe_group will change in `model_class.from_pretrained`
279+
# so need to re-create new ref_config.
280+
ref_config = Ernie4_5_MoeConfig.from_pretrained(**model_kwargs)
281+
ref_model = model_class._from_config(ref_config, dtype=dtype)
278282
ref_model.set_state_dict(model.state_dict())
279283
else:
280284
ref_model = None

‎examples/post-training/dpo/dpo_train.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,14 @@ def main():
256256
model_class = Ernie4_5_MoeForCausalLMPipe
257257
else:
258258
model_class = Ernie4_5_MoeForCausalLM
259-
if model_args.continue_training and model_args.weight_quantize_algo is not None:
259+
if model_args.continue_training:
260260
model = model_class.from_pretrained(model_args.model_name_or_path, config=config)
261261
# for DPO save
262262
if not dpo_config.reference_free and not dpo_config.lora:
263-
ref_model = model_class._from_config(config, dtype=dtype)
263+
# (LiuTing): config.moe_group will change in `model_class.from_pretrained`
264+
# so need to re-create new ref_config.
265+
ref_config = Ernie4_5_MoeConfig.from_pretrained(**model_kwargs)
266+
ref_model = model_class._from_config(ref_config, dtype=dtype)
264267
ref_model.set_state_dict(model.state_dict())
265268
else:
266269
ref_model = None

0 commit comments

Comments
 (0)