| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | # Adapted from |
| 5 | # https://huggingface.co/tiiuae/falcon-7b/blob/main/configuration_RW.py |
| 6 | # Copyright 2023 The vLLM team. |
| 7 | # Copyright 2022 the Big Science Workshop and HuggingFace Inc. team. |
| 8 | # All rights reserved. |
| 9 | # |
| 10 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | # you may not use this file except in compliance with the License. |
| 12 | # You may obtain a copy of the License at |
| 13 | # |
| 14 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | # |
| 16 | # Unless required by applicable law or agreed to in writing, software |
| 17 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | # See the License for the specific language governing permissions and |
| 20 | # limitations under the License. |
| 21 | """Falcon configuration.""" |
| 22 | |
| 23 | from transformers.configuration_utils import PreTrainedConfig |
| 24 | |
| 25 | |
| 26 | class RWConfig(PreTrainedConfig): |
| 27 | model_type = "falcon" |
| 28 | keys_to_ignore_at_inference = ["past_key_values"] |
| 29 | attribute_map = { |
| 30 | "num_hidden_layers": "n_layer", |
| 31 | "num_attention_heads": "n_head", |
| 32 | "num_kv_heads": "n_head_kv", |
| 33 | } |
| 34 | |
| 35 | def __init__( |
| 36 | self, |
| 37 | vocab_size=250880, |
| 38 | hidden_size=64, |
| 39 | n_layer=2, |
| 40 | n_head=8, |
| 41 | layer_norm_epsilon=1e-5, |
| 42 | initializer_range=0.02, |
| 43 | use_cache=True, |
| 44 | bos_token_id=1, |
| 45 | eos_token_id=2, |
| 46 | hidden_dropout=0.0, |
| 47 | attention_dropout=0.0, |
| 48 | multi_query=True, |
| 49 | n_head_kv=None, |
| 50 | alibi=False, |
| 51 | bias=False, |
| 52 | parallel_attn=False, |
| 53 | new_decoder_architecture=False, |
| 54 | **kwargs, |
| 55 | ) -> None: |
| 56 | self.vocab_size = vocab_size |
| 57 | # Backward compatibility with n_embed kwarg |
| 58 | n_embed = kwargs.pop("n_embed", None) |
| 59 | self.hidden_size = hidden_size if n_embed is None else n_embed |
| 60 | self.n_layer = n_layer |
| 61 | self.n_head = n_head |
| 62 | self.layer_norm_epsilon = layer_norm_epsilon |
| 63 | self.initializer_range = initializer_range |
| 64 | self.use_cache = use_cache |
| 65 | self.hidden_dropout = hidden_dropout |
| 66 | self.attention_dropout = attention_dropout |
| 67 | |
| 68 | self.bos_token_id = bos_token_id |
| 69 | self.eos_token_id = eos_token_id |
| 70 | self.multi_query = multi_query |
| 71 | self.n_head_kv = 1 if n_head_kv is None else n_head_kv |
| 72 | self.alibi = alibi |
| 73 | self.bias = bias |
| 74 | self.parallel_attn = parallel_attn |
| 75 | self.new_decoder_architecture = new_decoder_architecture |
| 76 | |
| 77 | if self.hidden_size == 8192: |
| 78 | # Hack for falcon-40b |
| 79 | self.new_decoder_architecture = True |
| 80 | |
| 81 | super().__init__(bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs) |
| 82 | |
| 83 | @property |
| 84 | def head_dim(self): |
| 85 | return self.hidden_size // self.n_head |
| 86 | |
| 87 | @property |
| 88 | def rotary(self): |
| 89 | return not self.alibi |