Upload configuration_falcon.py with huggingface_hub
Browse files- configuration_falcon.py +34 -152
configuration_falcon.py
CHANGED
|
@@ -1,152 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 36 |
-
documentation from [`PretrainedConfig`] for more information.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
Args:
|
| 40 |
-
vocab_size (`int`, *optional*, defaults to 65024):
|
| 41 |
-
Vocabulary size of the Falcon model. Defines the number of different tokens that can be represented by the
|
| 42 |
-
`inputs_ids` passed when calling [`FalconModel`]
|
| 43 |
-
hidden_size (`int`, *optional*, defaults to 4544):
|
| 44 |
-
Dimension of the hidden representations.
|
| 45 |
-
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 46 |
-
Number of hidden layers in the Transformer decoder.
|
| 47 |
-
num_attention_heads (`int`, *optional*, defaults to 71):
|
| 48 |
-
Number of attention heads for each attention layer in the Transformer encoder.
|
| 49 |
-
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 50 |
-
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 51 |
-
use_cache (`bool`, *optional*, defaults to `True`):
|
| 52 |
-
Whether the model should return the last key/values attentions (not used by all models). Only relevant if
|
| 53 |
-
`config.is_decoder=True`.
|
| 54 |
-
layer_norm_epsilon (`float`, *optional*, defaults to 1e-5):
|
| 55 |
-
The epsilon used by the layer normalization layers.
|
| 56 |
-
hidden_dropout (`float`, *optional*, defaults to 0.0):
|
| 57 |
-
The dropout probability for MLP layers.
|
| 58 |
-
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 59 |
-
The dropout probability for attention layers.
|
| 60 |
-
num_kv_heads (`int`, *optional*):
|
| 61 |
-
Number of key-value heads to use per attention layer. If unset, defaults to the same value as
|
| 62 |
-
`num_attention_heads`.
|
| 63 |
-
alibi (`bool`, *optional*, defaults to `False`):
|
| 64 |
-
Whether to use ALiBi positional biases during self-attention.
|
| 65 |
-
new_decoder_architecture (`bool`, *optional*, defaults to `False`):
|
| 66 |
-
Whether to use the new (Falcon-40B) decoder architecture. If `True`, the `multi_query` and `parallel_attn`
|
| 67 |
-
arguments are ignored, as the new decoder always uses parallel attention.
|
| 68 |
-
multi_query (`bool`, *optional*, defaults to `True`):
|
| 69 |
-
Whether to use multi-query attention in the decoder. Ignored when `new_decoder_architecture` is `True`.
|
| 70 |
-
parallel_attn (`bool`, *optional*, defaults to `True`):
|
| 71 |
-
Whether to compute attention in parallel with the feedforward layer. If False, they are consecutive
|
| 72 |
-
instead, as in the original Transformer architecture. Ignored when `new_decoder_architecture` is `True`.
|
| 73 |
-
bias (`bool`, *optional*, defaults to `False`):
|
| 74 |
-
Whether to use bias on Linear layers.
|
| 75 |
-
bos_token_id (`int`, *optional*, defaults to 11):
|
| 76 |
-
The id of the "beginning-of-sequence" token.
|
| 77 |
-
eos_token_id (`int`, *optional*, defaults to 11):
|
| 78 |
-
The id of the "end-of-sequence" token.
|
| 79 |
-
|
| 80 |
-
Example:
|
| 81 |
-
|
| 82 |
-
```python
|
| 83 |
-
>>> from transformers import FalconModel, FalconConfig
|
| 84 |
-
|
| 85 |
-
>>> # Initializing a small (2-layer) Falcon configuration
|
| 86 |
-
>>> configuration = FalconConfig(num_hidden_layers=2)
|
| 87 |
-
|
| 88 |
-
>>> # Initializing a model from the small configuration
|
| 89 |
-
>>> model = FalconModel(configuration)
|
| 90 |
-
|
| 91 |
-
>>> # Accessing the model configuration
|
| 92 |
-
>>> configuration = model.config
|
| 93 |
-
```"""
|
| 94 |
-
model_type = "falcon"
|
| 95 |
-
keys_to_ignore_at_inference = ["past_key_values"]
|
| 96 |
-
|
| 97 |
-
def __init__(
|
| 98 |
-
self,
|
| 99 |
-
vocab_size=65024,
|
| 100 |
-
hidden_size=4544,
|
| 101 |
-
num_hidden_layers=32,
|
| 102 |
-
num_attention_heads=71,
|
| 103 |
-
layer_norm_epsilon=1e-5,
|
| 104 |
-
initializer_range=0.02,
|
| 105 |
-
use_cache=True,
|
| 106 |
-
hidden_dropout=0.0,
|
| 107 |
-
attention_dropout=0.0,
|
| 108 |
-
num_kv_heads=None,
|
| 109 |
-
alibi=False,
|
| 110 |
-
new_decoder_architecture=False,
|
| 111 |
-
multi_query=True,
|
| 112 |
-
parallel_attn=True,
|
| 113 |
-
bias=False,
|
| 114 |
-
bos_token_id=11,
|
| 115 |
-
eos_token_id=11,
|
| 116 |
-
**kwargs,
|
| 117 |
-
):
|
| 118 |
-
logger.warning_once(
|
| 119 |
-
"\nWARNING: You are currently loading Falcon using legacy code contained in the model repository. Falcon has now been fully ported into the Hugging Face transformers library. "
|
| 120 |
-
"For the most up-to-date and high-performance version of the Falcon model code, please update to the latest version of transformers and then load the model "
|
| 121 |
-
"without the trust_remote_code=True argument.\n"
|
| 122 |
-
)
|
| 123 |
-
self.vocab_size = vocab_size
|
| 124 |
-
# Backward compatibility with n_embed kwarg
|
| 125 |
-
n_embed = kwargs.pop("n_embed", None)
|
| 126 |
-
self.hidden_size = hidden_size if n_embed is None else n_embed
|
| 127 |
-
self.num_hidden_layers = num_hidden_layers
|
| 128 |
-
self.num_attention_heads = num_attention_heads
|
| 129 |
-
self.layer_norm_epsilon = layer_norm_epsilon
|
| 130 |
-
self.initializer_range = initializer_range
|
| 131 |
-
self.use_cache = use_cache
|
| 132 |
-
self.hidden_dropout = hidden_dropout
|
| 133 |
-
self.attention_dropout = attention_dropout
|
| 134 |
-
|
| 135 |
-
self.bos_token_id = bos_token_id
|
| 136 |
-
self.eos_token_id = eos_token_id
|
| 137 |
-
self.num_kv_heads = num_attention_heads if num_kv_heads is None else num_kv_heads
|
| 138 |
-
self.alibi = alibi
|
| 139 |
-
self.new_decoder_architecture = new_decoder_architecture
|
| 140 |
-
self.multi_query = multi_query # Ignored when new_decoder_architecture is True
|
| 141 |
-
self.parallel_attn = parallel_attn
|
| 142 |
-
self.bias = bias
|
| 143 |
-
|
| 144 |
-
super().__init__(bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
|
| 145 |
-
|
| 146 |
-
@property
|
| 147 |
-
def head_dim(self):
|
| 148 |
-
return self.hidden_size // self.num_attention_heads
|
| 149 |
-
|
| 150 |
-
@property
|
| 151 |
-
def rotary(self):
|
| 152 |
-
return not self.alibi
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class FalconConfig(PretrainedConfig):
|
| 4 |
+
model_type = "falcon"
|
| 5 |
+
|
| 6 |
+
def __init__(
|
| 7 |
+
self,
|
| 8 |
+
vocab_size: int = 65024,
|
| 9 |
+
hidden_size: int = 8192,
|
| 10 |
+
num_hidden_layers: int = 60,
|
| 11 |
+
num_attention_heads: int = 64,
|
| 12 |
+
num_kv_heads: int = 8,
|
| 13 |
+
max_position_embeddings: int = 8192,
|
| 14 |
+
layer_norm_epsilon: float = 1e-5,
|
| 15 |
+
initializer_range: float = 0.02,
|
| 16 |
+
use_cache: bool = True,
|
| 17 |
+
bos_token_id: int = 11,
|
| 18 |
+
eos_token_id: int = 11,
|
| 19 |
+
**kwargs
|
| 20 |
+
):
|
| 21 |
+
super().__init__(
|
| 22 |
+
bos_token_id=bos_token_id,
|
| 23 |
+
eos_token_id=eos_token_id,
|
| 24 |
+
**kwargs
|
| 25 |
+
)
|
| 26 |
+
self.vocab_size = vocab_size
|
| 27 |
+
self.hidden_size = hidden_size
|
| 28 |
+
self.num_hidden_layers = num_hidden_layers
|
| 29 |
+
self.num_attention_heads = num_attention_heads
|
| 30 |
+
self.num_kv_heads = num_kv_heads
|
| 31 |
+
self.max_position_embeddings = max_position_embeddings
|
| 32 |
+
self.layer_norm_epsilon = layer_norm_epsilon
|
| 33 |
+
self.initializer_range = initializer_range
|
| 34 |
+
self.use_cache = use_cache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|