|
| 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