CoolFace
Modelpublic

zai-org/WebGLM

sourceHugging Faceupdated 3y agoView on Hugging Face
48likes229downloads
configuration_glm.py137 linesDownload Raw Back to root
1# coding=utf-82# Copyright 2022 shunxing1234 and The HuggingFace Inc. team. All rights reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8#     http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15""" GLM model configuration """16 17from transformers.configuration_utils import PretrainedConfig18from transformers.utils import logging19 20logger = logging.get_logger(__name__)21 22GLM_PRETRAINED_CONFIG_ARCHIVE_MAP = {23    "shunxing1234/GLM": "https://huggingface.co/shunxing1234/GLM/resolve/main/config.json",24    # See all GLM models at https://huggingface.co/models?filter=glm25}26 27 28class GLMConfig(PretrainedConfig):29    r"""30    This is the configuration class to store the configuration of a [`~GLMModel`].31    It is used to instantiate an GLM model according to the specified arguments, defining the model32    architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of33    the GLM [shunxing1234/GLM-base-cased](https://huggingface.co/shunxing1234/GLM-base-cased) architecture.34 35    Configuration objects inherit from  [`PretrainedConfig`] and can be used36    to control the model outputs. Read the documentation from  [`PretrainedConfig`]37    for more information.38 39 40    Args:41        vocab_size (`int`, *optional*, defaults to 30522):42            Vocabulary size of the GLM model. Defines the number of different tokens that can be represented by the43            `inputs_ids` passed when calling [`~GLMModel`] or44            [`~TFGLMModel`].45        hidden_size (`int`, *optional*, defaults to 768):46            Dimension of the encoder layers and the pooler layer.47        num_hidden_layers (`int`, *optional*, defaults to 12):48            Number of hidden layers in the Transformer encoder.49        num_attention_heads (`int`, *optional*, defaults to 12):50            Number of attention heads for each attention layer in the Transformer encoder.51        intermediate_size (`int`, *optional*, defaults to 3072):52            Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.53        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):54            The non-linear activation function (function or string) in the encoder and pooler.55            If string, `"gelu"`, `"relu"`, `"selu"` and `"gelu_new"` are supported.56        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):57            The dropout probabilitiy for all fully connected layers in the embeddings, encoder, and pooler.58        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):59            The dropout ratio for the attention probabilities.60        max_position_embeddings (`int`, *optional*, defaults to 512):61            The maximum sequence length that this model might ever be used with.62            Typically set this to something large just in case (e.g., 512 or 1024 or 2048).63        type_vocab_size (`int`, *optional*, defaults to 2):64            The vocabulary size of the `token_type_ids` passed when calling [`~GLMModel`] or65            [`~TFGLMModel`].66        initializer_range (`float`, *optional*, defaults to 0.02):67            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.68        layer_norm_eps (`float`, *optional*, defaults to 1e-12):69            The epsilon used by the layer normalization layers.70        use_cache (`bool`, *optional*, defaults to `True`):71            Whether or not the model should return the last key/values attentions (not used by all models). Only72            relevant if `config.is_decoder=True`.73        Example:74 75    ```python76    >>> from transformers import GLMModel, GLMConfig77 78    >>> # Initializing a GLM shunxing1234/GLM-base-cased style configuration79    >>> configuration = GLMConfig()80 81    >>> # Initializing a model from the shunxing1234/GLM-base-cased style configuration82    >>> model = GLMModel(configuration)83 84    >>> # Accessing the model configuration85    >>> configuration = model.config86    ```87"""88    model_type = "glm"89    attribute_map = {90        "num_hidden_layers": "num_layers"91    }92 93    def __init__(94            self,95            num_layers=24,96            vocab_size=30592,97            hidden_size=1024,98            num_attention_heads=16,99            embedding_dropout_prob=0.1,100            attention_dropout_prob=0.1,101            output_dropout_prob=0.1,102            max_sequence_length=512,103            checkpoint_activations=False,104            checkpoint_num_layers=1,105            parallel_output=True,106            relative_encoding=False,107            block_position_encoding=True,108            output_predict=False,109            spell_length=None,110            spell_func="lstm",111            attention_scale=1.0,112            initializer_range=0.02,113            pool_token="cls",114            **kwargs115    ):116        self.num_layers = num_layers117        self.vocab_size = vocab_size118        self.hidden_size = hidden_size119        self.num_attention_heads = num_attention_heads120        self.embedding_dropout_prob = embedding_dropout_prob121        self.attention_dropout_prob = attention_dropout_prob122        self.output_dropout_prob = output_dropout_prob123        self.max_sequence_length = max_sequence_length124        self.checkpoint_activations = checkpoint_activations125        self.checkpoint_num_layers = checkpoint_num_layers126        self.parallel_output = parallel_output127        self.relative_encoding = relative_encoding128        self.block_position_encoding = block_position_encoding129        self.output_predict = output_predict130        self.spell_length = spell_length131        self.spell_func = spell_func132        self.attention_scale = attention_scale133        self.initializer_range = initializer_range134        self.pool_token = pool_token135 136        super().__init__(**kwargs)137