Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/test_dpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,25 @@ def test_train_with_liger(self):
new_param = trainer.model.get_parameter(n)
assert not torch.equal(param, new_param), f"Parameter {n} has not changed."

@require_liger_kernel
@require_peft
def test_init_fails_with_peft_and_liger(self):
dataset = load_dataset("trl-internal-testing/zen", "standard_preference", split="train")

training_args = DPOConfig(
output_dir=self.tmp_dir,
use_liger_kernel=True,
report_to="none",
)

with pytest.raises(NotImplementedError, match="Liger DPO loss is not implemented for PEFT models."):
DPOTrainer(
model="trl-internal-testing/tiny-Qwen2ForCausalLM-2.5",
args=training_args,
train_dataset=dataset,
peft_config=LoraConfig(),
)

def test_train_with_iterable_dataset(self):
dataset = load_dataset("trl-internal-testing/zen", "standard_preference", split="train", streaming=True)

Expand Down
19 changes: 9 additions & 10 deletions trl/trainer/dpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ def __init__(
"Liger DPO loss does not support precomputing reference log probabilities. Either disable "
"`precompute_ref_log_probs` or set `use_liger_kernel` to False."
)
if is_peft_model(model):
raise NotImplementedError("Liger DPO loss is not implemented for PEFT models.")
Comment on lines +712 to +713

@qgallouedec qgallouedec May 6, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could remove this then?

trl/trl/trainer/dpo_trainer.py

Lines 1101 to 1102 in 62a66af

if is_peft_model(model):
raise NotImplementedError("Liger DPO loss is not implemented for PEFT models.")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the same! But codex told me to keep it... I should have followed my intuition.


# Dataset
# Skip dataset preparation if it's a VLM, where preprocessing (e.g., image-to-pixel conversion) is too costly
Expand Down Expand Up @@ -1096,16 +1098,13 @@ def _compute_loss_liger(self, model, inputs, return_outputs):
weight = lm_head.weight
bias = lm_head.bias

if is_peft_model(model):
raise NotImplementedError("Liger DPO loss is not implemented for PEFT models.")
else:
with torch.no_grad(), disable_gradient_checkpointing(self.model, self.args.gradient_checkpointing_kwargs):
ref_decoder = self.ref_model.get_decoder()
ref_outputs = ref_decoder(input_ids, attention_mask=attention_mask, use_cache=False)
ref_lm_head = self.ref_model.get_output_embeddings()
ref_hidden_states = ref_outputs.last_hidden_state[:, :-1].contiguous()
ref_weight = ref_lm_head.weight
ref_bias = ref_lm_head.bias
with torch.no_grad(), disable_gradient_checkpointing(self.model, self.args.gradient_checkpointing_kwargs):
ref_decoder = self.ref_model.get_decoder()
ref_outputs = ref_decoder(input_ids, attention_mask=attention_mask, use_cache=False)
ref_lm_head = self.ref_model.get_output_embeddings()
ref_hidden_states = ref_outputs.last_hidden_state[:, :-1].contiguous()
ref_weight = ref_lm_head.weight
ref_bias = ref_lm_head.bias

shift_completion_mask = completion_mask[:, 1:].contiguous()
labels = input_ids[:, 1:].clone()
Expand Down
Loading