diff --git a/src/python/py/models/builders/base.py b/src/python/py/models/builders/base.py index 9c30b0a82a..2b37f20070 100644 --- a/src/python/py/models/builders/base.py +++ b/src/python/py/models/builders/base.py @@ -3,7 +3,7 @@ # Licensed under the MIT License. See License.txt in the project root for # license information. # -# Copyright (C) [2026] Advanced Micro Devices, Inc. All rights reserved. +# Modifications Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. # Portions of this file consist of AI generated content. # -------------------------------------------------------------------------- from __future__ import annotations @@ -466,6 +466,17 @@ def make_rope_init(self, config): "ntk_beta": beta_fast, } + elif ( + config.rope_scaling.get("rope_type", config.rope_scaling.get("type")) == "linear" + and "factor" in config.rope_scaling + ): + # Hugging Face: modeling_rope_utils._compute_linear_scaling_rope_parameters — inv_freq /= factor + # Equivalent to inv_freq = 1 / (factor * theta ** (i / dim)) in make_rotary_embedding_caches_from_scratch. + factor = float(config.rope_scaling["factor"]) + if factor <= 0: + raise ValueError(f"rope_scaling.factor must be positive for linear RoPE scaling, got {factor}") + self.rope_attrs["rescale_factors"] = factor + elif "mrope_section" in config.rope_scaling: # For models that use MRoPE (e.g. Qwen 2.5 VL, Qwen 3 VL) self.rope_attrs["mrope"] = {