Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Skip adaption prompt tests with new transformers versions #1077

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions src/peft/tuners/adaption_prompt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib
from collections import namedtuple
from dataclasses import dataclass, field

from packaging.version import parse

from peft.config import PeftConfig
from peft.utils import PeftType

from .utils import llama_compute_query_states


MAX_TRANSFORMERS_VERSION = "4.35.0"


def is_transformers_version_ge(version: str) -> bool:
return parse(importlib.metadata.version("transformers")) >= parse(version)


@dataclass
class AdaptionPromptConfig(PeftConfig):
"""Stores the configuration of an [`AdaptionPromptModel`]."""
Expand All @@ -33,6 +43,13 @@ class AdaptionPromptConfig(PeftConfig):
adapter_layers: int = field(default=None, metadata={"help": "Number of adapter layers (from the top)"})

def __post_init__(self):
# TODO: Remove this check and function once PEFT works again with newest transformers version.
# Also remove the skip in test_adaption_prompt.py and uncomment the adaption prompt config in test_config.py.
if is_transformers_version_ge(MAX_TRANSFORMERS_VERSION):
raise ValueError(
f"Adaption prompt is not compatible with transformers >= {MAX_TRANSFORMERS_VERSION}, "
"please use an older version of transformers until this is fixed."
)
self.peft_type = PeftType.ADAPTION_PROMPT

@property
Expand Down
8 changes: 7 additions & 1 deletion tests/test_adaption_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ class AdaptionPromptTester(TestCase, PeftCommonTester):
"""

def setUp(self):
"""Check that llama is available in transformers package before running each test."""
# TODO: remove the imports and version check once PEFT works again with transformers
from peft.tuners.adaption_prompt.config import MAX_TRANSFORMERS_VERSION, is_transformers_version_ge

if is_transformers_version_ge(MAX_TRANSFORMERS_VERSION):
self.skipTest("Adaption prompt is currently failing on transformers 4.35.0, skipping test.")

# Check that llama is available in transformers package before running each test.
if not is_llama_available():
self.skipTest("Llama not available in transformers. Skipping test.")

Expand Down
6 changes: 4 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

from peft import (
AdaLoraConfig,
AdaptionPromptConfig,
# TODO: uncomment once PEFT works again with transformers
# AdaptionPromptConfig,
IA3Config,
LoHaConfig,
LoraConfig,
Expand All @@ -40,7 +41,8 @@
PEFT_MODELS_TO_TEST = [("lewtun/tiny-random-OPTForCausalLM-delta", "v1")]

ALL_CONFIG_CLASSES = (
AdaptionPromptConfig,
# TODO: uncomment once PEFT works again with transformers
# AdaptionPromptConfig,
AdaLoraConfig,
IA3Config,
LoHaConfig,
Expand Down