Skip to content

Commit 2e81332

Browse files
Reject prompt learning in distillation before wrapping the model (#7718)
1 parent a516f43 commit 2e81332

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

‎trl/trainer/distillation_trainer.py‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@
8282

8383

8484
if is_peft_available():
85-
import peft
86-
from peft import PeftConfig, PeftModel, PrefixTuningConfig, PromptLearningConfig, get_peft_model
85+
from peft import PeftConfig, PeftModel, PromptLearningConfig, get_peft_model
8786
from peft.tuners.tuners_utils import BaseTunerLayer
8887

8988

@@ -526,17 +525,14 @@ def __init__(
526525
get_peft_model_kwargs = {}
527526
if args.deepspeed_plugin is not None and args.deepspeed_plugin.zero_stage == 3 and not _is_quantized_model:
528527
get_peft_model_kwargs["autocast_adapter_dtype"] = False
529-
# Prefix tuning moves the cache onto the model's device map, which reads `Cache.key_cache`, removed
530-
# from transformers. Fixed in PEFT 0.18.0 (peft#2821).
531-
if (
532-
isinstance(peft_config, PrefixTuningConfig)
533-
and Version(peft.__version__) <= Version("0.17.1")
534-
and hasattr(model, "hf_device_map")
535-
):
528+
# Rejected here rather than after wrapping, since `get_peft_model` itself fails on prefix tuning with
529+
# peft <= 0.17.1 (peft#2821).
530+
if isinstance(peft_config, PromptLearningConfig):
536531
raise ValueError(
537-
"Prefix tuning requires `peft>=0.18.0` when the model is loaded with a device map. Upgrade "
538-
"peft, or load the model with `device_map=None`. See "
539-
"https://github.com/huggingface/peft/issues/2821."
532+
"Prompt-learning PEFT methods (PromptTuning, PrefixTuning, P-Tuning) are not supported. The "
533+
"distillation loss bypasses `PeftModel.forward()` by calling the backbone directly, so virtual "
534+
"tokens are never prepended and the loss is computed on the wrong sequence. Use a weight-based "
535+
"adapter such as LoRA instead."
540536
)
541537
model = get_peft_model(model, peft_config, **get_peft_model_kwargs)
542538

0 commit comments

Comments
 (0)