aashish1904 commited on
Commit
9676fa3
1 Parent(s): 1a385e7

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +338 -0
README.md ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ license: apache-2.0
5
+ tags:
6
+ - LLMs
7
+ - mistral
8
+ - Intel
9
+ pipeline_tag: text-generation
10
+ base_model: mistralai/Mistral-7B-v0.1
11
+ model-index:
12
+ - name: neural-chat-7b-v3-1
13
+ results:
14
+ - task:
15
+ type: Large Language Model
16
+ name: Large Language Model
17
+ dataset:
18
+ type: Open-Orca/SlimOrca
19
+ name: Open-Orca/SlimOrca
20
+ metrics:
21
+ - type: ARC (25-shot)
22
+ value: 66.21
23
+ name: ARC (25-shot)
24
+ verified: true
25
+ - type: HellaSwag (10-shot)
26
+ value: 83.64
27
+ name: HellaSwag (10-shot)
28
+ verified: true
29
+ - type: MMLU (5-shot)
30
+ value: 62.37
31
+ name: MMLU (5-shot)
32
+ verified: true
33
+ - type: TruthfulQA (0-shot)
34
+ value: 59.65
35
+ name: TruthfulQA (0-shot)
36
+ verified: true
37
+ - type: Winogrande (5-shot)
38
+ value: 78.14
39
+ name: Winogrande (5-shot)
40
+ verified: true
41
+ - type: GSM8K (5-shot)
42
+ value: 19.56
43
+ name: GSM8K (5-shot)
44
+ verified: true
45
+ - type: DROP (3-shot)
46
+ value: 43.84
47
+ name: DROP (3-shot)
48
+ verified: true
49
+ datasets:
50
+ - Open-Orca/SlimOrca
51
+ language:
52
+ - en
53
+
54
+ ---
55
+
56
+ [![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
57
+
58
+
59
+ # QuantFactory/neural-chat-7b-v3-1-GGUF
60
+ This is quantized version of [Intel/neural-chat-7b-v3-1](https://huggingface.co/Intel/neural-chat-7b-v3-1) created using llama.cpp
61
+
62
+ # Original Model Card
63
+
64
+
65
+ ## Model Details: Neural-Chat-v3-1
66
+
67
+ This model is a fine-tuned 7B parameter LLM on the Intel Gaudi 2 processor from the [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) on the open source dataset [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca). The model was aligned using the Direct Performance Optimization (DPO) method with [Intel/orca_dpo_pairs](https://huggingface.co/datasets/Intel/orca_dpo_pairs). For more information, refer to the Medium article [The Practice of Supervised Fine-tuning and Direct Preference Optimization on Intel Gaudi2](https://medium.com/@NeuralCompressor/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3).
68
+
69
+ <p align="center">
70
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/6297f0e30bd2f58c647abb1d/ctASHUT5QYIxMsOFa-sHC.webp" width="500"/>
71
+ Photo by Google DeepMind on Unsplash
72
+ </p>
73
+
74
+ | Model Detail | Description |
75
+ | ----------- | ----------- |
76
+ | Model Authors - Company | Intel. The NeuralChat team with members from DCAI/AISE/AIPT. Core team members: Kaokao Lv, Liang Lv, Chang Wang, Wenxin Zhang, Xuhui Ren, and Haihao Shen.|
77
+ | Date | October, 2023 |
78
+ | Version | v3-1 |
79
+ | Type | 7B Large Language Model |
80
+ | Paper or Other Resources | [Medium Blog](https://medium.com/@NeuralCompressor/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3) |
81
+ | License | Apache 2.0 |
82
+ | Questions or Comments | [Community Tab](https://huggingface.co/Intel/neural-chat-7b-v3-1/discussions) and [Intel DevHub Discord](https://discord.gg/rv2Gp55UJQ)|
83
+
84
+ | Intended Use | Description |
85
+ | ----------- | ----------- |
86
+ | Primary intended uses | You can use the fine-tuned model for several language-related tasks. Checkout the [LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard) to see how this model is doing. |
87
+ | Primary intended users | Anyone doing inference on language-related tasks. |
88
+ | Out-of-scope uses | This model in most cases will need to be fine-tuned for your particular task. The model should not be used to intentionally create hostile or alienating environments for people.|
89
+
90
+ ## How To Use
91
+
92
+ Context length for this model: 8192 tokens (same as https://huggingface.co/mistralai/Mistral-7B-v0.1)
93
+
94
+ ### Training hyperparameters
95
+
96
+ The following hyperparameters were used during training:
97
+ - learning_rate: 1e-04
98
+ - train_batch_size: 1
99
+ - eval_batch_size: 2
100
+ - seed: 42
101
+ - distributed_type: multi-HPU
102
+ - num_devices: 8
103
+ - gradient_accumulation_steps: 8
104
+ - total_train_batch_size: 64
105
+ - total_eval_batch_size: 8
106
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
107
+ - lr_scheduler_type: cosine
108
+ - lr_scheduler_warmup_ratio: 0.03
109
+ - num_epochs: 2.0
110
+
111
+ ### Reproduce the model
112
+ Here is the sample code to reproduce the model: [GitHub sample code](https://github.com/intel/intel-extension-for-transformers/blob/main/intel_extension_for_transformers/neural_chat/examples/finetuning/finetune_neuralchat_v3). Here is the documentation to reproduce building the model:
113
+
114
+ ```bash
115
+ git clone https://github.com/intel/intel-extension-for-transformers.git
116
+ cd intel-extension-for-transformers
117
+
118
+ docker build --no-cache ./ --target hpu --build-arg REPO=https://github.com/intel/intel-extension-for-transformers.git --build-arg ITREX_VER=main -f ./intel_extension_for_transformers/neural_chat/docker/Dockerfile -t chatbot_finetuning:latest
119
+
120
+ docker run -it --runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --net=host --ipc=host chatbot_finetuning:latest
121
+
122
+ # after entering docker container
123
+ cd examples/finetuning/finetune_neuralchat_v3
124
+
125
+ ```
126
+ We select the latest pretrained mistralai/Mistral-7B-v0.1 and the open source dataset Open-Orca/SlimOrca to conduct the experiment.
127
+
128
+ The below script use deepspeed zero2 to lanuch the training with 8 cards Gaudi2. In the `finetune_neuralchat_v3.py`, the default `use_habana=True, use_lazy_mode=True, device="hpu"` for Gaudi2. And if you want to run it on NVIDIA GPU, you can set them `use_habana=False, use_lazy_mode=False, device="auto"`.
129
+
130
+ ```python
131
+ deepspeed --include localhost:0,1,2,3,4,5,6,7 \
132
+ --master_port 29501 \
133
+ finetune_neuralchat_v3.py
134
+ ```
135
+
136
+ Merge the LoRA weights:
137
+
138
+ ```python
139
+ python apply_lora.py \
140
+ --base-model-path mistralai/Mistral-7B-v0.1 \
141
+ --lora-model-path finetuned_model/ \
142
+ --output-path finetuned_model_lora
143
+ ```
144
+
145
+
146
+ ### FP32 Inference with Transformers
147
+
148
+ ```python
149
+ import transformers
150
+
151
+ model_name = 'Intel/neural-chat-7b-v3-1'
152
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
153
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
154
+
155
+ def generate_response(system_input, user_input):
156
+
157
+ # Format the input using the provided template
158
+ prompt = f"### System:\n{system_input}\n### User:\n{user_input}\n### Assistant:\n"
159
+
160
+ # Tokenize and encode the prompt
161
+ inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False)
162
+
163
+ # Generate a response
164
+ outputs = model.generate(inputs, max_length=1000, num_return_sequences=1)
165
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
166
+
167
+ # Extract only the assistant's response
168
+ return response.split("### Assistant:\n")[-1]
169
+
170
+
171
+ # Example usage
172
+ system_input = "You are a math expert assistant. Your mission is to help users understand and solve various math problems. You should provide step-by-step solutions, explain reasonings and give the correct answer."
173
+ user_input = "calculate 100 + 520 + 60"
174
+ response = generate_response(system_input, user_input)
175
+ print(response)
176
+
177
+ # expected response
178
+ """
179
+ To calculate the sum of 100, 520, and 60, we will follow these steps:
180
+
181
+ 1. Add the first two numbers: 100 + 520
182
+ 2. Add the result from step 1 to the third number: (100 + 520) + 60
183
+
184
+ Step 1: Add 100 and 520
185
+ 100 + 520 = 620
186
+
187
+ Step 2: Add the result from step 1 to the third number (60)
188
+ (620) + 60 = 680
189
+
190
+ So, the sum of 100, 520, and 60 is 680.
191
+ """
192
+ ```
193
+
194
+ ### BF16 Inference with Intel Extension for Transformers and Intel Extension for Pytorch
195
+ ```python
196
+ from transformers import AutoTokenizer, TextStreamer
197
+ import torch
198
+ from intel_extension_for_transformers.transformers import AutoModelForCausalLM
199
+ import intel_extension_for_pytorch as ipex
200
+
201
+ model_name = "Intel/neural-chat-7b-v3-1"
202
+ prompt = "Once upon a time, there existed a little girl,"
203
+
204
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
205
+ inputs = tokenizer(prompt, return_tensors="pt").input_ids
206
+ streamer = TextStreamer(tokenizer)
207
+
208
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
209
+ model = ipex.optimize(model.eval(), dtype=torch.bfloat16, inplace=True, level="O1", auto_kernel_selection=True)
210
+
211
+ outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
212
+ ```
213
+
214
+
215
+ ### INT4 Inference with Transformers and Intel Extension for Transformers
216
+ ```python
217
+ from transformers import AutoTokenizer, TextStreamer
218
+ from intel_extension_for_transformers.transformers import AutoModelForCausalLM, WeightOnlyQuantConfig
219
+ model_name = "Intel/neural-chat-7b-v3-1"
220
+
221
+ # for int8, should set weight_dtype="int8"
222
+ config = WeightOnlyQuantConfig(compute_dtype="bf16", weight_dtype="int4")
223
+ prompt = "Once upon a time, there existed a little girl,"
224
+
225
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
226
+ inputs = tokenizer(prompt, return_tensors="pt").input_ids
227
+ streamer = TextStreamer(tokenizer)
228
+
229
+ model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=config)
230
+ outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
231
+
232
+ ```
233
+
234
+ | Factors | Description |
235
+ | ----------- | ----------- |
236
+ | Groups | More details about the dataset and annotations can be found at [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca) and the associated paper at https://arxiv.org/abs/2306.02707. |
237
+ | Instrumentation | The performance of the model can vary depending on the inputs to the model. In this case, the prompts provided can drastically change the prediction of the language model. |
238
+ | Environment | The model was trained on the Intel Gaudi 2 processor (8 cards). |
239
+ | Card Prompts | Model deployment on alternate hardware and software will change model performance. The model evaluation factors are from the Hugging Face LLM leaderboard: ARC, HellaSwag, MMLU, TruthfulQA, Winogrande, GSM8K, and DROP (see Quantitative Analyses below). |
240
+
241
+ | Metrics | Description |
242
+ | ----------- | ----------- |
243
+ | Model performance measures | The model performance was evaluated against other LLMs according to the measures on the LLM leaderboard. These were selected as this has become the standard for LLM performance. |
244
+ | Decision thresholds | No decision thresholds were used. |
245
+ | Approaches to uncertainty and variability | - |
246
+
247
+ | Training and Evaluation Data | Description |
248
+ | ----------- | ----------- |
249
+ | Datasets | The training data are from [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca). There is no contamination from the GSM8k test set, as this is not a part of the Open-Orca/SlimOrca dataset.|
250
+ | Motivation | - |
251
+ | Preprocessing | - |
252
+
253
+ ## Quantitative Analyses
254
+ The model was submitted to the [LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard). The detailed submission can be found here: [https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-1](https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-1). The metrics can be found below and show that the model has significantly improved performance from Mistral-7B-v0.1 and neural-chat-7b-v3.
255
+
256
+ | Model | Average ⬆️| ARC (25-s) ⬆️ | HellaSwag (10-s) ⬆️ | MMLU (5-s) ⬆️| TruthfulQA (MC) (0-s) ⬆️ | Winogrande (5-s) | GSM8K (5-s) | DROP (3-s) |
257
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- |
258
+ |[mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) | 50.32 | 59.58 | 83.31 | 64.16 | 42.15 | 78.37 | 18.12 | 6.14 |
259
+ | [Intel/neural-chat-7b-v3](https://huggingface.co/Intel/neural-chat-7b-v3) | **57.31** | 67.15 | 83.29 | 62.26 | 58.77 | 78.06 | 1.21 | 50.43 |
260
+ | [Intel/neural-chat-7b-v3-1](https://huggingface.co/Intel/neural-chat-7b-v3-1) | **59.06** | 66.21 | 83.64 | 62.37 | 59.65 | 78.14 | 19.56 | 43.84 |
261
+
262
+ ## Testing Model Quantizability
263
+ The following code block can be run to determine, for PyTorch models, if that model is amenable to quantization.
264
+ One caveat - the Intel Extension for PyTorch uses optimum ipex, which is pre-release and needs further testing.
265
+
266
+ To install the dependencies, you should first install Intel Extensions for PyTorch and tehn pip install each of the following dependencies:
267
+ - torch
268
+ - optimum.intel
269
+ - optimum[ipex]
270
+ - transformers
271
+
272
+ ### Intel Extension for PyTorch method:
273
+ In this case, we are testing if neural-chat-7b-v3-1 can be quantized and this testing method demonstrates the model size change, for example:
274
+ when the base type is specified to be torch.bfloat16 but also specifying that load_in_4bit=True which causes the weights only to be quantized we see an output from the model testing as follows:
275
+ - **model_quantize_internal: model size = 27625.02 MB**
276
+ - **model_quantize_internal: quant size = 4330.80 MB**
277
+
278
+ This code should run from within a python script - such as ipex_test.py as follows:
279
+ ```python
280
+ import torch
281
+ import os
282
+ from transformers import AutoTokenizer
283
+ from intel_extension_for_transformers.transformers import AutoModelForCausalLM, pipeline
284
+ model_name = "Intel/neural-chat-7b-v3-1"
285
+ prompt = "Once upon a time, there existed a little girl,"
286
+
287
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
288
+ inputs = tokenizer(prompt, return_tensors="pt").input_ids
289
+
290
+ result = {torch.bfloat16:"failed"}
291
+ typ = torch.bfloat16
292
+ try:
293
+ model = AutoModelForCausalLM.from_pretrained(model_name, load_in_4bit=True, torch_dtype = typ)
294
+ outputs = model.generate(inputs, max_new_tokens=20)
295
+ result[typ] = f"passed, {os.stat(model.bin_file).st_size}"
296
+ except:
297
+ result[typ] = "failed"
298
+
299
+
300
+ print("\n\nResults of quantizing: ")
301
+ # determine if Quantized
302
+ with open(r"output.log", 'r') as fp:
303
+ for l_no, line in enumerate(fp):
304
+ # search string
305
+ if 'model_quantize_internal' in line:
306
+ print(line)
307
+
308
+ print("\n\nExecution results ")
309
+ for k,v in result.items():
310
+ print(k,v)
311
+
312
+ print("\n\nModel Output: ")
313
+ tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
314
+ ```
315
+ Run the code as folows from a bash terminal:
316
+ ```bash
317
+ python ipex_test.py 2>&1 | tee output.log
318
+ ```
319
+ The entire output is captured in the output.log but it will be summarized,
320
+ along with output from the model indicating either pass or fail of the quantization as well as model output for a given prompt.
321
+
322
+
323
+ ## Ethical Considerations and Limitations
324
+ Neural-chat-7b-v3-1 can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
325
+
326
+ Therefore, before deploying any applications of neural-chat-7b-v3-1, developers should perform safety testing.
327
+
328
+ ## Caveats and Recommendations
329
+
330
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
331
+
332
+ Here are a couple of useful links to learn more about Intel's AI software:
333
+ * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
334
+ * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
335
+
336
+ ## Disclaimer
337
+
338
+ The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please cosult an attorney before using this model for commercial purposes.