Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
83b3d69
Fix missing PEFT availability check for peft_config in exp trainers
albertvillanova Apr 27, 2026
32e8764
Fix missing PEFT availability check in BCO
albertvillanova Apr 27, 2026
34a141b
Fix missing PEFT availability check in CPO
albertvillanova Apr 27, 2026
8eb11c5
Fix missing PEFT availability check in KTO
albertvillanova Apr 27, 2026
0d6660d
Fix missing PEFT availability check in ORPO
albertvillanova Apr 27, 2026
3a62cf9
Fix missing PEFT availability check in PPO
albertvillanova Apr 27, 2026
3f3be7b
Add TypeError check to Distillation
albertvillanova Apr 27, 2026
f571155
Add TypeError check to PPO
albertvillanova Apr 27, 2026
d2664dc
Add TypeError check to TPO
albertvillanova Apr 27, 2026
e7242f3
Add TypeError check to BCO
albertvillanova Apr 27, 2026
1392892
Add TypeError check to CPO
albertvillanova Apr 27, 2026
811f87f
Add TypeError check to KTO
albertvillanova Apr 27, 2026
3d487c8
Add TypeError check to ORPO
albertvillanova Apr 27, 2026
ef4149d
Add PEFT validation to PRM
albertvillanova Apr 27, 2026
7179659
Add PEFT validation to OnlineDPO
albertvillanova Apr 27, 2026
d0a7562
Remove redundant duplicate condition check in Distillation
albertvillanova Apr 27, 2026
d236c55
Merge remote-tracking branch 'upstream/main' into fix-peft-validation…
albertvillanova Apr 27, 2026
9f2cd22
Add PEFT validation to SDFT
albertvillanova Apr 28, 2026
81cb6f2
Add PEFT validation to BaseSelfDistillation
albertvillanova Apr 28, 2026
81153c8
Add PEFT validation to SSD
albertvillanova Apr 28, 2026
70b898f
Merge remote-tracking branch 'upstream/main' into fix-peft-validation…
albertvillanova Apr 28, 2026
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
9 changes: 5 additions & 4 deletions trl/experimental/bco/bco_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ def __init__(
if isinstance(ref_model, str):
ref_model = AutoModelForCausalLM.from_pretrained(ref_model, **model_init_kwargs)

# PEFT
# Initialize this variable to False. This helps tracking the case when `peft_module_casting_to_bf16`
# has been called in order to properly call autocast if needed.
self._peft_has_been_casted_to_bf16 = False

if not is_peft_available() and peft_config is not None:
raise ValueError(
"PEFT is not installed and you passed a `peft_config` in the trainer's kwargs, please install it with `pip install peft` to use the PEFT models"
if peft_config is not None and not is_peft_available():
raise ImportError(
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
elif is_peft_available() and peft_config is not None:
if isinstance(model, PeftModel):
Expand Down
9 changes: 5 additions & 4 deletions trl/experimental/cpo/cpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,14 @@ def __init__(
if isinstance(model, str):
model = AutoModelForCausalLM.from_pretrained(model, **model_init_kwargs)

# PEFT
# Initialize this variable to False. This helps tracking the case when `peft_module_casting_to_bf16`
# has been called in order to properly call autocast if needed.
self._peft_has_been_casted_to_bf16 = False

if not is_peft_available() and peft_config is not None:
raise ValueError(
"PEFT is not installed and you passed a `peft_config` in the trainer's kwargs, please install it to use the PEFT models"
if peft_config is not None and not is_peft_available():
raise ImportError(
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
elif is_peft_available() and peft_config is not None:
if isinstance(model, PeftModel):
Expand Down
5 changes: 5 additions & 0 deletions trl/experimental/distillation/distillation_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ def __init__(
processing_class.pad_token = processing_class.eos_token

# ── PEFT ──
if peft_config is not None and not is_peft_available():
raise ImportError(
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
if peft_config is not None:
model = get_peft_model(model, peft_config)

Expand Down
9 changes: 5 additions & 4 deletions trl/experimental/kto/kto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,14 @@ def __init__(
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token

# PEFT
# Initialize this variable to False. This helps tracking the case when `peft_module_casting_to_bf16`
# has been called in order to properly call autocast if needed.
self._peft_has_been_casted_to_bf16 = False

if not is_peft_available() and peft_config is not None:
raise ValueError(
"PEFT is not installed and you passed a `peft_config` in the trainer's kwargs, please install it with `pip install peft` to use the PEFT models"
if peft_config is not None and not is_peft_available():
raise ImportError(
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
if is_peft_available() and isinstance(model, PeftModel) and peft_config is not None:
raise ValueError(
Expand Down
9 changes: 5 additions & 4 deletions trl/experimental/orpo/orpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ def __init__(
if isinstance(model, str):
model = AutoModelForCausalLM.from_pretrained(model, **model_init_kwargs)

# PEFT
# Initialize this variable to False. This helps tracking the case when `peft_module_casting_to_bf16`
# has been called in order to properly call autocast if needed.
self._peft_has_been_casted_to_bf16 = False

if not is_peft_available() and peft_config is not None:
raise ValueError(
"PEFT is not installed and you passed a `peft_config` in the trainer's kwargs, please install it to use the PEFT models"
if peft_config is not None and not is_peft_available():
raise ImportError(
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
elif is_peft_available() and peft_config is not None:
if isinstance(model, PeftModel):
Expand Down
7 changes: 4 additions & 3 deletions trl/experimental/ppo/ppo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,11 @@ def __init__(
"[Approximating KL Divergence](http://joschu.net/blog/kl-approx.html) for details."
)

# peft support
if not is_peft_available() and peft_config is not None:
# PEFT
if peft_config is not None and not is_peft_available():
raise ImportError(
"PEFT is not installed and you passed a `peft_config` in the trainer's kwargs, please install it to use the PEFT models"
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
elif is_peft_available() and peft_config is not None:
if isinstance(self.policy_model, PeftModel):
Expand Down
6 changes: 6 additions & 0 deletions trl/experimental/tpo/tpo_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ def __init__(
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token

# PEFT
if peft_config is not None and not is_peft_available():
raise ImportError(
"You passed `peft_config` but the `peft` library is not installed. "
"Install it with `pip install trl[peft]`."
)
if is_peft_available() and is_peft_model(model) and peft_config is not None:
raise ValueError(
"You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first merge "
Expand Down
Loading