Skip to content
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
8 changes: 8 additions & 0 deletions src/transformers/configuration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import json
import math
import os
import warnings
from collections.abc import Sequence
from dataclasses import MISSING, dataclass, fields
from functools import wraps
Expand Down Expand Up @@ -707,7 +708,14 @@ def rope_scaling(self):

@rope_scaling.setter
def rope_scaling(self, value):
warnings.warn(
"`rope_scaling` is deprecated and will be removed in a future version. Set `rope_parameters` "
"instead, with `rope_type` and `rope_theta` included.",
FutureWarning,
)
self.rope_parameters = value
if value is not None:
self.standardize_rope_params()

def save_pretrained(self, save_directory: str | os.PathLike, push_to_hub: bool = False, **kwargs):
"""
Expand Down
23 changes: 23 additions & 0 deletions tests/utils/test_modeling_rope_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging as stdlib_logging
import math
import unittest
import warnings

from parameterized import parameterized

Expand All @@ -38,6 +39,28 @@

@require_torch
class RopeTest(unittest.TestCase):
def test_rope_scaling_setter_is_deprecated(self):
config = LlamaConfig(rope_theta=500000.0)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
config.rope_scaling = {
"type": "yarn",
"factor": 4.0,
"rope_theta": 500000.0,
"original_max_position_embeddings": 4096,
}
self.assertTrue(any(issubclass(w.category, FutureWarning) for w in caught))
self.assertEqual(config.rope_parameters["rope_type"], "yarn")
LlamaRotaryEmbedding(config)

def test_rope_scaling_setter_accepts_none(self):
config = LlamaConfig(rope_theta=500000.0)
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
config.rope_scaling = None
self.assertTrue(any(issubclass(w.category, FutureWarning) for w in caught))
self.assertIsNone(config.rope_parameters)

def get_config_with_rope_parameters(
self, rope_params: dict, is_nested: bool = False, same_rope_per_layer: bool = False
):
Expand Down
Loading