Skip to content
Merged
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
13 changes: 12 additions & 1 deletion src/python/py/models/builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"] = {
Expand Down