jupyterjazz
commited on
Commit
•
3830381
1
Parent(s):
1752c7c
configuration
Browse filesSigned-off-by: jupyterjazz <saba.sturua@jina.ai>
- configuration_xlm_roberta.py +85 -36
configuration_xlm_roberta.py
CHANGED
@@ -1,44 +1,89 @@
|
|
1 |
-
from
|
|
|
2 |
import torch
|
|
|
|
|
3 |
|
4 |
class XLMRobertaFlashConfig(PretrainedConfig):
|
5 |
def __init__(
|
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 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
):
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
self.vocab_size = vocab_size
|
44 |
self.hidden_size = hidden_size
|
@@ -67,7 +112,11 @@ class XLMRobertaFlashConfig(PretrainedConfig):
|
|
67 |
self.emb_pooler = emb_pooler
|
68 |
self.matryoshka_dimensions = matryoshka_dimensions
|
69 |
self.truncate_dim = truncate_dim
|
70 |
-
if
|
|
|
|
|
|
|
|
|
71 |
self.torch_dtype = getattr(torch, torch_dtype)
|
72 |
else:
|
73 |
self.torch_dtype = torch_dtype
|
|
|
1 |
+
from typing import Any, Dict, List, Optional, Union
|
2 |
+
|
3 |
import torch
|
4 |
+
from transformers import PretrainedConfig
|
5 |
+
|
6 |
|
7 |
class XLMRobertaFlashConfig(PretrainedConfig):
|
8 |
def __init__(
|
9 |
+
self,
|
10 |
+
vocab_size: int = 250002,
|
11 |
+
hidden_size: int = 1024,
|
12 |
+
num_hidden_layers: int = 24,
|
13 |
+
num_attention_heads: int = 16,
|
14 |
+
intermediate_size: int = 4096,
|
15 |
+
hidden_act: str = "gelu",
|
16 |
+
hidden_dropout_prob: float = 0.1,
|
17 |
+
attention_probs_dropout_prob: float = 0.1,
|
18 |
+
max_position_embeddings: int = 8194,
|
19 |
+
type_vocab_size: int = 1,
|
20 |
+
initializer_range: float = 0.02,
|
21 |
+
layer_norm_eps: float = 1e-05,
|
22 |
+
pad_token_id: int = 1,
|
23 |
+
bos_token_id: int = 0,
|
24 |
+
eos_token_id: int = 2,
|
25 |
+
position_embedding_type: str = "rotary",
|
26 |
+
rotary_emb_base: float = 10000.0,
|
27 |
+
use_cache: bool = True,
|
28 |
+
classifier_dropout: Optional[float] = None,
|
29 |
+
lora_adaptations: Optional[List[str]] = None,
|
30 |
+
lora_prompts: Optional[Dict[str, str]] = None,
|
31 |
+
lora_rank: int = 4,
|
32 |
+
lora_dropout_p: float = 0.0,
|
33 |
+
lora_alpha: int = 1,
|
34 |
+
lora_main_params_trainable: bool = False,
|
35 |
+
load_trained_adapters: bool = False,
|
36 |
+
use_flash_attn: bool = True,
|
37 |
+
torch_dtype: Optional[Union[str, torch.dtype]] = None,
|
38 |
+
emb_pooler: Optional[str] = None,
|
39 |
+
matryoshka_dimensions: Optional[List[int]] = None,
|
40 |
+
truncate_dim: Optional[int] = None,
|
41 |
+
**kwargs: Dict[str, Any],
|
42 |
):
|
43 |
+
"""
|
44 |
+
Initialize the XLMRobertaFlashConfig configuration.
|
45 |
+
|
46 |
+
Args:
|
47 |
+
vocab_size (int): Size of the vocabulary.
|
48 |
+
hidden_size (int): Dimensionality of the encoder layers and the pooler layer.
|
49 |
+
num_hidden_layers (int): Number of hidden layers in the Transformer encoder.
|
50 |
+
num_attention_heads (int): Number of attention heads for each attention layer in the Transformer encoder.
|
51 |
+
intermediate_size (int): Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer.
|
52 |
+
hidden_act (str): The activation function to use.
|
53 |
+
hidden_dropout_prob (float): The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
|
54 |
+
attention_probs_dropout_prob (float): The dropout ratio for the attention probabilities.
|
55 |
+
max_position_embeddings (int): The maximum length of the position embeddings.
|
56 |
+
type_vocab_size (int): The vocabulary size of the token type ids.
|
57 |
+
initializer_range (float): The standard deviation for initializing all weight matrices.
|
58 |
+
layer_norm_eps (float): The epsilon used by the layer normalization layers.
|
59 |
+
pad_token_id (int): The ID of the padding token.
|
60 |
+
bos_token_id (int): The ID of the beginning-of-sequence token.
|
61 |
+
eos_token_id (int): The ID of the end-of-sequence token.
|
62 |
+
position_embedding_type (str): Type of position embeddings. Options are 'absolute', 'alibi', or 'rotary'.
|
63 |
+
rotary_emb_base (float): Base for rotary embeddings.
|
64 |
+
use_cache (bool): Whether or not the model should return the last key/values attentions (not used by all models).
|
65 |
+
classifier_dropout (Optional[float]): The dropout ratio for the classification head.
|
66 |
+
lora_adaptations (Optional[List[str]]): LoRA adaptations configuration.
|
67 |
+
lora_prompts (Optional[Dict[str, str]]): LoRA prompts configuration.
|
68 |
+
lora_rank (int): Rank for LoRA adaptations.
|
69 |
+
lora_dropout_p (float): Dropout probability for LoRA adaptations.
|
70 |
+
lora_alpha (int): Alpha parameter for LoRA.
|
71 |
+
lora_main_params_trainable (bool): Whether to make the main model parameters trainable when using LoRA.
|
72 |
+
load_trained_adapters (bool): Whether to load trained adapters.
|
73 |
+
use_flash_attn (bool): Whether to use FlashAttention.
|
74 |
+
torch_dtype (Optional[Union[str, torch.dtype]]): Data type for the tensors.
|
75 |
+
emb_pooler (Optional[str]): Pooling layer configuration.
|
76 |
+
matryoshka_dimensions (Optional[List[int]]): Configuration for matryoshka dimension reduction.
|
77 |
+
truncate_dim (Optional[int]): Dimension to truncate embeddings to, if any.
|
78 |
+
**kwargs (Dict[str, Any]): Additional keyword arguments passed to the configuration.
|
79 |
+
"""
|
80 |
|
81 |
+
super().__init__(
|
82 |
+
pad_token_id=pad_token_id,
|
83 |
+
bos_token_id=bos_token_id,
|
84 |
+
eos_token_id=eos_token_id,
|
85 |
+
**kwargs,
|
86 |
+
)
|
87 |
|
88 |
self.vocab_size = vocab_size
|
89 |
self.hidden_size = hidden_size
|
|
|
112 |
self.emb_pooler = emb_pooler
|
113 |
self.matryoshka_dimensions = matryoshka_dimensions
|
114 |
self.truncate_dim = truncate_dim
|
115 |
+
if (
|
116 |
+
torch_dtype
|
117 |
+
and hasattr(torch, torch_dtype)
|
118 |
+
and type(getattr(torch, torch_dtype)) is torch.dtype
|
119 |
+
):
|
120 |
self.torch_dtype = getattr(torch, torch_dtype)
|
121 |
else:
|
122 |
self.torch_dtype = torch_dtype
|