chiliu commited on
Commit
7ba0cd6
1 Parent(s): b1ffc64
Files changed (1) hide show
  1. README.md +227 -0
README.md CHANGED
@@ -1,3 +1,230 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ library_name: transformers
5
+ tags:
6
+ - gpt
7
+ - llm
8
+ - large language model
9
+ inference: false
10
+ thumbnail: >-
11
+ https://h2o.ai/etc.clientlibs/h2o/clientlibs/clientlib-site/resources/images/favicon.ico
12
  license: apache-2.0
13
  ---
14
+ # Model Card
15
+ ## Github
16
+ https://github.com/chi2liu/mamba-gpt-3b
17
+
18
+ | Metric | Value |
19
+ |-----------------------|-------|
20
+ | MMLU (5-shot) | 25.3 |
21
+ | ARC (25-shot) | 40.5 |
22
+ | HellaSwag (10-shot) | 64.9 |
23
+ | TruthfulQA (0-shot) | 37.1 |
24
+ | Avg. | 42.0 |
25
+
26
+ We use state-of-the-art [Language Model Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness) to run the benchmark tests above.
27
+
28
+ ## Summary
29
+
30
+ We have fine-tuned the open-lama model and surpassed the original model in multiple evaluation subtasks, making it currently the best performing 3B model with comparable performance to llama-7b
31
+ - Base model: [openlm-research/open_llama_3b](https://huggingface.co/openlm-research/open_llama_3b)
32
+
33
+ ## Usage
34
+
35
+ To use the model with the `transformers` library on a machine with GPUs, first make sure you have the `transformers`, `accelerate` and `torch` libraries installed.
36
+
37
+ ```bash
38
+ pip install transformers==4.29.2
39
+ pip install accelerate==0.19.0
40
+ pip install torch==2.0.0
41
+ ```
42
+
43
+ ```python
44
+ import torch
45
+ from transformers import pipeline
46
+
47
+ generate_text = pipeline(
48
+ model="CobraMamba/mamba-gpt-3b",
49
+ torch_dtype="auto",
50
+ trust_remote_code=True,
51
+ use_fast=False,
52
+ device_map={"": "cuda:0"},
53
+ )
54
+
55
+ res = generate_text(
56
+ "Why is drinking water so healthy?",
57
+ min_new_tokens=2,
58
+ max_new_tokens=1024,
59
+ do_sample=False,
60
+ num_beams=1,
61
+ temperature=float(0.3),
62
+ repetition_penalty=float(1.2),
63
+ renormalize_logits=True
64
+ )
65
+ print(res[0]["generated_text"])
66
+ ```
67
+
68
+ You can print a sample prompt after the preprocessing step to see how it is feed to the tokenizer:
69
+
70
+ ```python
71
+ print(generate_text.preprocess("Why is drinking water so healthy?")["prompt_text"])
72
+ ```
73
+
74
+ ```bash
75
+ <|prompt|>Why is drinking water so healthy?</s><|answer|>
76
+ ```
77
+
78
+ Alternatively, you can download the mamba_gpt_pipeline.py, store it alongside your notebook, and construct the pipeline yourself from the loaded model and tokenizer. If the model and the tokenizer are fully supported in the `transformers` package, this will allow you to set `trust_remote_code=False`.
79
+
80
+ ```python
81
+ import torch
82
+ from mamba_gpt_pipeline.py import MambaGPTTextGenerationPipeline
83
+ from transformers import AutoModelForCausalLM, AutoTokenizer
84
+
85
+ tokenizer = AutoTokenizer.from_pretrained(
86
+ "CobraMamba/mamba-gpt-3b",
87
+ use_fast=False,
88
+ padding_side="left",
89
+ trust_remote_code=False,
90
+ )
91
+ model = AutoModelForCausalLM.from_pretrained(
92
+ "CobraMamba/mamba-gpt-3b",
93
+ torch_dtype="auto",
94
+ device_map={"": "cuda:0"},
95
+ trust_remote_code=False,
96
+ )
97
+ generate_text = MambaGPTTextGenerationPipeline(model=model, tokenizer=tokenizer)
98
+
99
+ res = generate_text(
100
+ "Why is drinking water so healthy?",
101
+ min_new_tokens=2,
102
+ max_new_tokens=1024,
103
+ do_sample=False,
104
+ num_beams=1,
105
+ temperature=float(0.3),
106
+ repetition_penalty=float(1.2),
107
+ renormalize_logits=True
108
+ )
109
+ print(res[0]["generated_text"])
110
+ ```
111
+
112
+
113
+ You may also construct the pipeline from the loaded model and tokenizer yourself and consider the preprocessing steps:
114
+
115
+ ```python
116
+ from transformers import AutoModelForCausalLM, AutoTokenizer
117
+
118
+ model_name = "CobraMamba/mamba-gpt-3b" # either local folder or huggingface model name
119
+ # Important: The prompt needs to be in the same format the model was trained with.
120
+ # You can find an example prompt in the experiment logs.
121
+ prompt = "<|prompt|>How are you?</s><|answer|>"
122
+
123
+ tokenizer = AutoTokenizer.from_pretrained(
124
+ model_name,
125
+ use_fast=False,
126
+ trust_remote_code=False,
127
+ )
128
+ model = AutoModelForCausalLM.from_pretrained(
129
+ model_name,
130
+ torch_dtype="auto",
131
+ device_map={"": "cuda:0"},
132
+ trust_remote_code=False,
133
+ )
134
+ model.cuda().eval()
135
+ inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).to("cuda")
136
+
137
+ # generate configuration can be modified to your needs
138
+ tokens = model.generate(
139
+ **inputs,
140
+ min_new_tokens=2,
141
+ max_new_tokens=1024,
142
+ do_sample=False,
143
+ num_beams=1,
144
+ temperature=float(0.3),
145
+ repetition_penalty=float(1.2),
146
+ renormalize_logits=True
147
+ )[0]
148
+
149
+ tokens = tokens[inputs["input_ids"].shape[1]:]
150
+ answer = tokenizer.decode(tokens, skip_special_tokens=True)
151
+ print(answer)
152
+ ```
153
+
154
+ ## Model Architecture
155
+
156
+ ```
157
+ LlamaForCausalLM(
158
+ (model): LlamaModel(
159
+ (embed_tokens): Embedding(32000, 4096, padding_idx=0)
160
+ (layers): ModuleList(
161
+ (0-31): 32 x LlamaDecoderLayer(
162
+ (self_attn): LlamaAttention(
163
+ (q_proj): Linear(in_features=4096, out_features=4096, bias=False)
164
+ (k_proj): Linear(in_features=4096, out_features=4096, bias=False)
165
+ (v_proj): Linear(in_features=4096, out_features=4096, bias=False)
166
+ (o_proj): Linear(in_features=4096, out_features=4096, bias=False)
167
+ (rotary_emb): LlamaRotaryEmbedding()
168
+ )
169
+ (mlp): LlamaMLP(
170
+ (gate_proj): Linear(in_features=4096, out_features=11008, bias=False)
171
+ (down_proj): Linear(in_features=11008, out_features=4096, bias=False)
172
+ (up_proj): Linear(in_features=4096, out_features=11008, bias=False)
173
+ (act_fn): SiLUActivation()
174
+ )
175
+ (input_layernorm): LlamaRMSNorm()
176
+ (post_attention_layernorm): LlamaRMSNorm()
177
+ )
178
+ )
179
+ (norm): LlamaRMSNorm()
180
+ )
181
+ (lm_head): Linear(in_features=4096, out_features=32000, bias=False)
182
+ )
183
+ ```
184
+
185
+ ## Evaluation
186
+ We evaluated OpenLLaMA on a wide range of tasks using [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness). The LLaMA results are generated by running the original LLaMA model on the same evaluation metrics. We note that our results for the LLaMA model differ slightly from the original LLaMA paper, which we believe is a result of different evaluation protocols. Similar differences have been reported in [this issue of lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness/issues/443). Additionally, we present the results of GPT-J, a 6B parameter model trained on the [Pile](https://pile.eleuther.ai/) dataset by [EleutherAI](https://www.eleuther.ai/).
187
+
188
+ The original LLaMA model was trained for 1 trillion tokens and GPT-J was trained for 500 billion tokens. We present the results in the table below. OpenLLaMA exhibits comparable performance to the original LLaMA and GPT-J across a majority of tasks, and outperforms them in some tasks.
189
+
190
+
191
+ | **Task/Metric** | finetuned-GPT 3B | OpenLLaMA 3B |
192
+ | ---------------------- | -------- | ------------ |
193
+ | anli_r1/acc | **0.35** | 0.33 |
194
+ | anli_r2/acc | **0.33** | 0.32 |
195
+ | anli_r3/acc | 0.35 | 0.35 |
196
+ | arc_challenge/acc | **0.35** | 0.34 |
197
+ | arc_challenge/acc_norm | 0.37 | 0.37 |
198
+ | arc_easy/acc | **0.71** | 0.69 |
199
+ | arc_easy/acc_norm | 0.65 | 0.65 |
200
+ | boolq/acc | **0.72** | 0.66 |
201
+ | hellaswag/acc | **0.49** | 0.43 |
202
+ | hellaswag/acc_norm | 0.66 | **0.67** |
203
+ | openbookqa/acc | 0.26 | **0.27** |
204
+ | openbookqa/acc_norm | 0.40 | 0.40 |
205
+ | piqa/acc | **0.76** | 0.75 |
206
+ | piqa/acc_norm | 0.76 | 0.76 |
207
+ | record/em | 0.88 | 0.88 |
208
+ | record/f1 | 0.88 | **0.89** |
209
+ | rte/acc | 0.55 | **0.58** |
210
+ | truthfulqa_mc/mc1 | **0.27** | 0.22 |
211
+ | truthfulqa_mc/mc2 | **0.37** | 0.35 |
212
+ | wic/acc | **0.49** | 0.48 |
213
+ | winogrande/acc | **0.63** | 0.62 |
214
+ | Average | **0.53** | 0.52 |
215
+
216
+
217
+ We removed the task CB and WSC from our benchmark, as our model performs suspiciously well on these two tasks. We hypothesize that there could be a benchmark data contamination in the training set.
218
+
219
+ ## Disclaimer
220
+
221
+ Please read this disclaimer carefully before using the large language model provided in this repository. Your use of the model signifies your agreement to the following terms and conditions.
222
+
223
+ - Biases and Offensiveness: The large language model is trained on a diverse range of internet text data, which may contain biased, racist, offensive, or otherwise inappropriate content. By using this model, you acknowledge and accept that the generated content may sometimes exhibit biases or produce content that is offensive or inappropriate. The developers of this repository do not endorse, support, or promote any such content or viewpoints.
224
+ - Limitations: The large language model is an AI-based tool and not a human. It may produce incorrect, nonsensical, or irrelevant responses. It is the user's responsibility to critically evaluate the generated content and use it at their discretion.
225
+ - Use at Your Own Risk: Users of this large language model must assume full responsibility for any consequences that may arise from their use of the tool. The developers and contributors of this repository shall not be held liable for any damages, losses, or harm resulting from the use or misuse of the provided model.
226
+ - Ethical Considerations: Users are encouraged to use the large language model responsibly and ethically. By using this model, you agree not to use it for purposes that promote hate speech, discrimination, harassment, or any form of illegal or harmful activities.
227
+ - Reporting Issues: If you encounter any biased, offensive, or otherwise inappropriate content generated by the large language model, please report it to the repository maintainers through the provided channels. Your feedback will help improve the model and mitigate potential issues.
228
+ - Changes to this Disclaimer: The developers of this repository reserve the right to modify or update this disclaimer at any time without prior notice. It is the user's responsibility to periodically review the disclaimer to stay informed about any changes.
229
+
230
+ By using the large language model provided in this repository, you agree to accept and comply with the terms and conditions outlined in this disclaimer. If you do not agree with any part of this disclaimer, you should refrain from using the model and any content generated by it.