From 83b3d6934620544eb44849e67e4488e1a56a7f30 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:49:03 +0200 Subject: [PATCH 01/19] Fix missing PEFT availability check for peft_config in exp trainers --- trl/experimental/distillation/distillation_trainer.py | 5 +++++ trl/experimental/tpo/tpo_trainer.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/trl/experimental/distillation/distillation_trainer.py b/trl/experimental/distillation/distillation_trainer.py index 77dbcc6c08e..ebd7ce1e1b1 100644 --- a/trl/experimental/distillation/distillation_trainer.py +++ b/trl/experimental/distillation/distillation_trainer.py @@ -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]`." + ) if peft_config is not None: model = get_peft_model(model, peft_config) diff --git a/trl/experimental/tpo/tpo_trainer.py b/trl/experimental/tpo/tpo_trainer.py index 544c0674cca..57478a6281d 100644 --- a/trl/experimental/tpo/tpo_trainer.py +++ b/trl/experimental/tpo/tpo_trainer.py @@ -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 " From 32e87641e9988c793d22f7ad202fb4e9441643a0 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:27:31 +0200 Subject: [PATCH 02/19] Fix missing PEFT availability check in BCO --- trl/experimental/bco/bco_trainer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/trl/experimental/bco/bco_trainer.py b/trl/experimental/bco/bco_trainer.py index 9cdf47c65ee..099d3b5436f 100644 --- a/trl/experimental/bco/bco_trainer.py +++ b/trl/experimental/bco/bco_trainer.py @@ -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): From 34a141b8772691f705d74d80dbd4f208a8e5cdb8 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:27:44 +0200 Subject: [PATCH 03/19] Fix missing PEFT availability check in CPO --- trl/experimental/cpo/cpo_trainer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/trl/experimental/cpo/cpo_trainer.py b/trl/experimental/cpo/cpo_trainer.py index f3e0f39920e..c403951eb7a 100644 --- a/trl/experimental/cpo/cpo_trainer.py +++ b/trl/experimental/cpo/cpo_trainer.py @@ -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): From 8eb11c56ad7246e3eb9b440487c62ee9856f019e Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:28:15 +0200 Subject: [PATCH 04/19] Fix missing PEFT availability check in KTO --- trl/experimental/kto/kto_trainer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/trl/experimental/kto/kto_trainer.py b/trl/experimental/kto/kto_trainer.py index 14359f8bd70..f6d989923f1 100644 --- a/trl/experimental/kto/kto_trainer.py +++ b/trl/experimental/kto/kto_trainer.py @@ -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( From 0d6660d94e787dcb434a3db5890bfa3df2bf5bb9 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:28:28 +0200 Subject: [PATCH 05/19] Fix missing PEFT availability check in ORPO --- trl/experimental/orpo/orpo_trainer.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/trl/experimental/orpo/orpo_trainer.py b/trl/experimental/orpo/orpo_trainer.py index 59d7636efb7..04a870dfb2d 100644 --- a/trl/experimental/orpo/orpo_trainer.py +++ b/trl/experimental/orpo/orpo_trainer.py @@ -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): From 3a62cf986c3c2a666fb93b7133eff806f4ec56a3 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:28:37 +0200 Subject: [PATCH 06/19] Fix missing PEFT availability check in PPO --- trl/experimental/ppo/ppo_trainer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/trl/experimental/ppo/ppo_trainer.py b/trl/experimental/ppo/ppo_trainer.py index 6366f987ec4..1432a06861f 100644 --- a/trl/experimental/ppo/ppo_trainer.py +++ b/trl/experimental/ppo/ppo_trainer.py @@ -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): From 3f3be7b94fcb65bd715223895261b8601bc7b24d Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:01:57 +0200 Subject: [PATCH 07/19] Add TypeError check to Distillation --- .../distillation/distillation_trainer.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/trl/experimental/distillation/distillation_trainer.py b/trl/experimental/distillation/distillation_trainer.py index ebd7ce1e1b1..02bb625cd1f 100644 --- a/trl/experimental/distillation/distillation_trainer.py +++ b/trl/experimental/distillation/distillation_trainer.py @@ -429,11 +429,17 @@ 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]`." - ) + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if peft_config is not None: model = get_peft_model(model, peft_config) From f5711555025ff6aa155a2cb9bceefa7cce07226a Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:02:17 +0200 Subject: [PATCH 08/19] Add TypeError check to PPO --- trl/experimental/ppo/ppo_trainer.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/trl/experimental/ppo/ppo_trainer.py b/trl/experimental/ppo/ppo_trainer.py index 1432a06861f..0d3e32f0a46 100644 --- a/trl/experimental/ppo/ppo_trainer.py +++ b/trl/experimental/ppo/ppo_trainer.py @@ -417,12 +417,17 @@ def __init__( ) # 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]`." - ) - elif is_peft_available() and peft_config is not None: + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if isinstance(self.policy_model, PeftModel): raise ValueError( "You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first " From d2664dc2285ce069575e5b9420085693ea5a89bc Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:02:31 +0200 Subject: [PATCH 09/19] Add TypeError check to TPO --- trl/experimental/tpo/tpo_trainer.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/trl/experimental/tpo/tpo_trainer.py b/trl/experimental/tpo/tpo_trainer.py index 57478a6281d..7195596e15c 100644 --- a/trl/experimental/tpo/tpo_trainer.py +++ b/trl/experimental/tpo/tpo_trainer.py @@ -351,11 +351,17 @@ def __init__( 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 peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) 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 " From e7242f34a91abe44d77665440055021ee8570791 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:06:23 +0200 Subject: [PATCH 10/19] Add TypeError check to BCO --- trl/experimental/bco/bco_trainer.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/trl/experimental/bco/bco_trainer.py b/trl/experimental/bco/bco_trainer.py index 099d3b5436f..a5a10725ae0 100644 --- a/trl/experimental/bco/bco_trainer.py +++ b/trl/experimental/bco/bco_trainer.py @@ -65,7 +65,7 @@ if is_peft_available(): - from peft import PeftModel, get_peft_model, prepare_model_for_kbit_training + from peft import PeftConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training if is_wandb_available(): import wandb @@ -473,12 +473,17 @@ def __init__( # 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 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 peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if isinstance(model, PeftModel): raise ValueError( "You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first " From 1392892a76254ffd0061c28052fa1735d7e559a5 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:06:43 +0200 Subject: [PATCH 11/19] Add TypeError check to CPO --- trl/experimental/cpo/cpo_trainer.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/trl/experimental/cpo/cpo_trainer.py b/trl/experimental/cpo/cpo_trainer.py index c403951eb7a..432c0bfd070 100644 --- a/trl/experimental/cpo/cpo_trainer.py +++ b/trl/experimental/cpo/cpo_trainer.py @@ -61,7 +61,7 @@ if is_peft_available(): - from peft import PeftModel, get_peft_model, prepare_model_for_kbit_training + from peft import PeftConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training if is_wandb_available(): @@ -173,12 +173,17 @@ def __init__( # 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 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 peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if isinstance(model, PeftModel): raise ValueError( "You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first " From 811f87f3ac159382e5866f9664010b2315c3c51e Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:07:07 +0200 Subject: [PATCH 12/19] Add TypeError check to KTO --- trl/experimental/kto/kto_trainer.py | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/trl/experimental/kto/kto_trainer.py b/trl/experimental/kto/kto_trainer.py index f6d989923f1..757fbad8a68 100644 --- a/trl/experimental/kto/kto_trainer.py +++ b/trl/experimental/kto/kto_trainer.py @@ -67,7 +67,7 @@ from liger_kernel.chunked_loss import LigerFusedLinearKTOLoss if is_peft_available(): - from peft import PeftModel, get_peft_model, prepare_model_for_kbit_training + from peft import PeftConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training if TYPE_CHECKING: @@ -293,17 +293,23 @@ def __init__( # 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 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( - "You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first merge " - "and unload the existing adapter, save the resulting base model, and then pass that base model along " - "with the new `peft_config` to the trainer." - ) + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) + if isinstance(model, PeftModel): + raise ValueError( + "You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first merge " + "and unload the existing adapter, save the resulting base model, and then pass that base model along " + "with the new `peft_config` to the trainer." + ) if is_peft_available() and isinstance(model, PeftModel) and ref_model is None: # If the model is a PEFT model with a pretrained adapter, we need to create a "ref" adapter that is a copy # of the "default" adapter, so that we can use it as the reference model during KTO training. From 3d487c81f396f8d97974e1bb591bf920213d9875 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:07:30 +0200 Subject: [PATCH 13/19] Add TypeError check to ORPO --- trl/experimental/orpo/orpo_trainer.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/trl/experimental/orpo/orpo_trainer.py b/trl/experimental/orpo/orpo_trainer.py index 04a870dfb2d..22e6a81fbf6 100644 --- a/trl/experimental/orpo/orpo_trainer.py +++ b/trl/experimental/orpo/orpo_trainer.py @@ -62,7 +62,7 @@ if is_peft_available(): - from peft import PeftModel, get_peft_model, prepare_model_for_kbit_training + from peft import PeftConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training if is_wandb_available(): @@ -182,12 +182,17 @@ def __init__( # 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 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 peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if isinstance(model, PeftModel): raise ValueError( "You passed a `PeftModel` instance together with a `peft_config` to the trainer. Please first " From ef4149df75ad7b9d67eb2ea13e148c12453da250 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:08:58 +0200 Subject: [PATCH 14/19] Add PEFT validation to PRM --- trl/experimental/prm/prm_trainer.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/trl/experimental/prm/prm_trainer.py b/trl/experimental/prm/prm_trainer.py index 7b26b69bd82..c6bf17ad453 100644 --- a/trl/experimental/prm/prm_trainer.py +++ b/trl/experimental/prm/prm_trainer.py @@ -44,7 +44,7 @@ if is_peft_available(): - from peft import PeftModel + from peft import PeftConfig, PeftModel logger = logging.get_logger(__name__) @@ -172,6 +172,18 @@ def __init__( if train_dataset is None: raise ValueError("`train_dataset` is required") + # PEFT + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if peft_config is not None or (is_peft_available() and isinstance(model, PeftModel)): model = prepare_peft_model(model, peft_config, args) From 7179659c5019ec6a3b4d5beba260f87bcc7d33c3 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:09:22 +0200 Subject: [PATCH 15/19] Add PEFT validation to OnlineDPO --- trl/experimental/online_dpo/online_dpo_trainer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trl/experimental/online_dpo/online_dpo_trainer.py b/trl/experimental/online_dpo/online_dpo_trainer.py index 4c7adef3b6d..5cb73fbcc83 100644 --- a/trl/experimental/online_dpo/online_dpo_trainer.py +++ b/trl/experimental/online_dpo/online_dpo_trainer.py @@ -282,6 +282,18 @@ def __init__( self.is_encoder_decoder = model.config.is_encoder_decoder self.is_vision_model = model.config.model_type in MODEL_FOR_IMAGE_TEXT_TO_TEXT_MAPPING_NAMES.keys() + # PEFT + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if peft_config is not None or (is_peft_available() and isinstance(model, PeftModel)): model = prepare_peft_model(model, peft_config, args) From d0a75622e52e8736230351d59938413ed6a3f54e Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:27:03 +0200 Subject: [PATCH 16/19] Remove redundant duplicate condition check in Distillation --- trl/experimental/distillation/distillation_trainer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/trl/experimental/distillation/distillation_trainer.py b/trl/experimental/distillation/distillation_trainer.py index 02bb625cd1f..f80dd19358a 100644 --- a/trl/experimental/distillation/distillation_trainer.py +++ b/trl/experimental/distillation/distillation_trainer.py @@ -440,7 +440,6 @@ def __init__( f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " f"got {type(peft_config).__name__}." ) - if peft_config is not None: model = get_peft_model(model, peft_config) # ── Data collator ── From 9f2cd225e2ac89dfa434726e4b495e55a646a839 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Tue, 28 Apr 2026 08:08:58 +0200 Subject: [PATCH 17/19] Add PEFT validation to SDFT --- trl/experimental/sdft/sdft_trainer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trl/experimental/sdft/sdft_trainer.py b/trl/experimental/sdft/sdft_trainer.py index 5bf6095c2a0..a4be9b395fe 100644 --- a/trl/experimental/sdft/sdft_trainer.py +++ b/trl/experimental/sdft/sdft_trainer.py @@ -195,6 +195,18 @@ def __init__( else inspect.signature(model.get_base_model().forward).parameters.keys() ) + # PEFT + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) 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 SDFTTrainer. Pass either a base " From 81cb6f213d771af17b06b32462c89dc2d70b6647 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Tue, 28 Apr 2026 08:09:10 +0200 Subject: [PATCH 18/19] Add PEFT validation to BaseSelfDistillation --- .../base_self_distillation_trainer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trl/experimental/self_distillation/base_self_distillation_trainer.py b/trl/experimental/self_distillation/base_self_distillation_trainer.py index bd9abb95164..5484a2efb66 100644 --- a/trl/experimental/self_distillation/base_self_distillation_trainer.py +++ b/trl/experimental/self_distillation/base_self_distillation_trainer.py @@ -104,6 +104,18 @@ def __init__( else inspect.signature(model.get_base_model().forward).parameters.keys() ) + # PEFT + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) if peft_config is not None or (is_peft_available() and getattr(model, "peft_config", None) is not None): model = prepare_peft_model(model, peft_config, args) From 81153c80548c9860004f41599a905262de08ef38 Mon Sep 17 00:00:00 2001 From: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> Date: Tue, 28 Apr 2026 08:09:23 +0200 Subject: [PATCH 19/19] Add PEFT validation to SSD --- trl/experimental/ssd/ssd_trainer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trl/experimental/ssd/ssd_trainer.py b/trl/experimental/ssd/ssd_trainer.py index ea378753653..91a0275047a 100644 --- a/trl/experimental/ssd/ssd_trainer.py +++ b/trl/experimental/ssd/ssd_trainer.py @@ -135,6 +135,18 @@ def __init__( else inspect.signature(model.get_base_model().forward).parameters.keys() ) + # PEFT + if peft_config is not None: + if 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 not isinstance(peft_config, PeftConfig): + raise TypeError( + f"`peft_config` must be a `peft.PeftConfig` instance (e.g. `peft.LoraConfig`), " + f"got {type(peft_config).__name__}." + ) 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 SSDTrainer. Pass either a base "