| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | # Adapted from |
| 5 | # https://github.com/zai-org/ChatGLM2-6B |
| 6 | from transformers import PreTrainedConfig |
| 7 | |
| 8 | |
| 9 | class ChatGLMConfig(PreTrainedConfig): |
| 10 | model_type = "chatglm" |
| 11 | attribute_map = { |
| 12 | "num_hidden_layers": "num_layers", |
| 13 | "n_head_kv": "multi_query_group_num", |
| 14 | } |
| 15 | |
| 16 | def __init__( |
| 17 | self, |
| 18 | num_layers=28, |
| 19 | padded_vocab_size=65024, |
| 20 | hidden_size=4096, |
| 21 | ffn_hidden_size=13696, |
| 22 | kv_channels=128, |
| 23 | num_attention_heads=32, |
| 24 | seq_length=2048, |
| 25 | hidden_dropout=0.0, |
| 26 | attention_dropout=0.0, |
| 27 | layernorm_epsilon=1e-5, |
| 28 | rmsnorm=True, |
| 29 | apply_residual_connection_post_layernorm=False, |
| 30 | post_layer_norm=True, |
| 31 | add_bias_linear=False, |
| 32 | add_qkv_bias=False, |
| 33 | interleaved_qkv=False, |
| 34 | bias_dropout_fusion=True, |
| 35 | multi_query_attention=False, |
| 36 | multi_query_group_num=1, |
| 37 | apply_query_key_layer_scaling=True, |
| 38 | attention_softmax_in_fp32=True, |
| 39 | fp32_residual_connection=False, |
| 40 | quantization_bit=0, |
| 41 | pre_seq_len=None, |
| 42 | prefix_projection=False, |
| 43 | **kwargs, |
| 44 | ): |
| 45 | self.num_layers = num_layers |
| 46 | self.vocab_size = padded_vocab_size |
| 47 | self.padded_vocab_size = padded_vocab_size |
| 48 | self.hidden_size = hidden_size |
| 49 | self.ffn_hidden_size = ffn_hidden_size |
| 50 | self.kv_channels = kv_channels |
| 51 | self.num_attention_heads = num_attention_heads |
| 52 | self.seq_length = seq_length |
| 53 | # It is to be compatible with long lora. |
| 54 | self.max_position_embeddings = seq_length |
| 55 | self.hidden_dropout = hidden_dropout |
| 56 | self.attention_dropout = attention_dropout |
| 57 | self.layernorm_epsilon = layernorm_epsilon |
| 58 | self.rmsnorm = rmsnorm |
| 59 | self.apply_residual_connection_post_layernorm = ( |
| 60 | apply_residual_connection_post_layernorm |
| 61 | ) |
| 62 | self.post_layer_norm = post_layer_norm |
| 63 | self.add_bias_linear = add_bias_linear |
| 64 | self.add_qkv_bias = add_qkv_bias |
| 65 | self.bias_dropout_fusion = bias_dropout_fusion |
| 66 | self.multi_query_attention = multi_query_attention |
| 67 | self.multi_query_group_num = multi_query_group_num |
| 68 | self.apply_query_key_layer_scaling = apply_query_key_layer_scaling |
| 69 | self.attention_softmax_in_fp32 = attention_softmax_in_fp32 |
| 70 | self.fp32_residual_connection = fp32_residual_connection |
| 71 | self.quantization_bit = quantization_bit |
| 72 | self.pre_seq_len = pre_seq_len |
| 73 | self.prefix_projection = prefix_projection |
| 74 | self.interleaved_qkv = interleaved_qkv |
| 75 | super().__init__(**kwargs) |