appledora commited on
Commit
cc59ff0
·
verified ·
1 Parent(s): b54638d

Upload configuration_recast_llama.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. configuration_recast_llama.py +78 -0
configuration_recast_llama.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # filename: configuration_recast_llama2.py
2
+ from transformers import PretrainedConfig
3
+
4
+
5
+ class RECAST7b_llama(PretrainedConfig):
6
+ model_type = "recast7b_llama"
7
+ attribute_map = {
8
+ "hidden_size": "hidden_size",
9
+ "num_attention_heads": "num_attention_heads",
10
+ }
11
+
12
+ def __init__(
13
+ self,
14
+ vocab_size=32000,
15
+ hidden_size=4096,
16
+ intermediate_size=11008,
17
+ num_hidden_layers=32,
18
+ num_attention_heads=32,
19
+ num_key_value_heads=32, # Llama 2 uses same as num_attention_heads
20
+ hidden_act="silu",
21
+ max_position_embeddings=4096, # Standard Llama 2 context length
22
+ initializer_range=0.02,
23
+ rms_norm_eps=1e-6, # Llama 2 uses 1e-6
24
+ use_cache=True,
25
+ pad_token_id=0, # Llama 2 uses 0
26
+ bos_token_id=1, # Llama 2 uses 1
27
+ eos_token_id=2, # Llama 2 uses 2
28
+ pretraining_tp=1,
29
+ tie_word_embeddings=False,
30
+ rope_theta=10000.0, # Standard RoPE, no complex scaling
31
+ attention_bias=False,
32
+ attention_dropout=0.0,
33
+ mlp_bias=False,
34
+ # Template-specific configs
35
+ num_templates=2,
36
+ num_groups=16, # Adjust based on your compression needs
37
+ coef_height=8, # Adjust based on your compression needs
38
+ # num_cf=1,
39
+ torch_dtype="bfloat16",
40
+ **kwargs
41
+ ):
42
+ self.vocab_size = vocab_size
43
+ self.max_position_embeddings = max_position_embeddings
44
+ self.hidden_size = hidden_size
45
+ self.intermediate_size = intermediate_size
46
+ self.num_hidden_layers = num_hidden_layers
47
+ self.num_attention_heads = num_attention_heads
48
+ self.num_key_value_heads = num_key_value_heads
49
+ self.hidden_act = hidden_act
50
+ self.initializer_range = initializer_range
51
+ self.rms_norm_eps = rms_norm_eps
52
+ self.pretraining_tp = pretraining_tp
53
+ self.use_cache = use_cache
54
+ self.mlp_bias = mlp_bias
55
+ self.attention_bias = attention_bias
56
+ self.attention_dropout = attention_dropout
57
+ self.rope_theta = rope_theta
58
+ self.rope_scaling = None # Llama 2 doesn't use rope scaling
59
+ self.torch_dtype = torch_dtype
60
+
61
+ # Template-specific configs
62
+ self.num_templates = num_templates
63
+ self.num_groups = num_groups
64
+ self.coef_height = coef_height
65
+ # self.num_cf = num_cf
66
+ # self.num_rank = num_rank
67
+
68
+ # Calculate coef_width automatically
69
+ layers_per_group = self.num_hidden_layers // self.num_groups
70
+ self.coef_width = self.coef_height * layers_per_group
71
+
72
+ super().__init__(
73
+ pad_token_id=pad_token_id,
74
+ bos_token_id=bos_token_id,
75
+ eos_token_id=eos_token_id,
76
+ tie_word_embeddings=tie_word_embeddings,
77
+ **kwargs
78
+ )