Skip to content
Merged
3 changes: 2 additions & 1 deletion python/sglang/srt/models/baichuan.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, is_npu
from sglang.srt.utils.hf_transformers_utils import get_rope_config

_is_npu = is_npu()

Expand Down Expand Up @@ -229,7 +230,7 @@ def __init__(
):
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_theta, _ = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
self.self_attn = BaiChuanAttention(
hidden_size=self.hidden_size,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/deepseek.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, cpu_has_amx_support, is_cpu
from sglang.srt.utils.hf_transformers_utils import get_rope_config

_is_cpu_amx_available = cpu_has_amx_support()
_is_cpu = is_cpu()
Expand Down Expand Up @@ -310,8 +311,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
self.self_attn = DeepseekAttention(
hidden_size=self.hidden_size,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/ernie4.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
from sglang.srt.models.deepseek_v2 import DeepseekV2MLP as Ernie4MLP
from sglang.srt.models.llama import LlamaAttention as Ernie4Attention
from sglang.srt.utils import add_prefix, make_layers
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class MoEGate(nn.Module):
Expand Down Expand Up @@ -155,8 +156,7 @@ def __init__(
is_mtp: bool = False,
):
super().__init__()
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
rope_is_neox_style = getattr(config, "rope_is_neox_style", False)
# Self attention.
self.self_attn = Ernie4Attention(
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/exaone.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class ExaoneGatedMLP(nn.Module):
Expand Down Expand Up @@ -182,8 +183,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
if rope_scaling is not None and getattr(
config, "original_max_position_embeddings", None
):
Expand Down
8 changes: 5 additions & 3 deletions python/sglang/srt/models/glm4.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
kv_cache_scales_loader,
)
from sglang.srt.utils import add_prefix, make_layers
from sglang.srt.utils.hf_transformers_utils import get_rope_config

Glm4Config = None

Expand Down Expand Up @@ -217,9 +218,10 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
partial_rotary_factor = config.rope_parameters.get("partial_rotary_factor", 0.5)
rope_theta, rope_scaling = get_rope_config(config)
partial_rotary_factor = (rope_scaling or {}).get("partial_rotary_factor")
if partial_rotary_factor is None:
partial_rotary_factor = getattr(config, "partial_rotary_factor", 0.5)
bias = getattr(config, "attention_bias", True)
max_position_embeddings = getattr(config, "max_position_embeddings", 32768)
head_dim = getattr(config, "head_dim", None)
Expand Down
10 changes: 5 additions & 5 deletions python/sglang/srt/models/glm4_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
log_info_on_rank0,
make_layers,
)
from sglang.srt.utils.hf_transformers_utils import get_rope_config

_is_hip = is_hip()
_is_cuda = is_cuda()
Expand Down Expand Up @@ -684,11 +685,10 @@ def __init__(
nn.Module.__init__(self)
self.hidden_size = config.hidden_size
self.config = config
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
partial_rotary_factor = getattr(
getattr(config, "rope_parameters", None), "partial_rotary_factor", None
) or getattr(config, "partial_rotary_factor", 0.5)
rope_theta, rope_scaling = get_rope_config(config)
partial_rotary_factor = (rope_scaling or {}).get("partial_rotary_factor")
if partial_rotary_factor is None:
partial_rotary_factor = getattr(config, "partial_rotary_factor", 0.5)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
head_dim = getattr(
config, "head_dim", config.hidden_size // config.num_attention_heads
Expand Down
3 changes: 2 additions & 1 deletion python/sglang/srt/models/grok.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from sglang.srt.model_loader.loader import DefaultModelLoader
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, is_npu
from sglang.srt.utils.hf_transformers_utils import get_rope_config

_is_npu = is_npu()

Expand Down Expand Up @@ -477,7 +478,7 @@ def __init__(
self.layer_id = layer_id
self.alt_stream = alt_stream or torch.cuda.Stream()

rope_theta = config.rope_parameters["rope_theta"]
rope_theta, _ = get_rope_config(config)
self.self_attn = Grok1Attention(
config=config,
hidden_size=self.hidden_size,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/hunyuan.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
maybe_remap_kv_scale_name,
)
from sglang.srt.utils import is_hip
from sglang.srt.utils.hf_transformers_utils import get_rope_config

expert_distribution_recorder = ExpertDistributionRecorder()

Expand Down Expand Up @@ -402,8 +403,7 @@ def __init__(
if isinstance(config.intermediate_size, int)
else config.intermediate_size[layer_id]
)
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
if rope_scaling is not None and getattr(
config, "original_max_position_embeddings", None
):
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/iquest_loopcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.models.llama import LlamaMLP as LoopCoderMLP
from sglang.srt.utils import add_prefix, make_layers
from sglang.srt.utils.hf_transformers_utils import get_rope_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -166,8 +167,7 @@ def __init__(
prefix=add_prefix("o_proj", prefix),
)

rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(
config, "max_position_embeddings", max_position
)
Expand Down
6 changes: 4 additions & 2 deletions python/sglang/srt/models/llada2.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
is_npu,
make_layers,
)
from sglang.srt.utils.hf_transformers_utils import get_rope_config

LoraConfig = None
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -486,12 +487,13 @@ def __init__(
self.rotary_dim = config.rotary_dim
else:
self.rotary_dim = self.head_dim
rope_theta, rope_scaling = get_rope_config(config)
self.rotary_emb = get_rope(
self.head_dim,
rotary_dim=self.rotary_dim,
max_position=config.max_position_embeddings,
base=config.rope_parameters["rope_theta"],
rope_scaling=config.rope_parameters,
base=rope_theta,
rope_scaling=rope_scaling,
)

self.attn = RadixAttention(
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/minicpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class MiniCPMMLP(nn.Module):
Expand Down Expand Up @@ -176,8 +177,7 @@ def __init__(
super().__init__()
self.config = config
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
self.self_attn = MiniCPMAttention(
hidden_size=self.hidden_size,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/minicpm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, is_cuda
from sglang.srt.utils.hf_transformers_utils import get_rope_config

if is_cuda():
from sgl_kernel import bmm_fp8 as _raw_bmm_fp8
Expand Down Expand Up @@ -305,8 +306,7 @@ def __init__(
super().__init__()
self.config = config
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
self.self_attn = MiniCPM3AttentionMLA(
config=config,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/orion.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, PPProxyTensors
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, make_layers
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class OrionMLP(nn.Module):
Expand Down Expand Up @@ -165,8 +166,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
self.self_attn = OrionAttention(
hidden_size=self.hidden_size,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/qwen.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class QWenMLP(nn.Module):
Expand Down Expand Up @@ -162,8 +163,7 @@ def __init__(
super().__init__()
self.ln_1 = RMSNorm(config.hidden_size, eps=config.layer_norm_epsilon)

rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
self.attn = QWenAttention(
config.hidden_size,
config.num_attention_heads,
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
kv_cache_scales_loader,
)
from sglang.srt.utils import add_prefix, make_layers
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class SolarMLP(nn.Module):
Expand Down Expand Up @@ -194,8 +195,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)

if rope_scaling is not None and getattr(
config, "original_max_position_embeddings", None
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/step3_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, log_info_on_rank0, make_layers
from sglang.srt.utils.hf_transformers_utils import get_rope_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -290,8 +291,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
head_dim = getattr(
config, "head_dim", config.hidden_size // config.num_attention_heads
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/xverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from sglang.srt.model_executor.model_runner import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class XverseMLP(nn.Module):
Expand Down Expand Up @@ -181,8 +182,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
if rope_scaling is not None and getattr(
config, "original_max_position_embeddings", None
):
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/models/xverse_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.model_loader.weight_utils import default_weight_loader
from sglang.srt.utils import add_prefix, is_npu
from sglang.srt.utils.hf_transformers_utils import get_rope_config


class XverseMLP(nn.Module):
Expand Down Expand Up @@ -291,8 +292,7 @@ def __init__(
) -> None:
super().__init__()
self.hidden_size = config.hidden_size
rope_theta = config.rope_parameters["rope_theta"]
rope_scaling = config.rope_parameters
rope_theta, rope_scaling = get_rope_config(config)
max_position_embeddings = getattr(config, "max_position_embeddings", 8192)
num_key_value_heads = getattr(
config, "num_key_value_heads", config.num_attention_heads
Expand Down
Loading