stardust-coder
commited on
Commit
•
a431732
1
Parent(s):
c7378b5
End of training
Browse files- README.md +116 -0
- generation_config.json +6 -0
- model.safetensors +1 -1
- modeling_bit_llama.py +134 -0
README.md
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- generated_from_trainer
|
4 |
+
model-index:
|
5 |
+
- name: myBit-Llama2-jp-127M-4
|
6 |
+
results: []
|
7 |
+
---
|
8 |
+
|
9 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
10 |
+
should probably proofread and complete it, then remove this comment. -->
|
11 |
+
|
12 |
+
# myBit-Llama2-jp-127M-4
|
13 |
+
|
14 |
+
This model is a fine-tuned version of [](https://huggingface.co/) on an unknown dataset.
|
15 |
+
It achieves the following results on the evaluation set:
|
16 |
+
- Loss: 3.0920
|
17 |
+
|
18 |
+
## Model description
|
19 |
+
|
20 |
+
More information needed
|
21 |
+
|
22 |
+
## Intended uses & limitations
|
23 |
+
|
24 |
+
More information needed
|
25 |
+
|
26 |
+
## Training and evaluation data
|
27 |
+
|
28 |
+
More information needed
|
29 |
+
|
30 |
+
## Training procedure
|
31 |
+
|
32 |
+
### Training hyperparameters
|
33 |
+
|
34 |
+
The following hyperparameters were used during training:
|
35 |
+
- learning_rate: 0.0024
|
36 |
+
- train_batch_size: 96
|
37 |
+
- eval_batch_size: 96
|
38 |
+
- seed: 42
|
39 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
40 |
+
- lr_scheduler_type: polynomial
|
41 |
+
- lr_scheduler_warmup_steps: 5000
|
42 |
+
- num_epochs: 1
|
43 |
+
|
44 |
+
### Training results
|
45 |
+
|
46 |
+
| Training Loss | Epoch | Step | Validation Loss |
|
47 |
+
|:-------------:|:-----:|:------:|:---------------:|
|
48 |
+
| 4.6932 | 0.02 | 2000 | 3.3504 |
|
49 |
+
| 3.252 | 0.03 | 4000 | 3.1987 |
|
50 |
+
| 3.1379 | 0.05 | 6000 | 3.0873 |
|
51 |
+
| 3.0466 | 0.06 | 8000 | 3.0233 |
|
52 |
+
| 2.9925 | 0.08 | 10000 | 2.9819 |
|
53 |
+
| 2.9553 | 0.1 | 12000 | 2.9471 |
|
54 |
+
| 2.9292 | 0.11 | 14000 | 2.9278 |
|
55 |
+
| 2.9158 | 0.13 | 16000 | 2.9159 |
|
56 |
+
| 2.907 | 0.15 | 18000 | 2.9084 |
|
57 |
+
| 2.9018 | 0.16 | 20000 | 2.9015 |
|
58 |
+
| 2.8945 | 0.18 | 22000 | 2.8971 |
|
59 |
+
| 2.8901 | 0.19 | 24000 | 2.9014 |
|
60 |
+
| 2.8906 | 0.21 | 26000 | 2.8980 |
|
61 |
+
| 2.8943 | 0.23 | 28000 | 2.9010 |
|
62 |
+
| 2.8985 | 0.24 | 30000 | 2.9165 |
|
63 |
+
| 3.0191 | 0.26 | 32000 | 3.3484 |
|
64 |
+
| 3.5616 | 0.28 | 34000 | 3.4516 |
|
65 |
+
| 3.2849 | 0.29 | 36000 | 3.0454 |
|
66 |
+
| 3.2425 | 0.31 | 38000 | 3.7183 |
|
67 |
+
| 3.655 | 0.32 | 40000 | 3.8947 |
|
68 |
+
| 3.3151 | 0.34 | 42000 | 3.6150 |
|
69 |
+
| 3.3482 | 0.36 | 44000 | 3.1714 |
|
70 |
+
| 3.1433 | 0.37 | 46000 | 3.1073 |
|
71 |
+
| 3.0462 | 0.39 | 48000 | 2.9786 |
|
72 |
+
| 3.0889 | 0.41 | 50000 | 3.3002 |
|
73 |
+
| 3.4652 | 0.42 | 52000 | 3.3920 |
|
74 |
+
| 3.3726 | 0.44 | 54000 | 3.1293 |
|
75 |
+
| 3.2314 | 0.45 | 56000 | 3.3841 |
|
76 |
+
| 3.5303 | 0.47 | 58000 | 3.3865 |
|
77 |
+
| 3.2828 | 0.49 | 60000 | 3.2591 |
|
78 |
+
| 3.0219 | 0.5 | 62000 | 2.9431 |
|
79 |
+
| 3.0714 | 0.52 | 64000 | 3.2328 |
|
80 |
+
| 3.1354 | 0.54 | 66000 | 3.0794 |
|
81 |
+
| 3.2194 | 0.55 | 68000 | 3.1326 |
|
82 |
+
| 3.394 | 0.57 | 70000 | 3.5974 |
|
83 |
+
| 3.2692 | 0.58 | 72000 | 3.1522 |
|
84 |
+
| 3.1513 | 0.6 | 74000 | 3.1398 |
|
85 |
+
| 3.2473 | 0.62 | 76000 | 3.1921 |
|
86 |
+
| 3.1717 | 0.63 | 78000 | 3.1827 |
|
87 |
+
| 3.211 | 0.65 | 80000 | 3.0845 |
|
88 |
+
| 2.9955 | 0.67 | 82000 | 3.0229 |
|
89 |
+
| 3.3145 | 0.68 | 84000 | 3.3382 |
|
90 |
+
| 3.0703 | 0.7 | 86000 | 3.5395 |
|
91 |
+
| 3.234 | 0.71 | 88000 | 2.9486 |
|
92 |
+
| 3.1077 | 0.73 | 90000 | 2.9488 |
|
93 |
+
| 3.1097 | 0.75 | 92000 | 2.9597 |
|
94 |
+
| 2.8979 | 0.76 | 94000 | 3.0215 |
|
95 |
+
| 3.236 | 0.78 | 96000 | 3.1758 |
|
96 |
+
| 3.1365 | 0.8 | 98000 | 3.4841 |
|
97 |
+
| 3.1954 | 0.81 | 100000 | 2.9520 |
|
98 |
+
| 3.2054 | 0.83 | 102000 | 3.6384 |
|
99 |
+
| 3.2957 | 0.84 | 104000 | 2.9212 |
|
100 |
+
| 2.9358 | 0.86 | 106000 | 3.0166 |
|
101 |
+
| 3.221 | 0.88 | 108000 | 3.3753 |
|
102 |
+
| 3.2241 | 0.89 | 110000 | 3.0858 |
|
103 |
+
| 3.1497 | 0.91 | 112000 | 2.9252 |
|
104 |
+
| 3.198 | 0.93 | 114000 | 3.8514 |
|
105 |
+
| 3.1427 | 0.94 | 116000 | 4.1130 |
|
106 |
+
| 3.2371 | 0.96 | 118000 | 2.8639 |
|
107 |
+
| 3.2576 | 0.97 | 120000 | 2.9192 |
|
108 |
+
| 3.3229 | 0.99 | 122000 | 3.0920 |
|
109 |
+
|
110 |
+
|
111 |
+
### Framework versions
|
112 |
+
|
113 |
+
- Transformers 4.38.2
|
114 |
+
- Pytorch 2.3.0+cu121
|
115 |
+
- Datasets 2.20.0
|
116 |
+
- Tokenizers 0.15.2
|
generation_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"transformers_version": "4.38.2"
|
6 |
+
}
|
model.safetensors
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
size 510960712
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0342f4324869091d5f08b1fdc85932b8dd0c4d690da3e0747329ddb83fc78d3c
|
3 |
size 510960712
|
modeling_bit_llama.py
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import warnings
|
2 |
+
from typing import Optional, Tuple
|
3 |
+
from transformers.models.llama.modeling_llama import (
|
4 |
+
LlamaConfig,
|
5 |
+
LlamaModel,
|
6 |
+
LlamaForCausalLM,
|
7 |
+
LlamaAttention,
|
8 |
+
LlamaFlashAttention2,
|
9 |
+
LlamaSdpaAttention,
|
10 |
+
LlamaMLP,
|
11 |
+
LlamaDecoderLayer,
|
12 |
+
)
|
13 |
+
from mybitnet.bitnet import BitLinear
|
14 |
+
import torch
|
15 |
+
from torch import nn
|
16 |
+
|
17 |
+
class BitLlamaConfig(LlamaConfig):
|
18 |
+
model_type = "bit_llama"
|
19 |
+
|
20 |
+
def __init__(self, bits=8, **kwargs):
|
21 |
+
super().__init__(**kwargs)
|
22 |
+
self.bits = bits
|
23 |
+
|
24 |
+
class BitLlamaMLP(LlamaMLP):
|
25 |
+
def __init__(self, config):
|
26 |
+
super().__init__(config)
|
27 |
+
self.gate_proj = BitLinear(self.hidden_size, self.intermediate_size, bias=False, bits=config.bits, flg_before_linear=False)
|
28 |
+
self.up_proj = BitLinear(self.hidden_size, self.intermediate_size, bias=False, bits=config.bits, flg_before_linear=True)
|
29 |
+
self.down_proj = BitLinear(self.intermediate_size, self.hidden_size, bias=False, bits=config.bits, flg_before_linear=True)
|
30 |
+
|
31 |
+
class BitLlamaAttention(LlamaAttention):
|
32 |
+
def __init__(self, config: BitLlamaConfig, layer_idx: Optional[int] = None):
|
33 |
+
super().__init__(config)
|
34 |
+
self.q_proj = BitLinear(self.hidden_size, self.num_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
35 |
+
self.k_proj = BitLinear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
36 |
+
self.v_proj = BitLinear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
37 |
+
self.o_proj = BitLinear(self.hidden_size, self.hidden_size, bias=False, bits=config.bits, flg_before_linear=True)
|
38 |
+
|
39 |
+
class BitLlamaFlashAttention2(LlamaFlashAttention2):
|
40 |
+
def __init__(self, config: BitLlamaConfig, layer_idx: Optional[int] = None):
|
41 |
+
super().__init__(config, layer_idx)
|
42 |
+
self.q_proj = BitLinear(self.hidden_size, self.num_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
43 |
+
self.k_proj = BitLinear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
44 |
+
self.v_proj = BitLinear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
45 |
+
self.o_proj = BitLinear(self.hidden_size, self.hidden_size, bias=False, bits=config.bits, flg_before_linear=True)
|
46 |
+
|
47 |
+
class BitLlamaSdpaAttention(LlamaSdpaAttention):
|
48 |
+
def __init__(self, config: BitLlamaConfig, layer_idx: Optional[int] = None):
|
49 |
+
super().__init__(config, layer_idx)
|
50 |
+
self.q_proj = BitLinear(self.hidden_size, self.num_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
51 |
+
self.k_proj = BitLinear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
52 |
+
self.v_proj = BitLinear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False, bits=config.bits, flg_before_linear=True)
|
53 |
+
self.o_proj = BitLinear(self.hidden_size, self.hidden_size, bias=False, bits=config.bits, flg_before_linear=True)
|
54 |
+
|
55 |
+
BITLLAMA_ATTENTION_CLASSES = {
|
56 |
+
"eager": BitLlamaAttention,
|
57 |
+
"flash_attention_2": BitLlamaFlashAttention2,
|
58 |
+
"sdpa": BitLlamaSdpaAttention,
|
59 |
+
}
|
60 |
+
|
61 |
+
class BitLlamaDecoderLayer(LlamaDecoderLayer):
|
62 |
+
def __init__(self, config: BitLlamaConfig, layer_idx: int):
|
63 |
+
super().__init__(config, layer_idx)
|
64 |
+
self.self_attn = BITLLAMA_ATTENTION_CLASSES[config._attn_implementation](config=config, layer_idx=layer_idx)
|
65 |
+
self.mlp = BitLlamaMLP(config)
|
66 |
+
del self.input_layernorm
|
67 |
+
del self.post_attention_layernorm
|
68 |
+
|
69 |
+
def forward(
|
70 |
+
self,
|
71 |
+
hidden_states: torch.Tensor,
|
72 |
+
attention_mask: Optional[torch.Tensor] = None,
|
73 |
+
position_ids: Optional[torch.LongTensor] = None,
|
74 |
+
past_key_value: Optional[Tuple[torch.Tensor]] = None,
|
75 |
+
output_attentions: Optional[bool] = False,
|
76 |
+
use_cache: Optional[bool] = False,
|
77 |
+
cache_position: Optional[torch.LongTensor] = None,
|
78 |
+
**kwargs,
|
79 |
+
) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
|
80 |
+
"""
|
81 |
+
refers: https://github.com/huggingface/transformers/blob/c5f0288bc7d76f65996586f79f69fba8867a0e67/src/transformers/models/llama/modeling_llama.py#L693
|
82 |
+
"""
|
83 |
+
if "padding_mask" in kwargs:
|
84 |
+
warnings.warn(
|
85 |
+
"Passing `padding_mask` is deprecated and will be removed in v4.37. Please make sure use `attention_mask` instead.`"
|
86 |
+
)
|
87 |
+
|
88 |
+
residual = hidden_states
|
89 |
+
|
90 |
+
# Self Attention
|
91 |
+
hidden_states, self_attn_weights, present_key_value = self.self_attn(
|
92 |
+
hidden_states=hidden_states,
|
93 |
+
attention_mask=attention_mask,
|
94 |
+
position_ids=position_ids,
|
95 |
+
past_key_value=past_key_value,
|
96 |
+
output_attentions=output_attentions,
|
97 |
+
use_cache=use_cache,
|
98 |
+
cache_position=cache_position,
|
99 |
+
**kwargs,
|
100 |
+
)
|
101 |
+
hidden_states = residual + hidden_states
|
102 |
+
|
103 |
+
# Fully Connected
|
104 |
+
residual = hidden_states
|
105 |
+
hidden_states = self.mlp(hidden_states)
|
106 |
+
hidden_states = residual + hidden_states
|
107 |
+
|
108 |
+
outputs = (hidden_states,)
|
109 |
+
|
110 |
+
if output_attentions:
|
111 |
+
outputs += (self_attn_weights,)
|
112 |
+
|
113 |
+
if use_cache:
|
114 |
+
outputs += (present_key_value,)
|
115 |
+
|
116 |
+
return outputs
|
117 |
+
|
118 |
+
class BitLlamaModel(LlamaModel):
|
119 |
+
config_class = BitLlamaConfig
|
120 |
+
|
121 |
+
def __init__(self, config: BitLlamaConfig):
|
122 |
+
super().__init__(config)
|
123 |
+
self.layers = nn.ModuleList(
|
124 |
+
[BitLlamaDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
125 |
+
)
|
126 |
+
|
127 |
+
class BitLlamaForCausalLM(LlamaForCausalLM):
|
128 |
+
config_class = BitLlamaConfig
|
129 |
+
|
130 |
+
def __init__(self, config: BitLlamaConfig):
|
131 |
+
super().__init__(config)
|
132 |
+
self.model = BitLlamaModel(config)
|
133 |
+
self.lm_head = BitLinear(config.hidden_size, config.vocab_size, bias=False, bits=config.bits, flg_before_linear=True)
|
134 |
+
|