zzy1123 commited on
Commit
7ebf906
·
verified ·
1 Parent(s): 03a7baa

Upload folder using huggingface_hub

Browse files
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "[MASK]": 32000
3
+ }
config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_mlp_class": "LLaMAMLP",
3
+ "_norm_class": "FusedRMSNorm",
4
+ "architectures": [
5
+ "DiffusionLlamaLM"
6
+ ],
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_diff_llama.DiffusionLlamaConfig",
9
+ "AutoModel": "modeling_diffusion_llama.DiffusionLlamaLM",
10
+ "AutoModelForCausalLM": "modeling_diff_llama.DiffusionLlamaLM"
11
+ },
12
+ "bias": false,
13
+ "block_size": 2048,
14
+ "condense_ratio": 1,
15
+ "dtype": "float32",
16
+ "eos_token_id": 2,
17
+ "intermediate_size": 4096,
18
+ "mask_token_id": 32000,
19
+ "model_type": "diff_llama_v2",
20
+ "n_embd": 1024,
21
+ "n_head": 16,
22
+ "n_layer": 20,
23
+ "n_query_groups": 16,
24
+ "name": "Diff_LLaMA_v2_336M",
25
+ "norm_eps": 1e-05,
26
+ "org": "Lightning-AI",
27
+ "pad_token_id": 0,
28
+ "padded_vocab_size": 32000,
29
+ "padding_multiple": 64,
30
+ "parallel_residual": false,
31
+ "rotary_percentage": 1.0,
32
+ "shared_attention_norm": false,
33
+ "transformers_version": "4.57.3",
34
+ "vocab_size": 32000
35
+ }
configuration_diff_llama.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+ from typing import Literal, Optional
3
+ from lit_gpt.config import Config
4
+
5
+ class DiffusionLlamaConfig(Config, PretrainedConfig):
6
+ model_type = "diff_llama_v2"
7
+ eos_token_id = 2,
8
+ pad_token_id = 0,
9
+ mask_token_id = 32000
10
+
11
+ def __init__(
12
+ self,
13
+ block_size: int = 4096,
14
+ vocab_size: int = 50254,
15
+ padding_multiple: int = 512,
16
+ padded_vocab_size: Optional[int] = None,
17
+ n_layer: int = 16,
18
+ n_head: int = 32,
19
+ n_embd: int = 4096,
20
+ rotary_percentage: float = 0.25,
21
+ parallel_residual: bool = True,
22
+ bias: bool = True,
23
+ n_query_groups: Optional[int] = None,
24
+ shared_attention_norm: bool = False,
25
+ _norm_class: Literal["LayerNorm", "RMSNorm", "FusedRMSNorm"] = "LayerNorm",
26
+ norm_eps: float = 1e-5,
27
+ _mlp_class: Literal["GptNeoxMLP", "LLaMAMLP"] = "GptNeoxMLP",
28
+ intermediate_size: Optional[int] = None,
29
+ condense_ratio: int = 1,
30
+ **kwargs,
31
+ ):
32
+ Config.__init__(
33
+ self,
34
+ block_size=block_size,
35
+ vocab_size=vocab_size,
36
+ padding_multiple=padding_multiple,
37
+ padded_vocab_size=padded_vocab_size,
38
+ n_layer=n_layer,
39
+ n_head=n_head,
40
+ n_embd=n_embd,
41
+ rotary_percentage=rotary_percentage,
42
+ parallel_residual=parallel_residual,
43
+ bias=bias,
44
+ n_query_groups=n_query_groups,
45
+ shared_attention_norm=shared_attention_norm,
46
+ _norm_class=_norm_class,
47
+ norm_eps=norm_eps,
48
+ _mlp_class=_mlp_class,
49
+ intermediate_size=intermediate_size,
50
+ condense_ratio=condense_ratio
51
+ )
52
+ PretrainedConfig.__init__(self, **kwargs)
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:671794256bef4dff670845aca8d38e5fa382931f8f96d40028b887ee01a116f8
3
+ size 1604509704
modeling_diff_llama.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from .configuration_diff_llama import DiffusionLlamaConfig
2
+ from lit_gpt.diffmodel import TransEncoder
3
+ from transformers import PreTrainedModel
4
+ from transformers.modeling_outputs import CausalLMOutputWithPast
5
+ import torch
6
+ import torch.nn as nn
7
+ from torch.nn import init
8
+ import math
9
+ from typing import Optional, Union, Tuple
10
+
11
+
12
+ class DiffusionLlamaLM(PreTrainedModel):
13
+ config_class = DiffusionLlamaConfig
14
+ base_model_prefix = "model"
15
+
16
+ def __init__(self, config: DiffusionLlamaConfig):
17
+ super().__init__(config)
18
+ self.model = TransEncoder(config)
19
+
20
+ # Initialize weights (Training feature)
21
+ self.post_init()
22
+
23
+ def _init_weights(self, module: nn.Module) -> None:
24
+ """
25
+ Initialization logic for training.
26
+ Adapted from original TransEncoder._init_weights.
27
+ """
28
+ n_layer = self.config.n_layer
29
+
30
+ if isinstance(module, nn.Embedding):
31
+ torch.nn.init.normal_(module.weight, mean=0.0, std=math.sqrt(2.0 / 5 / self.config.n_embd))
32
+ elif isinstance(module, nn.Linear):
33
+ torch.nn.init.normal_(module.weight, mean=0.0, std=math.sqrt(2.0 / 5 / self.config.n_embd))
34
+ if module.bias is not None:
35
+ torch.nn.init.zeros_(module.bias)
36
+
37
+ # Special initialization for SwiGLU / Projections based on names
38
+ # In HF _init_weights, 'module' is the current leaf. We check specific instances.
39
+ # if isinstance(module, LLaMAMLP):
40
+
41
+ # module is LLaMAMLP
42
+ for name, p in module.named_parameters():
43
+ if "proj.weight" in name:
44
+ nn.init.normal_(p, mean=0.0, std=1 / math.sqrt(self.config.n_embd) / n_layer)
45
+
46
+ # if isinstance(module, SwiGLU):
47
+ # for name, p in module.named_parameters():
48
+ # if "w3.weight" in name:
49
+ # nn.init.normal_(p, mean=0.0, std=1 / math.sqrt(self.config.n_embd) / n_layer)
50
+
51
+ # if isinstance(module, SelfAttention):
52
+ # for name, p in module.named_parameters():
53
+ # if "proj.weight" in name:
54
+ # nn.init.normal_(p, mean=0.0, std=1 / math.sqrt(self.config.n_embd) / n_layer)
55
+
56
+ def forward(self, input_ids: torch.Tensor, labels: Optional[torch.Tensor] = None, return_dict: Optional[bool] = None, **kwargs) -> Union[Tuple, CausalLMOutputWithPast]:
57
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
58
+
59
+ logits = self.model(input_ids)
60
+
61
+ loss = None
62
+ if labels is not None:
63
+ # Shift so that tokens < n predict n
64
+ shift_logits = logits[..., :-1, :].contiguous()
65
+ shift_labels = labels[..., 1:].contiguous()
66
+ loss_fct = nn.CrossEntropyLoss()
67
+ loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
68
+
69
+ if not return_dict:
70
+ return ((loss,) + (logits,)) if loss is not None else (logits,)
71
+
72
+ return CausalLMOutputWithPast(loss=loss, logits=logits)
special_tokens_map.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "mask_token": {
17
+ "content": "[MASK]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "pad_token": "<unk>",
24
+ "unk_token": {
25
+ "content": "<unk>",
26
+ "lstrip": false,
27
+ "normalized": false,
28
+ "rstrip": false,
29
+ "single_word": false
30
+ }
31
+ }
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,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
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
+ "32000": {
31
+ "content": "[MASK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ }
38
+ },
39
+ "bos_token": "<s>",
40
+ "clean_up_tokenization_spaces": false,
41
+ "eos_token": "</s>",
42
+ "extra_special_tokens": {},
43
+ "legacy": false,
44
+ "mask_token": "[MASK]",
45
+ "model_max_length": 1000000000000000019884624838656,
46
+ "pad_token": "<unk>",
47
+ "padding_side": "right",
48
+ "sp_model_kwargs": {},
49
+ "tokenizer_class": "LlamaTokenizer",
50
+ "unk_token": "<unk>",
51
+ "use_default_system_prompt": false
52
+ }