Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,68 @@
|
|
1 |
-
---
|
2 |
-
license: apache-2.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- LLM360/AmberDatasets
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
metrics:
|
8 |
+
- accuracy
|
9 |
+
pipeline_tag: text-generation
|
10 |
+
---
|
11 |
+
|
12 |
+
# FBI-LLM-7B
|
13 |
+
## Model Details
|
14 |
+
|
15 |
+
This work presents a Fully BInarized Large Language Model (FBI-LLM), demonstrating for the first time how to train a large-scale binary language model (not the ternary LLM like BitNet b1.58 from scratch to match the performance of its full-precision counterparts (e.g., FP16 or BF16) in transformer-based LLMs. It achieves this by employing an autoregressive distillation (AD) loss with maintaining equivalent model dimensions (130M, 1.3B, 7B) and training data volume as regular LLM pretraining, while delivering competitive results in terms of perplexity and task-specific effectiveness. Intriguingly, by analyzing the training trajectory, we find that the pretrained weight is not necessary for training binarized LLMs from scratch. This research encourages a new computational framework and may facilitate the future design of specialized hardware tailored for fully 1-bit LLMs. We make all models, code, and training dataset fully accessible and transparent to support further research.
|
16 |
+
|
17 |
+
**Input**: Models input text only.
|
18 |
+
|
19 |
+
**Output**: Models generate text only.
|
20 |
+
|
21 |
+
## Tokenizer
|
22 |
+
We use the same tokenizer as [meta-llama/Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf)
|
23 |
+
|
24 |
+
## Training Data
|
25 |
+
We use [AmberDateset](https://huggingface.co/datasets/LLM360/AmberDatasets) to train our models.
|
26 |
+
|
27 |
+
## Result
|
28 |
+
|
29 |
+
<img src=https://huggingface.co/LiqunMa/FBI-LLM_7B/resolve/main/main_result.jpg width="90%" />
|
30 |
+
<!-- ![image](https://huggingface.co/LiqunMa/FBI-LLM_7B/resolve/main/main_result.jpg =200x) -->
|
31 |
+
|
32 |
+
## How to use
|
33 |
+
Please download the code from [LiqunMa/FBI-LLM](https://github.com/LiqunMa/FBI-LLM) firstly
|
34 |
+
```python
|
35 |
+
from pathlib import Path
|
36 |
+
from transformers import AutoTokenizer,LlamaConfig,LlamaForCausalLM, AutoModelForCausalLM
|
37 |
+
from qat.replace_module import replace_with_learnable_binarylinear
|
38 |
+
|
39 |
+
|
40 |
+
def load_model(model_size, model_dir):
|
41 |
+
assert model_size in ["130M", "1.3B", "7B"]
|
42 |
+
|
43 |
+
model_dir = Path(model_dir)
|
44 |
+
with Path(f'FBI-LLM_configs/FBI-LLM_llama2_{model_size}.json').open('r') as r_f:
|
45 |
+
config = json.load(r_f)
|
46 |
+
llama_config = LlamaConfig(**config)
|
47 |
+
model = LlamaForCausalLM(llama_config).to('cuda')
|
48 |
+
tokenizer = AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-hf', padding_side="right", use_fast=False)
|
49 |
+
model = replace_with_learnable_binarylinear(model, scaling_pattern = "column", keep_parts = ["lm_head"])
|
50 |
+
|
51 |
+
weight_dict = {}
|
52 |
+
ckpt_plist = [p for p in model_dir.iterdir() if p.suffix == '.bin']
|
53 |
+
for p in ckpt_plist:
|
54 |
+
weight_dict = torch.load(p)
|
55 |
+
for k,v in _weight_dict.items():
|
56 |
+
weight_dict[k] = v
|
57 |
+
|
58 |
+
model.load_state_dict(weight_dict)
|
59 |
+
for param in model.parameters():
|
60 |
+
param.data = param.data.to(torch.float16)
|
61 |
+
|
62 |
+
return model, tokenizer
|
63 |
+
```
|
64 |
+
|
65 |
+
## Citation
|
66 |
+
### BibTeX:
|
67 |
+
```
|
68 |
+
```
|