CoolFace
Modelpublic

WebOrganizer/TopicClassifier

sourceHugging Faceupdated 3mo agoView on Hugging Face
17likes4.9kdownloads
configuration.py146 linesDownload Raw Back to root
1# coding=utf-82# Copyright 2024 The GTE Team Authors and Alibaba Group.3# Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9#     http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16""" NEW model configuration"""17from transformers.configuration_utils import PretrainedConfig18from transformers.utils import logging19 20logger = logging.get_logger(__name__)21 22 23class NewConfig(PretrainedConfig):24    r"""25    This is the configuration class to store the configuration of a [`NewModel`] or a [`TFNewModel`]. It is used to26    instantiate a NEW model according to the specified arguments, defining the model architecture. Instantiating a27    configuration with the defaults will yield a similar configuration to that of the NEW28    [izhx/new-base-en](https://huggingface.co/izhx/new-base-en) architecture.29 30    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the31    documentation from [`PretrainedConfig`] for more information.32 33 34    Args:35        vocab_size (`int`, *optional*, defaults to 30522):36            Vocabulary size of the NEW model. Defines the number of different tokens that can be represented by the37            `inputs_ids` passed when calling [`NewModel`] or [`TFNewModel`].38        hidden_size (`int`, *optional*, defaults to 768):39            Dimensionality of the encoder layers and the pooler layer.40        num_hidden_layers (`int`, *optional*, defaults to 12):41            Number of hidden layers in the Transformer encoder.42        num_attention_heads (`int`, *optional*, defaults to 12):43            Number of attention heads for each attention layer in the Transformer encoder.44        intermediate_size (`int`, *optional*, defaults to 3072):45            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.46        hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):47            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,48            `"relu"`, `"silu"` and `"gelu_new"` are supported.49        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):50            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.51        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):52            The dropout ratio for the attention probabilities.53        max_position_embeddings (`int`, *optional*, defaults to 512):54            The maximum sequence length that this model might ever be used with. Typically set this to something large55            just in case (e.g., 512 or 1024 or 2048).56        type_vocab_size (`int`, *optional*, defaults to 2):57            The vocabulary size of the `token_type_ids` passed when calling [`NewModel`] or [`TFNewModel`].58        initializer_range (`float`, *optional*, defaults to 0.02):59            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.60        layer_norm_eps (`float`, *optional*, defaults to 1e-12):61            The epsilon used by the layer normalization layers.62        position_embedding_type (`str`, *optional*, defaults to `"rope"`):63            Type of position embedding. Choose one of `"absolute"`, `"rope"`.64        rope_theta (`float`, *optional*, defaults to 10000.0):65            The base period of the RoPE embeddings.66        rope_scaling (`Dict`, *optional*):67            Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling68            strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is69            `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update70            `max_position_embeddings` to the expected new maximum. See the following thread for more information on how71            these scaling strategies behave:72            https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an73            experimental feature, subject to breaking API changes in future versions.74        classifier_dropout (`float`, *optional*):75            The dropout ratio for the classification head.76 77    Examples:78 79    ```python80    >>> from transformers import NewConfig, NewModel81 82    >>> # Initializing a NEW izhx/new-base-en style configuration83    >>> configuration = NewConfig()84 85    >>> # Initializing a model (with random weights) from the izhx/new-base-en style configuration86    >>> model = NewModel(configuration)87 88    >>> # Accessing the model configuration89    >>> configuration = model.config90    ```"""91 92    model_type = "new"93 94    def __init__(95        self,96        vocab_size=30528,97        hidden_size=768,98        num_hidden_layers=12,99        num_attention_heads=12,100        intermediate_size=3072,101        hidden_act="gelu",102        hidden_dropout_prob=0.1,103        attention_probs_dropout_prob=0.0,104        max_position_embeddings=2048,105        type_vocab_size=1,106        initializer_range=0.02,107        layer_norm_type='layer_norm',108        layer_norm_eps=1e-12,109        # pad_token_id=0,110        position_embedding_type="rope",111        rope_theta=10000.0,112        rope_scaling=None,113        classifier_dropout=None,114        pack_qkv=True,115        unpad_inputs=False,116        use_memory_efficient_attention=False,117        logn_attention_scale=False,118        logn_attention_clip1=False,119        **kwargs,120    ):121        super().__init__(**kwargs)122 123        self.vocab_size = vocab_size124        self.hidden_size = hidden_size125        self.num_hidden_layers = num_hidden_layers126        self.num_attention_heads = num_attention_heads127        self.hidden_act = hidden_act128        self.intermediate_size = intermediate_size129        self.hidden_dropout_prob = hidden_dropout_prob130        self.attention_probs_dropout_prob = attention_probs_dropout_prob131        self.max_position_embeddings = max_position_embeddings132        self.type_vocab_size = type_vocab_size133        self.initializer_range = initializer_range134        self.layer_norm_type = layer_norm_type135        self.layer_norm_eps = layer_norm_eps136        self.position_embedding_type = position_embedding_type137        self.rope_theta = rope_theta138        self.rope_scaling = rope_scaling139        self.classifier_dropout = classifier_dropout140 141        self.pack_qkv = pack_qkv142        self.unpad_inputs = unpad_inputs143        self.use_memory_efficient_attention = use_memory_efficient_attention144        self.logn_attention_scale = logn_attention_scale145        self.logn_attention_clip1 = logn_attention_clip1146