Skip to content

Commit 8b1881d

Browse files
yicycycliuhao2638
andauthored
add olmo2 model (#4353)
Co-authored-by: liuhao2638 <2284903223@qq.com>
1 parent 365adff commit 8b1881d

11 files changed

Lines changed: 1042 additions & 2 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PaddleFormers 是基于百度深度学习框架 PaddlePaddle 搭建的 Transform
5555
<tbody>
5656
<!-- LLM 分类 - 跨行合并开始 -->
5757
<tr>
58-
<td rowspan="13" style="vertical-align: top;">LLM</td>
58+
<td rowspan="14" style="vertical-align: top;">LLM</td>
5959
<td>DeepSeekv3</td>
6060
<td>deepseek-ai/DeepSeek-V3-Base、deepseek-ai/DeepSeek-V3、deepseek-ai/DeepSeek-V3-0324</td>
6161
<td>deepseek3</td>
@@ -95,6 +95,11 @@ PaddleFormers 是基于百度深度学习框架 PaddlePaddle 搭建的 Transform
9595
<td>meta-llama/Meta-Llama-3-8B、meta-llama/Meta-Llama-3-8B-Instruct、meta-llama/Meta-Llama-3-70B、meta-llama/Meta-Llama-3-70B-Instruct、meta-llama/Llama-3.1-8B、meta-llama/Llama-3.1-8B-Instruct、meta-llama/Llama-3.1-70B、meta-llama/Llama-3.1-70B-Instruct、meta-llama/Llama-3.1-405B、meta-llama/Llama-3.1-405B-Instruct、meta-llama/Llama-3.2-1B、meta-llama/Llama-3.2-1B-Instruct、meta-llama/Llama-3.2-3B、meta-llama/Llama-3.2-3B-Instruct、meta-llama/Llama-3.3-70B-Instruct</td>
9696
<td>llama3</td>
9797
</tr>
98+
<tr>
99+
<td>OLMo2</td>
100+
<td>allenai/OLMo-2-0425-1B、allenai/OLMo-2-0425-1B-SFT、allenai/OLMo-2-0425-1B-DPO、allenai/OLMo-2-0425-1B-Instruct、allenai/OLMo-2-1124-7B、allenai/OLMo-2-1124-7B-SFT、allenai/OLMo-2-1124-7B-DPO、allenai/OLMo-2-1124-7B-Instruct、allenai/OLMo-2-1124-13B、allenai/OLMo-2-1124-13B-SFT、allenai/OLMo-2-1124-13B-DPO、allenai/OLMo-2-1124-13B-Instruct、allenai/OLMo-2-0325-32B、allenai/OLMo-2-0325-32B-SFT、allenai/OLMo-2-0325-32B-DPO、allenai/OLMo-2-0325-32B-Instruct</td>
101+
<td>jinja</td>
102+
</tr>
98103
<tr>
99104
<td>phi-4</td>
100105
<td>microsoft/phi-4</td>

docs/zh/model_capability.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
|GLM-4.5||||||
88
|GPT-OSS||||x|x|
99
|LLaMA3||||||
10+
|OLMo2||||||
1011
|Phi4||||||
1112
|Qwen2||||||
1213
|Qwen3||||||
@@ -25,6 +26,7 @@
2526
|GLM-4.5|||||||
2627
|GPT-OSS|||x|x|||
2728
|LLaMA3|||-|x|||
29+
|OLMo2|||-|x|||
2830
|Phi4|||-|x|||
2931
|Qwen2|||x|x|||
3032
|Qwen3|||||||

paddleformers/cli/utils/llm_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_lora_target_modules(model):
7777
]
7878
elif model.config.model_type == "bloom":
7979
target_modules = [".*query_key_value.*", ".*dense.*", ".*dense_h_to_4h.*", ".*dense_4h_to_h.*"]
80-
elif model.config.model_type in ["llama", "jamba"]:
80+
elif model.config.model_type in ["llama", "jamba", "olmo2"]:
8181
target_modules = [
8282
".*q_proj.*",
8383
".*v_proj.*",

paddleformers/transformers/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@
356356
],
357357
"glm_ocr.processor": ["Glm46VProcessor"],
358358
"glm_ocr.image_processor": ["Glm46VImageProcessor"],
359+
"olmo2.configuration": ["Olmo2Config"],
360+
"olmo2.modeling": ["Olmo2DecoderLayer", "Olmo2Model", "Olmo2ForCausalLM", "Olmo2ForCausalLMPipe"],
361+
"olmo2": [],
359362
"intern_lm3.configuration": ["InternLM3Config"],
360363
"intern_lm3.modeling": [
361364
"InternLM3Model",
@@ -470,6 +473,7 @@
470473
from .phi3 import *
471474
from .gemma3_text import *
472475
from .glm_ocr import *
476+
from .olmo2 import *
473477
from .intern_lm3 import *
474478
from .intern_lm2_5 import *
475479
from .intern import *

paddleformers/transformers/auto/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
("glm_ocr", "GlmOcrConfig"),
6666
("qwen3_5", "Qwen3_5Config"),
6767
("qwen3_5_moe", "Qwen3_5MoEConfig"),
68+
("olmo2", "Olmo2Config"),
6869
("internlm3", "InternLM3Config"),
6970
("internlm2", "InternLM2Config"),
7071
# TODO(VL): When Gemma4 VL is implemented, "gemma4" should point to Gemma4Config (VL wrapper)
@@ -102,6 +103,7 @@
102103
("minicpm", "MiniCPM"),
103104
("qwen3_5_moe", "Qwen3_5MoEForConditionalGeneration"),
104105
("qwen3_5", "Qwen3_5ForConditionalGeneration"),
106+
("olmo2", "Olmo2ForCausalLM"),
105107
("internlm3", "InternLM3ForCausalLM"),
106108
("internlm2", "InternLM2"),
107109
("gemma4_moe", "Gemma4MoeForCausalLM"),

paddleformers/transformers/auto/modeling.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
("Gemma4Moe", "gemma4_moe"),
8585
("Glm4vMoe", "glm4v_moe"),
8686
("GlmOcr", "glm_ocr"),
87+
("Olmo2", "olmo2"),
8788
("InternLM3", "intern_lm3"),
8889
("InternLM2", "intern"),
8990
]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
"""Package"""
15+
16+
import sys
17+
from typing import TYPE_CHECKING
18+
19+
from ...utils.lazy_import import _LazyModule
20+
21+
import_structure = {
22+
"configuration": ["Olmo2Config"],
23+
"modeling": [
24+
"Olmo2DecoderLayer",
25+
"Olmo2Model",
26+
"Olmo2ForCausalLM",
27+
"Olmo2ForCausalLMPipe",
28+
],
29+
}
30+
31+
if TYPE_CHECKING:
32+
from .configuration import *
33+
from .modeling import *
34+
else:
35+
sys.modules[__name__] = _LazyModule(
36+
__name__,
37+
globals()["__file__"],
38+
import_structure,
39+
module_spec=__spec__,
40+
)
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from ..configuration_utils import PretrainedConfig
16+
from ..modeling_rope_utils import rope_config_validation, standardize_rope_params
17+
18+
19+
class Olmo2Config(PretrainedConfig):
20+
model_type = "olmo2"
21+
22+
def __init__(
23+
self,
24+
vocab_size=50304,
25+
hidden_size=4096,
26+
intermediate_size=11008,
27+
max_position_embeddings=2048,
28+
num_hidden_layers=32,
29+
num_attention_heads=32,
30+
initializer_range=0.02,
31+
rms_norm_eps=1e-5,
32+
use_cache=True,
33+
pad_token_id=1,
34+
bos_token_id=None,
35+
eos_token_id=50279,
36+
hidden_act="silu",
37+
num_key_value_heads=None,
38+
attention_bias=False,
39+
attention_dropout=0.0,
40+
tie_word_embeddings=False,
41+
head_dim=None,
42+
rope_theta=10000.0,
43+
**kwargs,
44+
):
45+
self.vocab_size = vocab_size
46+
self.max_position_embeddings = max_position_embeddings
47+
self.hidden_size = hidden_size
48+
self.intermediate_size = intermediate_size
49+
self.num_hidden_layers = num_hidden_layers
50+
self.num_attention_heads = num_attention_heads
51+
52+
if num_key_value_heads is None:
53+
num_key_value_heads = num_attention_heads
54+
55+
self.num_key_value_heads = num_key_value_heads
56+
self.hidden_act = hidden_act
57+
self.initializer_range = initializer_range
58+
self.rms_norm_eps = rms_norm_eps
59+
self.use_cache = use_cache
60+
self.attention_bias = attention_bias
61+
self.attention_dropout = attention_dropout
62+
self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads
63+
64+
self.rope_theta = rope_theta
65+
self.rope_scaling = kwargs.pop("rope_scaling", None)
66+
if self.rope_scaling is not None and "type" in self.rope_scaling:
67+
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
68+
self.rope_parameters = self.rope_scaling
69+
standardize_rope_params(self, rope_theta=self.rope_theta)
70+
rope_config_validation(self)
71+
72+
super().__init__(
73+
pad_token_id=pad_token_id,
74+
bos_token_id=bos_token_id,
75+
eos_token_id=eos_token_id,
76+
tie_word_embeddings=tie_word_embeddings,
77+
**kwargs,
78+
)

0 commit comments

Comments
 (0)