w32zhong commited on
Commit
dc22a00
·
verified ·
1 Parent(s): 8b26da2

Upload folder using huggingface_hub

Browse files
beagle.json ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset.debug": false,
3
+ "dataset.git_diff": "",
4
+ "dataset.git_sha1": "unknown",
5
+ "dataset.manual_sample_ids": [],
6
+ "dataset.output_dir": "output",
7
+ "dataset.path": "output/datasets/ds_Llama-2-7b-chat-hf/",
8
+ "dataset.run_name": "temp_run",
9
+ "dataset.seed": 42,
10
+ "dataset_generation.batch_size": 1,
11
+ "dataset_generation.debug": false,
12
+ "dataset_generation.debug_target": null,
13
+ "dataset_generation.ds_prefix": "ds_",
14
+ "dataset_generation.git_diff": "",
15
+ "dataset_generation.git_sha1": "unknown",
16
+ "dataset_generation.max_length": 2048,
17
+ "dataset_generation.output_dir": "output",
18
+ "dataset_generation.run_name": "temp_run",
19
+ "dataset_generation.save_every": 1000,
20
+ "dataset_generation.seed": 42,
21
+ "inference.debug": false,
22
+ "inference.draft_tree_shape": "mc_sim_7b_65",
23
+ "inference.git_diff": "",
24
+ "inference.git_sha1": "unknown",
25
+ "inference.max_new_tokens": 512,
26
+ "inference.mode": "speculative",
27
+ "inference.output_dir": "output",
28
+ "inference.run_name": "temp_run",
29
+ "inference.seed": 42,
30
+ "modeling.add_noise": false,
31
+ "modeling.attention_offset": "random.randrange(10)",
32
+ "modeling.attention_wind": "2",
33
+ "modeling.ckpt_path": null,
34
+ "modeling.debug": false,
35
+ "modeling.decoder_key_remap": {},
36
+ "modeling.dtype": "torch.bfloat16",
37
+ "modeling.frozen_targets": [],
38
+ "modeling.git_diff": "",
39
+ "modeling.git_sha1": "unknown",
40
+ "modeling.layer_path": "model.layers",
41
+ "modeling.lmhead_path": "lm_head",
42
+ "modeling.model_path": "beagle/models/llama2",
43
+ "modeling.norm_path": "model.norm",
44
+ "modeling.output_dir": "output",
45
+ "modeling.reuse_layer": -1,
46
+ "modeling.rotary_path": "model.rotary_emb",
47
+ "modeling.run_name": "temp_run",
48
+ "modeling.seed": 42,
49
+ "modeling.tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
50
+ "modeling.use_fc_eagle": false,
51
+ "modeling.use_lower_layers": 1,
52
+ "modeling.use_state_distill": false,
53
+ "training.adam_beta2": 0.95,
54
+ "training.bf16": true,
55
+ "training.ddp_find_unused_parameters": false,
56
+ "training.debug": false,
57
+ "training.filter_out_shorts": false,
58
+ "training.git_diff": "",
59
+ "training.git_sha1": "1cddc93f8ac2df83b8f58b148dd1b3b06eea8890",
60
+ "training.gradient_accumulation_steps": 4,
61
+ "training.learning_rate": 3e-05,
62
+ "training.logging_steps": 1,
63
+ "training.lr_scheduler_type": "constant_with_warmup",
64
+ "training.max_grad_norm": 0.5,
65
+ "training.max_length": 4096,
66
+ "training.max_steps": -1,
67
+ "training.num_train_epochs": 10,
68
+ "training.output_dir": "output",
69
+ "training.overwrite_output_dir": true,
70
+ "training.per_device_train_batch_size": 4,
71
+ "training.project": "beagle",
72
+ "training.report_to": "wandb",
73
+ "training.resume_from_checkpoint": false,
74
+ "training.resume_wandb_runid": null,
75
+ "training.run_name": "temp_run",
76
+ "training.save_steps": 500,
77
+ "training.save_total_limit": 2,
78
+ "training.seed": 42,
79
+ "training.warmup_steps": 50
80
+ }
config.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": false,
12
+ "beagle_attention_offset": "random.randrange(10)",
13
+ "beagle_attention_wind": "2",
14
+ "beagle_ckpt_path": null,
15
+ "beagle_debug": false,
16
+ "beagle_decoder_key_remap": {},
17
+ "beagle_dtype": "torch.bfloat16",
18
+ "beagle_frozen_targets": [],
19
+ "beagle_git_diff": "",
20
+ "beagle_git_sha1": "unknown",
21
+ "beagle_layer_path": "model.layers",
22
+ "beagle_lmhead_path": "lm_head",
23
+ "beagle_model_path": "beagle/models/llama2",
24
+ "beagle_norm_path": "model.norm",
25
+ "beagle_output_dir": "output",
26
+ "beagle_reuse_layer": -1,
27
+ "beagle_rotary_path": "model.rotary_emb",
28
+ "beagle_run_name": "temp_run",
29
+ "beagle_seed": 42,
30
+ "beagle_tokenizer_path": "meta-llama/Llama-2-7b-chat-hf",
31
+ "beagle_use_fc_eagle": false,
32
+ "beagle_use_lower_layers": 1,
33
+ "beagle_use_state_distill": false,
34
+ "bos_token_id": 1,
35
+ "eos_token_id": 2,
36
+ "head_dim": 128,
37
+ "hidden_act": "silu",
38
+ "hidden_size": 4096,
39
+ "initializer_range": 0.02,
40
+ "intermediate_size": 11008,
41
+ "max_position_embeddings": 4096,
42
+ "mlp_bias": false,
43
+ "model_type": "llama",
44
+ "num_attention_heads": 32,
45
+ "num_hidden_layers": 32,
46
+ "num_key_value_heads": 32,
47
+ "pretraining_tp": 1,
48
+ "rms_norm_eps": 1e-05,
49
+ "rope_scaling": null,
50
+ "rope_theta": 10000.0,
51
+ "speculative_base_model": "meta-llama/Llama-2-7b-chat-hf",
52
+ "tie_word_embeddings": false,
53
+ "torch_dtype": "bfloat16",
54
+ "transformers_version": "4.47.1",
55
+ "use_cache": true,
56
+ "vocab_size": 32000
57
+ }
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:c6336a63dd5b30860cede7c5af5dc4a6b0bc6f32d6a071673ad26166bfc5d6cf
3
+ size 1333832056
modeling_speculative_llama.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=0
68
+ )
69
+
70
+
71
+ class LlamaForSpeculativeCausalLM(LlamaForCausalLM, BeagleMixin):
72
+ _no_split_modules = ["LlamaDecoderLayer", "LlamaBeagleDecoderLayer"]
73
+
74
+ def __init__(self, config):
75
+ super().__init__(config)
76
+
77
+ BeagleMixin.__init__(self, config)
78
+ self.speculative_decoder = LlamaBeagleDecoderLayer(config, layer_id=0)
79
+
80
+ self.post_init()
81
+
82
+ def forward(self, *args, **kwargs) -> Union[Tuple[torch.Tensor], BaseModelOutputWithPast]:
83
+ 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 (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% 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' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% 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
+ }