|
| 1 | +# coding=utf-8 |
| 2 | +# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved. |
| 3 | +# |
| 4 | +# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX |
| 5 | +# and OPT implementations in this library. It has been modified from its |
| 6 | +# original forms to accommodate minor architectural differences compared |
| 7 | +# to GPT-NeoX and OPT used by the Meta AI team that trained the model. |
| 8 | +# |
| 9 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +# you may not use this file except in compliance with the License. |
| 11 | +# You may obtain a copy of the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +# See the License for the specific language governing permissions and |
| 19 | +# limitations under the License. |
| 20 | +""" PanGuMoE model configuration""" |
| 21 | + |
| 22 | +from transformers.utils import logging |
| 23 | +from transformers.configuration_utils import PretrainedConfig |
| 24 | + |
| 25 | + |
| 26 | +logger = logging.get_logger(__name__) |
| 27 | + |
| 28 | +PanGuMoE_PRETRAINED_CONFIG_ARCHIVE_MAP = {} |
| 29 | + |
| 30 | + |
| 31 | +class PanGuMoEConfig(PretrainedConfig): |
| 32 | + |
| 33 | + model_type = "PanGuMoE" |
| 34 | + _auto_class = "AutoConfig" |
| 35 | + |
| 36 | + def __init__( |
| 37 | + self, |
| 38 | + vocab_size=161856, |
| 39 | + hidden_size=5120, |
| 40 | + num_hidden_layers=48, |
| 41 | + num_attention_heads=40, |
| 42 | + num_key_value_heads=8, |
| 43 | + hidden_act="silu", |
| 44 | + max_position_embeddings=4096, |
| 45 | + initializer_range=0.02, |
| 46 | + rms_norm_eps=1e-5, |
| 47 | + use_cache=True, |
| 48 | + pad_token_id=0, |
| 49 | + bos_token_id=1, |
| 50 | + eos_token_id=2, |
| 51 | + tie_word_embeddings=False, |
| 52 | + rope_theta=1000000.0, |
| 53 | + moe_intermediate_size=1344, |
| 54 | + shared_expert_intermediate_size=5376, |
| 55 | + num_experts_per_tok=8, |
| 56 | + num_experts=64, |
| 57 | + output_router_logits=False, |
| 58 | + router_aux_loss_coef=0.001, |
| 59 | + **kwargs, |
| 60 | + ): |
| 61 | + self.vocab_size = vocab_size |
| 62 | + self.max_position_embeddings = max_position_embeddings |
| 63 | + self.hidden_size = hidden_size |
| 64 | + self.num_hidden_layers = num_hidden_layers |
| 65 | + self.num_attention_heads = num_attention_heads |
| 66 | + self.num_key_value_heads = num_key_value_heads |
| 67 | + self.hidden_act = hidden_act |
| 68 | + self.initializer_range = initializer_range |
| 69 | + self.rms_norm_eps = rms_norm_eps |
| 70 | + self.use_cache = use_cache |
| 71 | + self.rope_theta = rope_theta |
| 72 | + |
| 73 | + # MoE arguments |
| 74 | + self.moe_intermediate_size = moe_intermediate_size |
| 75 | + self.shared_expert_intermediate_size = shared_expert_intermediate_size |
| 76 | + self.num_experts_per_tok = num_experts_per_tok |
| 77 | + self.num_experts = num_experts |
| 78 | + self.output_router_logits = output_router_logits |
| 79 | + self.router_aux_loss_coef = router_aux_loss_coef |
| 80 | + |
| 81 | + super().__init__( |
| 82 | + pad_token_id=pad_token_id, |
| 83 | + bos_token_id=bos_token_id, |
| 84 | + eos_token_id=eos_token_id, |
| 85 | + tie_word_embeddings=tie_word_embeddings, |
| 86 | + **kwargs, |
| 87 | + ) |
0 commit comments