Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 9 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 @@ -713,7 +714,15 @@ 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,
)
if value is None:
return
self.rope_parameters = value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should set None if asked - just not ry to standardize :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b84f86d: None is assigned as-is (rope_parameters becomes None) and standardize_rope_params() only runs for a dict; the None test now asserts that. 37 pass locally.

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_ignores_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.assertEqual(config.rope_parameters["rope_theta"], 500000.0)

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