w32zhong commited on
Commit
2ee22d4
·
verified ·
1 Parent(s): 1ac5f68

Upload folder using huggingface_hub

Browse files
beagle.json ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset.debug": false,
3
+ "dataset.eval_path": "./output/datasets/self_ds_Llama-2-7b-chat-hf/",
4
+ "dataset.git_diff": "",
5
+ "dataset.git_sha1": "unknown",
6
+ "dataset.manual_sample_ids": [],
7
+ "dataset.max_read_items": null,
8
+ "dataset.output_dir": "output",
9
+ "dataset.path": "output/datasets/ds_Llama-2-7b-chat-hf",
10
+ "dataset.read_eagle_format": false,
11
+ "dataset.run_name": "temp_run",
12
+ "dataset.seed": 42,
13
+ "dataset_generation.batch_size": 1,
14
+ "dataset_generation.debug": false,
15
+ "dataset_generation.debug_target": null,
16
+ "dataset_generation.ds_prefix": "ds_",
17
+ "dataset_generation.git_diff": "",
18
+ "dataset_generation.git_sha1": "unknown",
19
+ "dataset_generation.max_length": 4096,
20
+ "dataset_generation.output_dir": "output",
21
+ "dataset_generation.run_name": "temp_run",
22
+ "dataset_generation.save_every": 1000,
23
+ "dataset_generation.seed": 42,
24
+ "dataset_generation.sharegpt_path": "Aeala/ShareGPT_Vicuna_unfiltered",
25
+ "device_names": [
26
+ "NVIDIA L40S"
27
+ ],
28
+ "inference.alpha_stats": false,
29
+ "inference.debug": false,
30
+ "inference.draft_growing": false,
31
+ "inference.draft_tree_shape": "mc_sim_7b_64",
32
+ "inference.dynamic_draft": true,
33
+ "inference.dynamic_draft_all_top_k": 59,
34
+ "inference.dynamic_draft_max_depth": 5,
35
+ "inference.dynamic_draft_top_k": 10,
36
+ "inference.git_diff": "",
37
+ "inference.git_sha1": "unknown",
38
+ "inference.interactive": false,
39
+ "inference.max_draft_growing_depth": 100,
40
+ "inference.max_new_tokens": 512,
41
+ "inference.mode": "speculative",
42
+ "inference.output_dir": "output",
43
+ "inference.run_name": "temp_run",
44
+ "inference.seed": 42,
45
+ "inference.timer": false,
46
+ "modeling.add_noise": true,
47
+ "modeling.attention_wind": "3",
48
+ "modeling.ckpt_path": null,
49
+ "modeling.debug": false,
50
+ "modeling.decoder_key_remap": {},
51
+ "modeling.dtype": "torch.float32",
52
+ "modeling.frozen_targets": [],
53
+ "modeling.git_diff": "",
54
+ "modeling.git_sha1": "unknown",
55
+ "modeling.layer_path": "model.layers",
56
+ "modeling.lmhead_path": "lm_head",
57
+ "modeling.load_config_from_model_path": false,
58
+ "modeling.mask_token": "\u2581blank",
59
+ "modeling.mask_token_rate": 0,
60
+ "modeling.model_path": "beagle/models/llama/Llama-2-7b-chat-hf/",
61
+ "modeling.norm_path": "model.norm",
62
+ "modeling.only_first_state_distill": false,
63
+ "modeling.output_dir": "output",
64
+ "modeling.reuse_layer": null,
65
+ "modeling.rotary_path": "model.rotary_emb",
66
+ "modeling.run_name": "temp_run",
67
+ "modeling.save_loading": true,
68
+ "modeling.seed": 42,
69
+ "modeling.strictly_follow_eagle_decoder": false,
70
+ "modeling.tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
71
+ "modeling.use_dyt": false,
72
+ "modeling.use_fc_eagle": false,
73
+ "modeling.use_lower_layers": 0,
74
+ "modeling.use_moe": false,
75
+ "modeling.use_state_distill": true,
76
+ "training.adam_beta1": 0.9,
77
+ "training.adam_beta2": 0.95,
78
+ "training.average_tokens_across_devices": false,
79
+ "training.bf16": true,
80
+ "training.ddp_find_unused_parameters": false,
81
+ "training.debug": false,
82
+ "training.disable_sampled_print": false,
83
+ "training.eval_max_tti_wind": null,
84
+ "training.eval_steps": 100,
85
+ "training.eval_strategy": "steps",
86
+ "training.fast_dry_run": false,
87
+ "training.filter_out_shorts": true,
88
+ "training.force_model_parallel": false,
89
+ "training.git_diff": "diff --git a/beagle/configs.ini b/beagle/configs.ini\nindex 7e119f9..6c1545a 100644\n--- a/beagle/configs.ini\n+++ b/beagle/configs.ini\n@@ -157,6 +157,11 @@ per_device_train_batch_size = 1\n gradient_accumulation_steps = 8\n max_length = 4096\n \n+[training.@l40s_bs8_ctx2048_sm]\n+per_device_train_batch_size = 2\n+gradient_accumulation_steps = 4\n+max_length = 2048\n+\n [dataset]\n #manual_sample_ids = ['v4PzAY8_0', 'oM7QCY2_0', 'efVCaLN_0']\n manual_sample_ids = []",
90
+ "training.git_sha1": "0fd5ab514678b181c0602502811571cb9ffb5944",
91
+ "training.gradient_accumulation_steps": 4,
92
+ "training.learning_rate": 3e-05,
93
+ "training.logging_first_step": true,
94
+ "training.logging_steps": 20,
95
+ "training.loss_pivot_only": false,
96
+ "training.loss_reweighting": false,
97
+ "training.loss_reweighting_use_surrogate": false,
98
+ "training.lr_scheduler_type": "constant_with_warmup",
99
+ "training.max_grad_norm": 0.5,
100
+ "training.max_length": 2048,
101
+ "training.max_steps": -1,
102
+ "training.max_tti_wind": 1,
103
+ "training.model_init_ckpt": null,
104
+ "training.num_train_epochs": 10,
105
+ "training.number_sampled_print": "index",
106
+ "training.optim": "adamw_torch_fused",
107
+ "training.output_dir": "output/old-force-560",
108
+ "training.overwrite_output_dir": true,
109
+ "training.per_device_eval_batch_size": 1,
110
+ "training.per_device_train_batch_size": 2,
111
+ "training.project": "beagle",
112
+ "training.ranking_distill_topk": null,
113
+ "training.report_to": "wandb",
114
+ "training.resume_from_checkpoint": false,
115
+ "training.resume_wandb_runid": null,
116
+ "training.run_name": "temp_run",
117
+ "training.save_steps": 500,
118
+ "training.save_strategy": "steps",
119
+ "training.save_total_limit": 2,
120
+ "training.save_vram": true,
121
+ "training.seed": 42,
122
+ "training.slow_dry_run": false,
123
+ "training.tf32": false,
124
+ "training.topk_w": 1.0,
125
+ "training.use_eagle_pipeline": false,
126
+ "training.warmup_steps": 0,
127
+ "training.world_size": 1
128
+ }
config.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "meta-llama/Llama-2-7b-chat-hf",
3
+ "architectures": [
4
+ "LlamaForSpeculativeCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "auto_map": {
9
+ "AutoModelForSpeculativeCausalLM": "modeling_speculative_llama.LlamaForSpeculativeCausalLM"
10
+ },
11
+ "beagle_add_noise": true,
12
+ "beagle_attention_wind": "3",
13
+ "beagle_ckpt_path": null,
14
+ "beagle_debug": false,
15
+ "beagle_decoder_key_remap": {},
16
+ "beagle_dtype": "torch.float32",
17
+ "beagle_frozen_targets": [],
18
+ "beagle_git_diff": "",
19
+ "beagle_git_sha1": "unknown",
20
+ "beagle_layer_path": "model.layers",
21
+ "beagle_lmhead_path": "lm_head",
22
+ "beagle_load_config_from_model_path": false,
23
+ "beagle_mask_token": "\u2581blank",
24
+ "beagle_mask_token_rate": 0,
25
+ "beagle_model_path": "beagle/models/llama/Llama-2-7b-chat-hf/",
26
+ "beagle_norm_path": "model.norm",
27
+ "beagle_only_first_state_distill": false,
28
+ "beagle_output_dir": "output",
29
+ "beagle_reuse_layer": null,
30
+ "beagle_rotary_path": "model.rotary_emb",
31
+ "beagle_run_name": "temp_run",
32
+ "beagle_save_loading": true,
33
+ "beagle_seed": 42,
34
+ "beagle_strictly_follow_eagle_decoder": false,
35
+ "beagle_tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
36
+ "beagle_use_dyt": false,
37
+ "beagle_use_fc_eagle": false,
38
+ "beagle_use_lower_layers": 0,
39
+ "beagle_use_moe": false,
40
+ "beagle_use_state_distill": true,
41
+ "bos_token_id": 1,
42
+ "eos_token_id": 2,
43
+ "head_dim": 128,
44
+ "hidden_act": "silu",
45
+ "hidden_size": 4096,
46
+ "initializer_range": 0.02,
47
+ "intermediate_size": 11008,
48
+ "max_position_embeddings": 4096,
49
+ "mlp_bias": false,
50
+ "model_type": "llama",
51
+ "num_attention_heads": 32,
52
+ "num_hidden_layers": 0,
53
+ "num_key_value_heads": 32,
54
+ "pretraining_tp": 1,
55
+ "rms_norm_eps": 1e-05,
56
+ "rope_scaling": null,
57
+ "rope_theta": 10000.0,
58
+ "speculative_base_model": "meta-llama/Llama-2-7b-chat-hf",
59
+ "tie_word_embeddings": false,
60
+ "torch_dtype": "float32",
61
+ "transformers_version": "4.47.1",
62
+ "use_cache": true,
63
+ "vocab_size": 32000
64
+ }
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 1,
3
+ "do_sample": true,
4
+ "eos_token_id": 2,
5
+ "max_length": 4096,
6
+ "pad_token_id": 0,
7
+ "temperature": 0.6,
8
+ "top_p": 0.9,
9
+ "transformers_version": "4.47.1"
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3ed0ad203ff0d9a2292f5413b10b491b286756b50e0e6595d50f065d081f564
3
+ size 1858127224
modeling_speculative_llama.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.models.llama.modeling_llama import *
2
+ from beagle.mixin import *
3
+ from beagle.dyt import *
4
+ from beagle.moe import *
5
+
6
+
7
+ class LlamaBeagleAttention(LlamaAttention, BeagleAttentionMixin):
8
+
9
+ def forward(
10
+ self,
11
+ hidden_states: torch.Tensor,
12
+ attention_mask: Optional[torch.Tensor] = None,
13
+ position_ids: Optional[torch.LongTensor] = None,
14
+ past_key_value: Optional[Cache] = None,
15
+ output_attentions: bool = False,
16
+ use_cache: bool = False,
17
+ cache_position: Optional[torch.LongTensor] = None,
18
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
19
+ **kwargs,
20
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
21
+
22
+ bsz, q_len, _ = hidden_states.size()
23
+ query_states, key_states, value_states = self.qkv_transform(
24
+ hidden_states, past_key_value, use_cache, position_embeddings, **kwargs)
25
+
26
+ ################################################
27
+ ### everything kept original starting from here
28
+ ################################################
29
+
30
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
31
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
32
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
33
+
34
+ if attention_mask is not None: # no matter the length, we just slice it
35
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
36
+ attn_weights = attn_weights + causal_mask
37
+
38
+ # upcast attention to fp32
39
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
40
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
41
+ attn_output = torch.matmul(attn_weights, value_states)
42
+
43
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
44
+ raise ValueError(
45
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
46
+ f" {attn_output.size()}"
47
+ )
48
+
49
+ attn_output = attn_output.transpose(1, 2).contiguous()
50
+
51
+ attn_output = attn_output.reshape(bsz, q_len, -1)
52
+
53
+ attn_output = self.o_proj(attn_output)
54
+
55
+ if not output_attentions:
56
+ attn_weights = None
57
+
58
+ return attn_output, attn_weights, past_key_value
59
+
60
+
61
+ class LlamaBeagleDecoderLayer(LlamaDecoderLayer):
62
+ def __init__(self, config, layer_id):
63
+ super().__init__(config, layer_id)
64
+
65
+ if not config.beagle_use_fc_eagle:
66
+ delattr(self, 'self_attn')
67
+ recycle_vram()
68
+ self.self_attn = LlamaBeagleAttention(
69
+ config=config, layer_idx=layer_id
70
+ )
71
+
72
+ if config.beagle_use_moe:
73
+ def init_exp(moe_hidden_size, moe_intermediate_size):
74
+ config.hidden_size = moe_hidden_size
75
+ config.intermediate_size = moe_intermediate_size
76
+ return LlamaMLP(config)
77
+ from transformers import AutoConfig
78
+ moe_config = AutoConfig.from_pretrained(
79
+ "beagle/models/deepseek-moe", trust_remote_code=True)
80
+ moe_config.hidden_size = config.hidden_size
81
+ moe_config.moe_intermediate_size = config.intermediate_size
82
+ moe_config.n_routed_experts = 3
83
+ moe_config.n_shared_experts = None
84
+ moe_config.num_experts_per_tok = 1
85
+ self.mlp = DeepseekMoE(moe_config, init_exp)
86
+
87
+ if config.beagle_strictly_follow_eagle_decoder:
88
+ delattr(self, 'input_layernorm')
89
+ recycle_vram()
90
+ self.input_layernorm = nn.Identity()
91
+
92
+ elif config.beagle_use_dyt:
93
+ normalized_shape = self.input_layernorm.weight.shape
94
+ delattr(self, 'input_layernorm')
95
+ delattr(self, 'post_attention_layernorm')
96
+ recycle_vram()
97
+ self.input_layernorm = DynamicTanhNorm(normalized_shape)
98
+ self.post_attention_layernorm = DynamicTanhNorm(normalized_shape)
99
+
100
+
101
+ class LlamaForSpeculativeCausalLM(LlamaForCausalLM, BeagleMixin):
102
+ _no_split_modules = ["LlamaDecoderLayer", "LlamaBeagleDecoderLayer"]
103
+
104
+ def __init__(self, config):
105
+ super().__init__(config)
106
+
107
+ BeagleMixin.__init__(self, config)
108
+ self.speculative_decoder = LlamaBeagleDecoderLayer(config, layer_id=0)
109
+
110
+ self.post_init()
111
+
112
+ def forward(self, *args, **kwargs) -> Union[Tuple[torch.Tensor], BaseModelOutputWithPast]:
113
+ return self.beagle_forward(*args, **kwargs)
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "</s>",
17
+ "unk_token": {
18
+ "content": "<unk>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ }
30
+ },
31
+ "bos_token": "<s>",
32
+ "chat_template": "{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<<SYS>>\\n' + system_message + '\\n<</SYS>>\\n\\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{% generation %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endgeneration %}{% endif %}{% endfor %}",
33
+ "clean_up_tokenization_spaces": false,
34
+ "eos_token": "</s>",
35
+ "extra_special_tokens": {},
36
+ "legacy": false,
37
+ "model_max_length": 1000000000000000019884624838656,
38
+ "pad_token": "</s>",
39
+ "padding_side": "right",
40
+ "sp_model_kwargs": {},
41
+ "tokenizer_class": "LlamaTokenizer",
42
+ "unk_token": "<unk>",
43
+ "use_default_system_prompt": false
44
+ }