Skip to content
Open
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ PaddleFormers 是基于百度深度学习框架 PaddlePaddle 搭建的 Transform
<tbody>
<!-- LLM 分类 - 跨行合并开始 -->
<tr>
<td rowspan="18" style="vertical-align: top;">LLM</td>
<td rowspan="20" style="vertical-align: top;">LLM</td>
<td>DeepSeekv3</td>
<td>deepseek-ai/DeepSeek-V3-Base、deepseek-ai/DeepSeek-V3、deepseek-ai/DeepSeek-V3-0324</td>
<td>deepseek3</td>
Expand All @@ -65,6 +65,11 @@ PaddleFormers 是基于百度深度学习框架 PaddlePaddle 搭建的 Transform
<td>CohereForAI/aya-expanse-8b、CohereForAI/aya-expanse-32b</td>
<td>aya</td>
</tr>
<tr>
<td>StableLM</td>
<td>stabilityai/stable-code-3b</td>
<td>-(基础代码补全模型)</td>
</tr>
<tr>
<td>DeepSeekv3.2</td>
<td>deepseek-ai/DeepSeek-V3.2</td>
Expand Down
1 change: 1 addition & 0 deletions docs/zh/model_capability.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
|模型|PT / CPT|SFT|SFT-LoRA|DPO|DPO-LoRA|
|-|-|-|-|-|-|
|Cohere|✓|✓|✓|✓|✓|
|StableLM|✓|✓|✓|✓|✓|
|DeepSeekv3|✓|✓|✓|✓|✓|
|🏛️ERNIE-4.5|✓|✓|✓|✓|✓|
|Gemma3|✓|✓|✓|✓|✓|
Expand Down
10 changes: 10 additions & 0 deletions paddleformers/cli/utils/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,16 @@ def get_lora_target_modules(model):
"model.visual.blocks.*mlp.up_proj.*",
"model.visual.blocks.*mlp.down_proj.*",
]
elif model.config.model_type == "stablelm":
target_modules = [
".*q_proj.*",
".*k_proj.*",
".*v_proj.*",
".*o_proj.*",
".*gate_proj.*",
".*up_proj.*",
".*down_proj.*",
]
elif model.config.model_type == "internlm2":
# Covers both InternLM2 2.0 and 2.5: both route through the unified
# `intern/` proxy with `model_type = "internlm2"` and share the same
Expand Down
12 changes: 12 additions & 0 deletions paddleformers/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,17 @@
],
"glm_ocr.processor": ["Glm46VProcessor"],
"glm_ocr.image_processor": ["Glm46VImageProcessor"],
"stablelm": [],
"stablelm.configuration": ["StableLmConfig"],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

上面可以再补一个"stablelm": [],风格对齐

"stablelm.modeling": [
"StableLmModel",
"StableLmForCausalLM",
"StableLmForCausalLMPipe",
"StableLmPretrainedModel",
"StableLmRotaryEmbedding",
"StableLmDecoderLayer",
"StableLmAttention",
],
"olmo2.configuration": ["Olmo2Config"],
"olmo2.modeling": ["Olmo2DecoderLayer", "Olmo2Model", "Olmo2ForCausalLM", "Olmo2ForCausalLMPipe"],
"olmo2": [],
Expand Down Expand Up @@ -612,6 +623,7 @@
from .gemma3 import *
from .shieldgemma2 import *
from .glm_ocr import *
from .stablelm import *
from .molmo import *
from .olmo2 import *
from .intern_lm3 import *
Expand Down
2 changes: 2 additions & 0 deletions paddleformers/transformers/auto/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
("molmo", "MolmoConfig"),
("qwen3_5", "Qwen3_5Config"),
("qwen3_5_moe", "Qwen3_5MoEConfig"),
("stablelm", "StableLmConfig"),

@WYB27 WYB27 Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

下面的MODEL_NAMES_MAPPING也需要注册对应内容

同时也需要在docs/zh/model_capability.md和仓库README补一下该模型相关的内容

("olmo2", "Olmo2Config"),
("internlm3", "InternLM3Config"),
("internlm2", "InternLM2Config"),
Expand Down Expand Up @@ -139,6 +140,7 @@
("qwen3_5_moe", "Qwen3_5MoEForConditionalGeneration"),
("qwen3_5", "Qwen3_5ForConditionalGeneration"),
("minicpm3", "MiniCPM3Model"),
("stablelm", "StableLmForCausalLM"),
("olmo2", "Olmo2ForCausalLM"),
("internlm3", "InternLM3ForCausalLM"),
("internlm2", "InternLM2"),
Expand Down
1 change: 1 addition & 0 deletions paddleformers/transformers/auto/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
("Gemma4Moe", "gemma4_moe"),
("Glm4vMoe", "glm4v_moe"),
("GlmOcr", "glm_ocr"),
("StableLm", "stablelm"),
("Molmo", "molmo"),
("Olmo2", "olmo2"),
("InternLM3", "intern_lm3"),
Expand Down
52 changes: 52 additions & 0 deletions paddleformers/transformers/stablelm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING

from ...utils.lazy_import import _LazyModule

import_structure = {
"configuration": ["StableLmConfig"],
"modeling": [
"StableLmModel",
"StableLmForCausalLM",
"StableLmForCausalLMPipe",
"StableLmPretrainedModel",
"StableLmRotaryEmbedding",
"StableLmDecoderLayer",
"StableLmAttention",
],
}

if TYPE_CHECKING:
from .configuration import StableLmConfig
from .modeling import (
StableLmAttention,
StableLmDecoderLayer,
StableLmForCausalLM,
StableLmForCausalLMPipe,
StableLmModel,
StableLmPretrainedModel,
StableLmRotaryEmbedding,
)

else:
import sys

sys.modules[__name__] = _LazyModule(
__name__,
globals()["__file__"],
import_structure,
module_spec=__spec__,
)
132 changes: 132 additions & 0 deletions paddleformers/transformers/stablelm/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import math

from ..configuration_utils import PretrainedConfig
from ..modeling_rope_utils import rope_config_validation, standardize_rope_params


class StableLmConfig(PretrainedConfig):
model_type = "stablelm"
keys_to_ignore_at_inference = ["past_key_values"]

def __init__(
self,
vocab_size=50304,
intermediate_size=6912,
hidden_size=2560,
num_hidden_layers=32,
num_attention_heads=32,
num_key_value_heads=32,
hidden_act="silu",
max_position_embeddings=4096,
initializer_range=0.02,
layer_norm_eps=1.0e-5,
use_cache=True,
tie_word_embeddings=False,
rope_theta=10000.0,
partial_rotary_factor=0.25,
rope_parameters=None,
use_qkv_bias=False,
qk_layernorm=False,
use_parallel_residual=False,
hidden_dropout=0.0,
attention_dropout=0.0,
bos_token_id=0,
eos_token_id=0,
pad_token_id=None,
**kwargs,
):
for name, value in {
"vocab_size": vocab_size,
"hidden_size": hidden_size,
"intermediate_size": intermediate_size,
"num_hidden_layers": num_hidden_layers,
"num_attention_heads": num_attention_heads,
"num_key_value_heads": num_key_value_heads,
"max_position_embeddings": max_position_embeddings,
}.items():
if value <= 0:
raise ValueError(f"{name} must be positive, got {value!r}")
if hidden_size % num_attention_heads:
raise ValueError("hidden_size must be divisible by num_attention_heads")
if num_attention_heads % num_key_value_heads:
raise ValueError("num_attention_heads must be divisible by num_key_value_heads")
for name, value in {"hidden_dropout": hidden_dropout, "attention_dropout": attention_dropout}.items():

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 可维护性建议(AI 生成债务,不阻塞合入):整型参数的校验已按评审意见去掉 isinstance,但这里的 dropout 校验和第 75-81 行的 eps/theta 校验仍保留 isinstance + math.isfinite 的同构循环,三段校验写法不一致,后续增参数要分别维护。同目录 olmo2 / cohere 的配置不做此类校验。建议统一:保留真正需要的约束(如整除、partial RoPE 维度为偶数),其余样板校验一并精简。

if not isinstance(value, (int, float)) or not math.isfinite(value) or not 0 <= value < 1:
raise ValueError(f"{name} must be in [0, 1), got {value!r}")
if not isinstance(partial_rotary_factor, (int, float)) or not 0 < partial_rotary_factor <= 1:
raise ValueError("partial_rotary_factor must be in (0, 1]")
rotary_dim = int(hidden_size // num_attention_heads * partial_rotary_factor)
if rotary_dim <= 0 or rotary_dim % 2:
raise ValueError("partial RoPE dimension must be positive and even")
for name, value in {
"layer_norm_eps": layer_norm_eps,
"initializer_range": initializer_range,
"rope_theta": rope_theta,
}.items():
if not isinstance(value, (int, float)) or not math.isfinite(value) or value <= 0:
raise ValueError(f"{name} must be positive and finite")
self.vocab_size = vocab_size
self.hidden_size = hidden_size
self.intermediate_size = intermediate_size
self.max_position_embeddings = max_position_embeddings
self.num_hidden_layers = num_hidden_layers
self.num_attention_heads = num_attention_heads
self.num_key_value_heads = num_key_value_heads
self.hidden_act = hidden_act
self.initializer_range = initializer_range
self.layer_norm_eps = layer_norm_eps
self.use_cache = use_cache
self.tie_word_embeddings = tie_word_embeddings
self.use_qkv_bias = use_qkv_bias
self.qk_layernorm = qk_layernorm
self.use_parallel_residual = use_parallel_residual
self.hidden_dropout = hidden_dropout
self.attention_dropout = attention_dropout

self.rope_theta = rope_theta
self.partial_rotary_factor = partial_rotary_factor
rope_scaling = kwargs.pop("rope_scaling", None)
if rope_parameters is None:
rope_parameters = rope_scaling
if rope_parameters is not None and not isinstance(rope_parameters, dict):
raise ValueError("rope_parameters and rope_scaling must be dicts or None")
self.rope_parameters = dict(rope_parameters) if rope_parameters is not None else None
standardize_rope_params(self, rope_theta=self.rope_theta)
effective_rope_theta = self.rope_parameters["rope_theta"]
if (
not isinstance(effective_rope_theta, (int, float))
or not math.isfinite(effective_rope_theta)
or effective_rope_theta <= 0
):
raise ValueError("rope_parameters.rope_theta must be positive and finite")
rope_config_validation(self, ignore_keys={"partial_rotary_factor"})

self.norm_eps = self.layer_norm_eps
self.mlp_bias = False

if kwargs.get("architectures") is None:
kwargs["architectures"] = ["StableLmForCausalLM"]
super().__init__(
pad_token_id=pad_token_id,
bos_token_id=bos_token_id,
eos_token_id=eos_token_id,
tie_word_embeddings=tie_word_embeddings,
**kwargs,
)
if getattr(self, "head_dim", None) not in (None, hidden_size // num_attention_heads):
raise ValueError("StableLM head_dim must equal hidden_size // num_attention_heads")
self.head_dim = hidden_size // num_attention_heads
Loading
Loading