mirror of
https://github.com/wassname/peft.git
synced 2026-09-09 11:28:32 +08:00
revert changes
This commit is contained in:
@@ -26,7 +26,6 @@ config = LoraConfig(
|
||||
lora_alpha=32,
|
||||
lora_dropout=0.05,
|
||||
bias="none",
|
||||
task_type="VISION_2_SEQ",
|
||||
)
|
||||
|
||||
# We load our model and processor using `transformers`
|
||||
|
||||
@@ -19,7 +19,6 @@ from .peft_model import (
|
||||
PeftModelForSeq2SeqLM,
|
||||
PeftModelForSequenceClassification,
|
||||
PeftModelForTokenClassification,
|
||||
PeftModelForVision2Seq,
|
||||
)
|
||||
from .tuners import LoraConfig, PrefixTuningConfig, PromptEncoderConfig, PromptTuningConfig
|
||||
from .utils import PromptLearningConfig
|
||||
@@ -30,7 +29,6 @@ MODEL_TYPE_TO_PEFT_MODEL_MAPPING = {
|
||||
"SEQ_2_SEQ_LM": PeftModelForSeq2SeqLM,
|
||||
"CAUSAL_LM": PeftModelForCausalLM,
|
||||
"TOKEN_CLS": PeftModelForTokenClassification,
|
||||
"VISION_2_SEQ": PeftModelForVision2Seq,
|
||||
}
|
||||
|
||||
PEFT_TYPE_TO_CONFIG_MAPPING = {
|
||||
@@ -140,9 +138,6 @@ def get_peft_model(model, peft_config):
|
||||
model_config = model.config.to_dict()
|
||||
peft_config.base_model_name_or_path = model.__dict__.get("name_or_path", None)
|
||||
|
||||
if peft_config.task_type == "VISION_2_SEQ" and not isinstance(peft_config, LoraConfig):
|
||||
raise ValueError("Vision2Seq task type is only supported with LORA")
|
||||
|
||||
if peft_config.task_type not in MODEL_TYPE_TO_PEFT_MODEL_MAPPING.keys():
|
||||
peft_config = _prepare_lora_config(peft_config, model_config)
|
||||
return PeftModel(model, peft_config)
|
||||
|
||||
@@ -1034,72 +1034,3 @@ class PeftModelForTokenClassification(PeftModel):
|
||||
hidden_states=outputs.hidden_states,
|
||||
attentions=outputs.attentions,
|
||||
)
|
||||
|
||||
|
||||
class PeftModelForVision2Seq(PeftModel):
|
||||
"""
|
||||
Peft model for vision to text models.
|
||||
|
||||
Args:
|
||||
model ([`~transformers.PreTrainedModel`]): Base transformer model.
|
||||
peft_config ([`PeftConfig`]): Peft config.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
```py
|
||||
>>> from transformers import AutoModelForVision2Seq
|
||||
>>> from peft import PeftModelForVision2Seq, get_peft_config
|
||||
|
||||
>>> config = {
|
||||
... "peft_type": "LORA",
|
||||
... "task_type": "VISION_2_SEQ",
|
||||
... "inference_mode": False,
|
||||
... "r": 8,
|
||||
... "target_modules": ["q", "v"],
|
||||
... "lora_alpha": 32,
|
||||
... "lora_dropout": 0.1,
|
||||
... "merge_weights": False,
|
||||
... "fan_in_fan_out": False,
|
||||
... "enable_lora": None,
|
||||
... "bias": "none",
|
||||
... }
|
||||
|
||||
>>> peft_config = get_peft_config(config)
|
||||
>>> model = AutoModelForVision2Seq.from_pretrained("Salesforce/blip2-flan-t5-xl")
|
||||
>>> peft_model = PeftModelForVision2Seq(model, peft_config)
|
||||
>>> peft_model.print_trainable_parameters()
|
||||
trainable params: 1843200 || all params: 775873280 || trainable%: 0.23756456724479544
|
||||
```
|
||||
"""
|
||||
|
||||
def __init__(self, model, peft_config: PeftConfig):
|
||||
super().__init__(model, peft_config)
|
||||
self.base_model_prepare_inputs_for_generation = self.base_model.prepare_inputs_for_generation
|
||||
|
||||
def forward(
|
||||
self,
|
||||
pixel_values=None,
|
||||
attention_mask=None,
|
||||
decoder_input_ids=None,
|
||||
decoder_attention_mask=None,
|
||||
labels=None,
|
||||
output_attentions=None,
|
||||
output_hidden_states=None,
|
||||
return_dict=None,
|
||||
**kwargs,
|
||||
):
|
||||
r"""
|
||||
A simple wrapper around the base model's forward method.
|
||||
"""
|
||||
return self.base_model(
|
||||
pixel_values=pixel_values,
|
||||
attention_mask=attention_mask,
|
||||
decoder_input_ids=decoder_input_ids,
|
||||
decoder_attention_mask=decoder_attention_mask,
|
||||
labels=labels,
|
||||
output_attentions=output_attentions,
|
||||
output_hidden_states=output_hidden_states,
|
||||
return_dict=return_dict,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user