w32zhong commited on
Commit
55e1971
·
verified ·
1 Parent(s): 0b3b587

Upload folder using huggingface_hub

Browse files
beagle.json ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset.debug": false,
3
+ "dataset.git_diff": "",
4
+ "dataset.git_sha1": "unknown",
5
+ "dataset.manual_sample_ids": [],
6
+ "dataset.max_read_items": null,
7
+ "dataset.output_dir": "output",
8
+ "dataset.path": "/mnt/1T-temp-SSD/wei/datasets/ds_Llama-2-7b-chat-hf",
9
+ "dataset.read_eagle_format": false,
10
+ "dataset.run_name": "temp_run",
11
+ "dataset.seed": 42,
12
+ "dataset_generation.batch_size": 1,
13
+ "dataset_generation.debug": false,
14
+ "dataset_generation.debug_target": null,
15
+ "dataset_generation.ds_prefix": "ds_",
16
+ "dataset_generation.git_diff": "",
17
+ "dataset_generation.git_sha1": "unknown",
18
+ "dataset_generation.max_length": 4096,
19
+ "dataset_generation.output_dir": "output",
20
+ "dataset_generation.run_name": "temp_run",
21
+ "dataset_generation.save_every": 1000,
22
+ "dataset_generation.seed": 42,
23
+ "inference.debug": false,
24
+ "inference.detail_time_stats": false,
25
+ "inference.draft_tree_shape": "mc_sim_7b_65",
26
+ "inference.git_diff": "",
27
+ "inference.git_sha1": "unknown",
28
+ "inference.max_new_tokens": 512,
29
+ "inference.mode": "speculative",
30
+ "inference.output_dir": "output",
31
+ "inference.run_name": "temp_run",
32
+ "inference.seed": 42,
33
+ "modeling.add_noise": true,
34
+ "modeling.attention_offset": "random.randrange(0, 3)",
35
+ "modeling.attention_wind": "5",
36
+ "modeling.ckpt_path": null,
37
+ "modeling.debug": false,
38
+ "modeling.decoder_key_remap": {},
39
+ "modeling.draft_growing": false,
40
+ "modeling.dtype": "torch.bfloat16",
41
+ "modeling.frozen_targets": [],
42
+ "modeling.git_diff": "",
43
+ "modeling.git_sha1": "unknown",
44
+ "modeling.layer_path": "model.layers",
45
+ "modeling.lmhead_path": "lm_head",
46
+ "modeling.load_config_from_model_path": false,
47
+ "modeling.model_path": "beagle/models/llama2/Llama-2-7b-chat-hf/",
48
+ "modeling.norm_path": "model.norm",
49
+ "modeling.output_dir": "output",
50
+ "modeling.reuse_layer": null,
51
+ "modeling.rotary_path": "model.rotary_emb",
52
+ "modeling.run_name": "temp_run",
53
+ "modeling.seed": 42,
54
+ "modeling.strictly_follow_eagle_decoder": true,
55
+ "modeling.tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
56
+ "modeling.use_fc_eagle": false,
57
+ "modeling.use_lower_layers": 0,
58
+ "modeling.use_state_distill": false,
59
+ "training.adam_beta2": 0.95,
60
+ "training.bf16": true,
61
+ "training.ddp_find_unused_parameters": false,
62
+ "training.debug": false,
63
+ "training.eval_steps": 100,
64
+ "training.eval_strategy": "steps",
65
+ "training.filter_out_shorts": false,
66
+ "training.git_diff": "diff --git a/beagle/configs.ini b/beagle/configs.ini\nindex 677dffc..fa73a33 100644\n--- a/beagle/configs.ini\n+++ b/beagle/configs.ini\n@@ -73,6 +73,11 @@ per_device_train_batch_size = 4\n gradient_accumulation_steps = 4\n max_length = 2048\n \n+[training.@a6000ada_bs16_ctx4096]\n+per_device_train_batch_size = 2\n+gradient_accumulation_steps = 8\n+max_length = 4096\n+\n [dataset]\n #manual_sample_ids = ['v4PzAY8_0', 'oM7QCY2_0', 'efVCaLN_0']\n manual_sample_ids = []",
67
+ "training.git_sha1": "c83a51b10353968b27866251d5453dd84cba142d",
68
+ "training.gradient_accumulation_steps": 8,
69
+ "training.learning_rate": 3e-05,
70
+ "training.logging_steps": 1,
71
+ "training.lr_scheduler_type": "constant_with_warmup",
72
+ "training.max_grad_norm": 0.5,
73
+ "training.max_length": 4096,
74
+ "training.max_steps": -1,
75
+ "training.num_train_epochs": 10,
76
+ "training.optim": "adamw_torch_fused",
77
+ "training.output_dir": "output",
78
+ "training.overwrite_output_dir": true,
79
+ "training.per_device_eval_batch_size": 1,
80
+ "training.per_device_train_batch_size": 2,
81
+ "training.project": "beagle",
82
+ "training.report_to": "wandb",
83
+ "training.resume_from_checkpoint": false,
84
+ "training.resume_wandb_runid": null,
85
+ "training.run_name": "temp_run",
86
+ "training.save_steps": 500,
87
+ "training.save_strategy": "steps",
88
+ "training.save_total_limit": 2,
89
+ "training.save_vram": true,
90
+ "training.seed": 42,
91
+ "training.warmup_steps": 50
92
+ }
config.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_offset": "random.randrange(0, 3)",
13
+ "beagle_attention_wind": "5",
14
+ "beagle_ckpt_path": null,
15
+ "beagle_debug": false,
16
+ "beagle_decoder_key_remap": {},
17
+ "beagle_draft_growing": false,
18
+ "beagle_dtype": "torch.bfloat16",
19
+ "beagle_frozen_targets": [],
20
+ "beagle_git_diff": "",
21
+ "beagle_git_sha1": "unknown",
22
+ "beagle_layer_path": "model.layers",
23
+ "beagle_lmhead_path": "lm_head",
24
+ "beagle_load_config_from_model_path": false,
25
+ "beagle_model_path": "beagle/models/llama2/Llama-2-7b-chat-hf/",
26
+ "beagle_norm_path": "model.norm",
27
+ "beagle_output_dir": "output",
28
+ "beagle_reuse_layer": null,
29
+ "beagle_rotary_path": "model.rotary_emb",
30
+ "beagle_run_name": "temp_run",
31
+ "beagle_seed": 42,
32
+ "beagle_strictly_follow_eagle_decoder": true,
33
+ "beagle_tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
34
+ "beagle_use_fc_eagle": false,
35
+ "beagle_use_lower_layers": 0,
36
+ "beagle_use_state_distill": false,
37
+ "bos_token_id": 1,
38
+ "eos_token_id": 2,
39
+ "head_dim": 128,
40
+ "hidden_act": "silu",
41
+ "hidden_size": 4096,
42
+ "initializer_range": 0.02,
43
+ "intermediate_size": 11008,
44
+ "max_position_embeddings": 4096,
45
+ "mlp_bias": false,
46
+ "model_type": "llama",
47
+ "num_attention_heads": 32,
48
+ "num_hidden_layers": 32,
49
+ "num_key_value_heads": 32,
50
+ "pretraining_tp": 1,
51
+ "rms_norm_eps": 1e-05,
52
+ "rope_scaling": null,
53
+ "rope_theta": 10000.0,
54
+ "speculative_base_model": "meta-llama/Llama-2-7b-chat-hf",
55
+ "tie_word_embeddings": false,
56
+ "torch_dtype": "bfloat16",
57
+ "transformers_version": "4.47.1",
58
+ "use_cache": true,
59
+ "vocab_size": 32000
60
+ }
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:5a508a013225c7cc95854486586e19edad5450a775a677379a1b8382b5a66cb3
3
+ size 929055992
modeling_speculative_llama.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.models.llama.modeling_llama import *
2
+ from beagle.mixin import *
3
+
4
+
5
+ class LlamaBeagleAttention(LlamaAttention, BeagleAttentionMixin):
6
+
7
+ def forward(
8
+ self,
9
+ hidden_states: torch.Tensor,
10
+ attention_mask: Optional[torch.Tensor] = None,
11
+ position_ids: Optional[torch.LongTensor] = None,
12
+ past_key_value: Optional[Cache] = None,
13
+ output_attentions: bool = False,
14
+ use_cache: bool = False,
15
+ cache_position: Optional[torch.LongTensor] = None,
16
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
17
+ **kwargs,
18
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
19
+
20
+ bsz, q_len, _ = hidden_states.size()
21
+ query_states, key_states, value_states = self.qkv_transform(
22
+ hidden_states, past_key_value, use_cache, position_embeddings, **kwargs)
23
+
24
+ ################################################
25
+ ### everything kept original starting from here
26
+ ################################################
27
+
28
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
29
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
30
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
31
+
32
+ if attention_mask is not None: # no matter the length, we just slice it
33
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
34
+ attn_weights = attn_weights + causal_mask
35
+
36
+ # upcast attention to fp32
37
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
38
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
39
+ attn_output = torch.matmul(attn_weights, value_states)
40
+
41
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
42
+ raise ValueError(
43
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
44
+ f" {attn_output.size()}"
45
+ )
46
+
47
+ attn_output = attn_output.transpose(1, 2).contiguous()
48
+
49
+ attn_output = attn_output.reshape(bsz, q_len, -1)
50
+
51
+ attn_output = self.o_proj(attn_output)
52
+
53
+ if not output_attentions:
54
+ attn_weights = None
55
+
56
+ return attn_output, attn_weights, past_key_value
57
+
58
+
59
+ class LlamaBeagleDecoderLayer(LlamaDecoderLayer):
60
+ def __init__(self, config, layer_id):
61
+ super().__init__(config, layer_id)
62
+
63
+ if not config.beagle_use_fc_eagle:
64
+ delattr(self, 'self_attn')
65
+ recycle_vram()
66
+ self.self_attn = LlamaBeagleAttention(
67
+ config=config, layer_idx=layer_id
68
+ )
69
+
70
+ if config.beagle_strictly_follow_eagle_decoder:
71
+ delattr(self, 'input_layernorm')
72
+ recycle_vram()
73
+ self.input_layernorm = nn.Identity()
74
+
75
+
76
+ class LlamaForSpeculativeCausalLM(LlamaForCausalLM, BeagleMixin):
77
+ _no_split_modules = ["LlamaDecoderLayer", "LlamaBeagleDecoderLayer"]
78
+
79
+ def __init__(self, config):
80
+ super().__init__(config)
81
+
82
+ BeagleMixin.__init__(self, config)
83
+ self.speculative_decoder = LlamaBeagleDecoderLayer(config, layer_id=0)
84
+
85
+ self.post_init()
86
+
87
+ def forward(self, *args, **kwargs) -> Union[Tuple[torch.Tensor], BaseModelOutputWithPast]:
88
+ 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_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
+ }