w32zhong commited on
Commit
688419f
·
verified ·
1 Parent(s): 4169e23

Upload folder using huggingface_hub

Browse files
beagle.json ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/hg_cache/temp_llama_dataset/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_64",
26
+ "inference.git_diff": "",
27
+ "inference.git_sha1": "unknown",
28
+ "inference.interactive": false,
29
+ "inference.max_new_tokens": 512,
30
+ "inference.mode": "speculative",
31
+ "inference.output_dir": "output",
32
+ "inference.run_name": "temp_run",
33
+ "inference.seed": 42,
34
+ "modeling.add_noise": true,
35
+ "modeling.attention_offset": "random.randrange(0, 3)",
36
+ "modeling.attention_wind": "5",
37
+ "modeling.ckpt_path": null,
38
+ "modeling.debug": false,
39
+ "modeling.decoder_key_remap": {},
40
+ "modeling.draft_growing": false,
41
+ "modeling.dtype": "torch.float32",
42
+ "modeling.frozen_targets": [],
43
+ "modeling.git_diff": "",
44
+ "modeling.git_sha1": "unknown",
45
+ "modeling.layer_path": "model.layers",
46
+ "modeling.lmhead_path": "lm_head",
47
+ "modeling.load_config_from_model_path": false,
48
+ "modeling.model_path": "beagle/models/llama2/Llama-2-7b-chat-hf/",
49
+ "modeling.norm_path": "model.norm",
50
+ "modeling.output_dir": "output",
51
+ "modeling.reuse_layer": null,
52
+ "modeling.rotary_path": "model.rotary_emb",
53
+ "modeling.run_name": "temp_run",
54
+ "modeling.save_loading": true,
55
+ "modeling.seed": 42,
56
+ "modeling.strictly_follow_eagle_decoder": false,
57
+ "modeling.tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
58
+ "modeling.use_fc_eagle": false,
59
+ "modeling.use_lower_layers": 0,
60
+ "modeling.use_state_distill": false,
61
+ "training.adam_beta1": 0.9,
62
+ "training.adam_beta2": 0.95,
63
+ "training.bf16": true,
64
+ "training.ddp_find_unused_parameters": false,
65
+ "training.debug": false,
66
+ "training.eval_steps": 100,
67
+ "training.eval_strategy": "steps",
68
+ "training.filter_out_shorts": false,
69
+ "training.git_diff": "diff --git a/README.md b/README.md\nindex 906761d..da3f70e 100644\n--- a/README.md\n+++ b/README.md\n@@ -21,13 +21,14 @@ Training:\n ```sh\n wandb login\n # multi-GPU training:\n-torchrun --standalone --nnodes=1 --nproc-per-node=2 -m beagle.train \\\n+CUDA_VISIBLE_DEVICES=0,1,2,3 \\\n+ torchrun --standalone --nnodes=1 --nproc-per-node=4 -m beagle.train \\\n --@llama2_7b_chat --@rtx4070tis_bs4_ctx4096 --modeling.use_lower_layers 0 \\\n --dataset.path /mnt/hg_cache/temp_llama_dataset/datasets/ds_Llama-2-7b-chat-hf \\\n --modeling.save_loading --training.report_to wandb\n \n # customized training:\n-CUDA_VISIBLE_DEVICES=1,2 \\\n+CUDA_VISIBLE_DEVICES=0,1 \\\n torchrun --standalone --nnodes=1 --nproc-per-node=2 -m beagle.train \\\n [email protected]_2.4B_instr --@rtx4070tis_dev_bs8 \\\n --dataset.path /mnt/truenas_sync/beagle_train_data/datasets/ds_EXAONE-3.5-2.4B-Instruct \\\ndiff --git a/beagle/train.py b/beagle/train.py\nindex 74795e1..c25096e 100644\n--- a/beagle/train.py\n+++ b/beagle/train.py\n@@ -199,8 +199,6 @@ def train(configs, run_name, tokenizer, model,\n if not configs.overwrite_output_dir:\n assert not os.path.exists(configs.output_dir), configs.output_dir\n \n- print('[rank]', rank, '/', world_size)\n-\n random.seed(configs.seed)\n torch.manual_seed(configs.seed)\n \n@@ -326,6 +324,9 @@ def main(config_file='beagle/configs.ini', **injects):\n configs.set_obj('training.git_diff', git_diff)\n master_print('[git]', git_sha1, '\\n', git_diff)\n \n+ print('[rank]', rank, '/', world_size)\n+ configs.set_obj('training.world_size', world_size)\n+\n if rank == 0 and configs.training.report_to == 'wandb':\n import wandb\n wandb.init(",
70
+ "training.git_sha1": "453d65d9cbee2ac0dedb03c3c49d99b1344a81ed",
71
+ "training.gradient_accumulation_steps": 8,
72
+ "training.learning_rate": 3e-05,
73
+ "training.logging_steps": 5,
74
+ "training.lr_scheduler_type": "constant_with_warmup",
75
+ "training.max_grad_norm": 0.5,
76
+ "training.max_length": 4096,
77
+ "training.max_steps": -1,
78
+ "training.model_init_ckpt": null,
79
+ "training.num_train_epochs": 10,
80
+ "training.optim": "adamw_torch_fused",
81
+ "training.output_dir": "output",
82
+ "training.overwrite_output_dir": true,
83
+ "training.per_device_eval_batch_size": 1,
84
+ "training.per_device_train_batch_size": 2,
85
+ "training.project": "beagle",
86
+ "training.report_to": "wandb",
87
+ "training.resume_from_checkpoint": false,
88
+ "training.resume_wandb_runid": null,
89
+ "training.run_name": "temp_run",
90
+ "training.save_steps": 500,
91
+ "training.save_strategy": "steps",
92
+ "training.save_total_limit": 2,
93
+ "training.save_vram": true,
94
+ "training.seed": 42,
95
+ "training.tf32": false,
96
+ "training.use_eagle_pipeline": false,
97
+ "training.warmup_steps": 2000,
98
+ "training.world_size": 1
99
+ }
config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.float32",
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_save_loading": true,
32
+ "beagle_seed": 42,
33
+ "beagle_strictly_follow_eagle_decoder": false,
34
+ "beagle_tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
35
+ "beagle_use_fc_eagle": false,
36
+ "beagle_use_lower_layers": 0,
37
+ "beagle_use_state_distill": false,
38
+ "bos_token_id": 1,
39
+ "eos_token_id": 2,
40
+ "head_dim": 128,
41
+ "hidden_act": "silu",
42
+ "hidden_size": 4096,
43
+ "initializer_range": 0.02,
44
+ "intermediate_size": 11008,
45
+ "max_position_embeddings": 4096,
46
+ "mlp_bias": false,
47
+ "model_type": "llama",
48
+ "num_attention_heads": 32,
49
+ "num_hidden_layers": 0,
50
+ "num_key_value_heads": 32,
51
+ "pretraining_tp": 1,
52
+ "rms_norm_eps": 1e-05,
53
+ "rope_scaling": null,
54
+ "rope_theta": 10000.0,
55
+ "speculative_base_model": "meta-llama/Llama-2-7b-chat-hf",
56
+ "tie_word_embeddings": false,
57
+ "torch_dtype": "float32",
58
+ "transformers_version": "4.47.1",
59
+ "use_cache": true,
60
+ "vocab_size": 32000
61
+ }
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:6b84ac6ec585166ca8ae8639bb5481bcfcc32fb2b443c96ebe0d1ebf828996df
3
+ size 1858127224
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
+ }