gate369 commited on
Commit
cb93332
·
verified ·
1 Parent(s): 8ecfc88

Model save

Browse files
README.md CHANGED
@@ -1,77 +1,49 @@
1
  ---
2
- datasets:
3
- - abideen/Cosmopedia-100k-pretrai-
4
- - LLMs/Alpaca-ShareGPT
5
- - roneneldan/TinyStories
6
- - Salesforce/wikitext
7
  tags:
8
- - Mistral
9
- - 1bit
10
- - bitnet
11
- - abideen
12
  ---
13
 
14
- How to Use.
15
- This code snippet loads the model and tokenizer to the cudae device, and converts the any linear layers in
16
- all child modules to -1, 1, or 0.
17
- This code can also be used to convert a fair amount of models to 1.58bit, however they will need to be trained before you can use
18
- them as they become extremly losyy.
19
- ```
20
- from transformers import AutoModelForCausalLM, AutoTokenizer
21
- from transformers.models.llama.modeling_llama import *
22
- # Load a pretrained BitNet model
23
- model = "liminerity/Bitnet-Mistral.0.2-v6.9"
24
- tokenizer = AutoTokenizer.from_pretrained(model)
25
- model = AutoModelForCausalLM.from_pretrained(model)
26
 
 
27
 
28
- def activation_quant(x):
29
- scale = 127.0 / x.abs().max(dim=-1, keepdim=True).values.clamp_(min=1e-5)
30
- y = (x * scale).round().clamp_(-128, 127)
31
- y = y / scale
32
- return y
33
- def weight_quant(w):
34
- scale = 1.0 / w.abs().mean().clamp_(min=1e-5)
35
- u = (w * scale).round().clamp_(-1, 1)
36
- u = u / scale
37
- return u
38
 
39
- class BitLinear(nn.Linear):
40
- def forward(self, x):
41
- w = self.weight # a weight tensor with shape [d, k]
42
- x = x.to(w.device)
43
- RMSNorm = LlamaRMSNorm(x.shape[-1]).to(w.device)
44
- x_norm = RMSNorm(x)
45
- # A trick for implementing Straight−Through−Estimator (STE) using detach()
46
- x_quant = x_norm + (activation_quant(x_norm) - x_norm).detach()
47
- w_quant = w + (weight_quant(w) - w).detach()
48
- y = F.linear(x_quant, w_quant)
49
- return y
50
 
51
- def convert_to_bitnet(model, copy_weights):
52
- for name, module in model.named_modules():
53
- # Replace linear layers with BitNet
54
- if isinstance(module, LlamaSdpaAttention) or isinstance(module, LlamaMLP):
55
- for child_name, child_module in module.named_children():
56
- if isinstance(child_module, nn.Linear):
57
- bitlinear = BitLinear(child_module.in_features, child_module.out_features, child_module.bias is not None).to(device="cuda:0")
58
- if copy_weights:
59
- bitlinear.weight = child_module.weight
60
- if child_module.bias is not None:
61
- bitlinear.bias = child_module.bias
62
- setattr(module, child_name, bitlinear)
63
- # Remove redundant input_layernorms
64
- elif isinstance(module, LlamaDecoderLayer):
65
- for child_name, child_module in module.named_children():
66
- if isinstance(child_module, LlamaRMSNorm) and child_name == "input_layernorm":
67
- setattr(module, child_name, nn.Identity().to(device="cuda:0"))
68
 
 
69
 
70
- convert_to_bitnet(model, copy_weights=True)
71
- model.to(device="cuda:0")
72
 
73
- prompt = "What is Machine Learning?"
74
- inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
75
- generate_ids = model.generate(inputs.input_ids, max_length=50)
76
- tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
77
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ base_model: liminerity/Bitnet-Mistral.0.2-v6.9
 
 
 
 
3
  tags:
4
+ - generated_from_trainer
5
+ model-index:
6
+ - name: Bitnet-Mistral.0.2-v6.9
7
+ results: []
8
  ---
9
 
10
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
11
+ should probably proofread and complete it, then remove this comment. -->
 
 
 
 
 
 
 
 
 
 
12
 
13
+ # Bitnet-Mistral.0.2-v6.9
14
 
15
+ This model is a fine-tuned version of [liminerity/Bitnet-Mistral.0.2-v6.9](https://huggingface.co/liminerity/Bitnet-Mistral.0.2-v6.9) on the None dataset.
 
 
 
 
 
 
 
 
 
16
 
17
+ ## Model description
 
 
 
 
 
 
 
 
 
 
18
 
19
+ More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ ## Intended uses & limitations
22
 
23
+ More information needed
 
24
 
25
+ ## Training and evaluation data
26
+
27
+ More information needed
28
+
29
+ ## Training procedure
30
+
31
+ ### Training hyperparameters
32
+
33
+ The following hyperparameters were used during training:
34
+ - learning_rate: 0.005
35
+ - train_batch_size: 8
36
+ - eval_batch_size: 8
37
+ - seed: 42
38
+ - gradient_accumulation_steps: 16
39
+ - total_train_batch_size: 128
40
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
41
+ - lr_scheduler_type: linear
42
+ - num_epochs: 3
43
+
44
+ ### Framework versions
45
+
46
+ - Transformers 4.41.2
47
+ - Pytorch 2.3.0+cu121
48
+ - Datasets 2.20.0
49
+ - Tokenizers 0.19.1
final_model/config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "liminerity/Bitnet-Mistral.0.2-v6.9",
3
+ "architectures": [
4
+ "MistralForCausalLM"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 256,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 512,
13
+ "max_position_embeddings": 4096,
14
+ "model_type": "mistral",
15
+ "num_attention_heads": 8,
16
+ "num_hidden_layers": 24,
17
+ "num_key_value_heads": 8,
18
+ "rms_norm_eps": 1e-05,
19
+ "rope_theta": 1000000.0,
20
+ "sliding_window": null,
21
+ "tie_word_embeddings": false,
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.41.2",
24
+ "use_cache": true,
25
+ "vocab_size": 32000
26
+ }
final_model/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.41.2"
6
+ }
final_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05985f5e4c4180e8a501137cf7bcc5a2d13a3f94a0dd475ff4494460e434eed7
3
+ size 128524840
final_model/special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
final_model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
final_model/tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dadfd56d766715c61d2ef780a525ab43b8e6da4de6865bda3d95fdef5e134055
3
+ size 493443
final_model/tokenizer_config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": true,
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
+ "clean_up_tokenization_spaces": false,
33
+ "eos_token": "</s>",
34
+ "legacy": true,
35
+ "model_max_length": 1000000000000000019884624838656,
36
+ "pad_token": "</s>",
37
+ "sp_model_kwargs": {},
38
+ "spaces_between_special_tokens": false,
39
+ "tokenizer_class": "LlamaTokenizer",
40
+ "unk_token": "<unk>",
41
+ "use_default_system_prompt": false
42
+ }
final_model/training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35fb96ca85885e2d93da071581f263a71b8c8722510bbc4107be59b3442c9034
3
+ size 5304
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.41.2"
6
+ }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1667afa824bd2b8cfeb8139c255f9e2d4d069117961b54a1ba2dd4783f4d7622
3
  size 128524840
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05985f5e4c4180e8a501137cf7bcc5a2d13a3f94a0dd475ff4494460e434eed7
3
  size 128524840
runs/Jun28_18-25-28_e63ef39226bb/events.out.tfevents.1719599151.e63ef39226bb.5920.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d4072015ed5797f65591b0b006f6906eea55b743b7bedc3b3fd7e0cdcc4417ac
3
+ size 12995
training_args.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:6093ede7cac8225f3a19ec50a6e634a2066a037951d940b11f496d37aaaf677e
3
- size 5240
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:35fb96ca85885e2d93da071581f263a71b8c8722510bbc4107be59b3442c9034
3
+ size 5304