Skip to content

Guard target_parameters use for peft<0.17.0 - #7119

Merged
albertvillanova merged 1 commit into
mainfrom
guard-target-parameters
Sep 9, 2026
Merged

albertvillanova merged 1 commit into
mainfrom
guard-target-parameters

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

LoraConfig.target_parameters only exists from peft 0.17.0, but TRL uses it unconditionally in three places. With the floor at peft>=0.13.0 (#7102), 0.13 to 0.16 are supported versions on which those paths raise.

Motivation

  • get_peft_config in trl/trainer/utils.py passes target_parameters= to LoraConfig on every call, so trl <cmd> --use_peft raises TypeError: LoraConfig.__init__() got an unexpected keyword argument 'target_parameters' on peft below 0.17. This hits all seven CLI scripts (sft, dpo, grpo, rloo, kto, reward, distillation), whether or not the user asked for --lora_target_parameters.
  • DPO, GRPO, KTO and RLOO read default_config.target_parameters before testing the peft version, so passing a pre-wrapped LoRA PeftModel raises AttributeError: 'LoraConfig' object has no attribute 'target_parameters'. Reordering alone does not fix it: the existing < 0.20.0 test is true on 0.13 to 0.16, so the attribute access still runs. The check needs a lower bound as well.
  • Six tests construct LoraConfig(target_parameters=[...]) under a bare @require_peft, so they error at construction instead of skipping.

Changes

  • get_peft_config passes target_parameters only when the user set --lora_target_parameters. No version comparison is needed: the field defaults to None in peft, so omitting it is behaviour-identical on 0.17+.
  • The four trainer guards become two-sided, Version("0.17.0") <= Version(peft.__version__) < Version("0.20.0"), with the field read last. Applied identically in all four copies, comment included.
  • New require_peft_target_parameters in tests/testing_utils.py, following the existing require_response_parsing pattern, replaces @require_peft on the six affected tests. The not is_peft_available() or ... ordering matters, since peft is imported under if is_peft_available(): and a skipif condition is evaluated at import time.

The < 0.20.0 upper bound is unchanged and stays: it encodes peft#3340, fixed by peft#3350 in 0.20.0, where a second adapter alongside target_parameters became possible. Only the lower bound is new, and it exists solely because the floor sits below 0.17.

Verification

The introducing version is counted at the release tags rather than inferred from dates. Occurrences of target_parameters in src/peft/tuners/lora/config.py:

tag occurrences
v0.15.0 0
v0.16.0 0
v0.17.0 10
v0.18.0 10

Run against a peft 0.16.0 install, each failure reproduced before the change and gone after:

peft 0.16.0 peft 0.20.1
old get_peft_config construction TypeError: unexpected keyword argument 'target_parameters' ok
new get_peft_config builds, LoraConfig identical to the old output builds, identical to the old output
old trainer condition AttributeError: 'LoraConfig' object has no attribute 'target_parameters' ok
new trainer condition False, so the ref adapter is added as before unchanged
require_peft_target_parameters skips runs

get_peft_config equivalence was checked field by field on the resulting LoraConfig for the default case, for --lora_target_parameters set, and for --lora_target_modules set. The four affected tests that do not need vLLM pass at peft 0.20.1, confirming the decorator swap did not silently disable them.


Note

Low Risk
Compatibility guards and test skips only; behavior on peft ≥ 0.17 without lora_target_parameters stays the same.

Overview
Fixes crashes on peft 0.13–0.16 where LoraConfig.target_parameters does not exist, while keeping the existing 0.17 ≤ peft < 0.20 reference-adapter workaround.

get_peft_config now passes target_parameters to LoraConfig only when --lora_target_parameters is set, so default CLI --use_peft no longer raises TypeError on older PEFT.

DPO, GRPO, KTO, and RLOO tighten the ref-adapter guard to 0.17.0 <= peft < 0.20.0 before reading default_config.target_parameters, avoiding AttributeError when a pre-wrapped PeftModel is passed on peft < 0.17.

Tests add require_peft_target_parameters (peft ≥ 0.17) and apply it to the six MoE tests that construct LoraConfig(target_parameters=...).

Reviewed by Cursor Bugbot for commit 5f2b9f7. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

bot-ci-comment Bot commented Sep 8, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec

Copy link
Copy Markdown
Member

LGTM, thanks.

get_peft_config does pass target_parameters unconditionally, so --use_peft breaks on 0.13 to 0.16 for all seven CLI scripts whether or not the flag was used. Quite surprised to see we didn't add these guard before!

@albertvillanova
albertvillanova merged commit c052919 into main Sep 9, 2026
10 checks passed
@albertvillanova
albertvillanova deleted the guard-target-parameters branch September 9, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants