Source code for mindnlp.models.gpt.gpt_config

# coding=utf-8
# Copyright 2018 The OpenAI Team Authors and HuggingFace Inc. team.
# Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
# Copyright 2023 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""MindNLP gpt config"""

from mindnlp.abc import PreTrainedConfig
from mindnlp.configs import MINDNLP_CONFIG_URL_BASE

__all__ = ['GPTConfig']

GPT_SUPPORT_LIST = ["openai-gpt"]

CONFIG_ARCHIVE_MAP = {
    model: MINDNLP_CONFIG_URL_BASE.format('gpt', model) for model in GPT_SUPPORT_LIST
}

[docs]class GPTConfig(PreTrainedConfig): r""" GPT config """ model_type = "gpt" attribute_map = { "max_position_embeddings": "n_positions", "hidden_size": "n_embd", "num_attention_heads": "n_head", "num_hidden_layers": "n_layer", } pretrained_config_archive_map = CONFIG_ARCHIVE_MAP def __init__( self, vocab_size=40478, n_positions=512, n_embd=768, hidden_size=768, n_layer=12, n_head=12, afn="gelu_new", resid_pdrop=0.1, embd_pdrop=0.1, attn_pdrop=0.1, layer_norm_epsilon=1e-5, initializer_range=0.02, summary_type="cls_index", summary_use_proj=True, summary_activation=None, summary_proj_to_labels=True, summary_first_dropout=0.1, **kwargs ): self.vocab_size = vocab_size self.n_positions = n_positions self.n_embd = n_embd self.hidden_size = hidden_size self.n_layer = n_layer self.n_head = n_head self.afn = afn self.resid_pdrop = resid_pdrop self.embd_pdrop = embd_pdrop self.attn_pdrop = attn_pdrop self.layer_norm_epsilon = layer_norm_epsilon self.initializer_range = initializer_range self.summary_type = summary_type self.summary_use_proj = summary_use_proj self.summary_activation = summary_activation self.summary_first_dropout = summary_first_dropout self.summary_proj_to_labels = summary_proj_to_labels super().__init__(**kwargs)