Files changed (1) hide show
  1. README.md +183 -43
README.md CHANGED
@@ -1,25 +1,81 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
4
 
5
- ## Fine-tuning on Intel Gaudi2
6
 
7
- This model is a fine-tuned model based on [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). Then we align it with DPO algorithm. For more details, you can refer our blog: [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).
8
 
9
- ## Model date
10
- Neural-chat-7b-v3 was trained between September and October, 2023.
 
 
11
 
12
- ## Evaluation
 
 
 
 
 
 
 
 
13
 
14
- We submit our model to [open_llm_leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard), and the model performance has been **improved significantly** as we see from the average metric of 7 tasks from the leaderboard.
 
 
 
 
15
 
16
- | Model | Average ⬆️| ARC (25-s) ⬆️ | HellaSwag (10-s) ⬆️ | MMLU (5-s) ⬆️| TruthfulQA (MC) (0-s) ⬆️ | Winogrande (5-s) | GSM8K (5-s) | DROP (3-s) |
17
- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
18
- |[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 |
19
- | **Ours** | **57.31** | 67.15 | 83.29 | 62.26 | 58.77 | 78.06 | 1.21 | 50.43 |
20
-
21
-
22
- ## Training procedure
23
 
24
  ### Training hyperparameters
25
 
@@ -38,43 +94,100 @@ The following hyperparameters were used during training:
38
  - lr_scheduler_warmup_ratio: 0.03
39
  - num_epochs: 2.0
40
 
 
 
 
 
 
 
41
 
42
- ## Prompt Template
 
 
 
 
 
43
 
44
  ```
45
- ### System:
46
- {system}
47
- ### User:
48
- {usr}
49
- ### Assistant:
50
 
 
 
 
 
51
  ```
52
 
 
53
 
54
- ## FP32 Inference with transformers
 
 
 
 
 
55
 
56
- ```shell
57
- from transformers import AutoTokenizer, TextStreamer
58
- model_name = "Intel/neural-chat-7b-v3"
59
- prompt = "Once upon a time, there existed a little girl,"
60
 
61
- tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
62
- inputs = tokenizer(prompt, return_tensors="pt").input_ids
63
- streamer = TextStreamer(tokenizer)
64
 
65
- model = AutoModelForCausalLM.from_pretrained(model_name)
66
- outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
67
- )
68
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
- ## INT4 Inference with transformers
 
 
71
 
72
- ```shell
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  from transformers import AutoTokenizer, TextStreamer
74
  from intel_extension_for_transformers.transformers import AutoModelForCausalLM, WeightOnlyQuantConfig
75
  model_name = "Intel/neural-chat-7b-v3"
76
  config = WeightOnlyQuantConfig(compute_dtype="int8", weight_dtype="int4")
77
- prompt = "Once upon a time, there existed a little girl,"
78
 
79
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
80
  inputs = tokenizer(prompt, return_tensors="pt").input_ids
@@ -82,22 +195,49 @@ streamer = TextStreamer(tokenizer)
82
 
83
  model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=config)
84
  outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
85
- )
86
  ```
87
 
88
- ## Ethical Considerations and Limitations
89
- neural-chat-7b-v3 can produce factually incorrect output, and should not be relied on to produce factually accurate information. neural-chat-7b-v3 was trained on [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca) based on [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1). 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.
 
 
 
 
90
 
91
- Therefore, before deploying any applications of neural-chat-7b-v3, developers should perform safety testing.
 
 
 
 
92
 
93
- ## Disclaimer
 
 
 
 
 
 
 
94
 
95
- 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.
 
 
 
96
 
97
- ## Organizations developing the model
 
98
 
99
- The NeuralChat team with members from Intel/DCAI/AISE. Core team members: Kaokao Lv, Liang Lv, Chang Wang, Wenxin Zhang, Xuhui Ren, and Haihao Shen.
100
 
101
- ## Useful links
 
 
 
 
102
  * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
103
  * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ tags:
4
+ - LLMs
5
+ - mistral
6
+ - Intel
7
+ pipeline_tag: text-generation
8
+ base_model: mistralai/Mistral-7B-v0.1
9
+ model-index:
10
+ - name: neural-chat-7b-v3
11
+ results:
12
+ - task:
13
+ type: Large Language Model
14
+ name: Large Language Model
15
+ dataset:
16
+ type: Open-Orca/SlimOrca
17
+ name: Open-Orca/SlimOrca
18
+ metrics:
19
+ - type: ARC (25-shot)
20
+ value: 67.15
21
+ name: ARC (25-shot)
22
+ verified: true
23
+ - type: HellaSwag (10-shot)
24
+ value: 83.29
25
+ name: HellaSwag (10-shot)
26
+ verified: true
27
+ - type: MMLU (5-shot)
28
+ value: 62.26
29
+ name: MMLU (5-shot)
30
+ verified: true
31
+ - type: TruthfulQA (0-shot)
32
+ value: 58.77
33
+ name: TruthfulQA (0-shot)
34
+ verified: true
35
+ - type: Winogrande (5-shot)
36
+ value: 78.06
37
+ name: Winogrande (5-shot)
38
+ verified: true
39
+ - type: GSM8K (5-shot)
40
+ value: 1.21
41
+ name: GSM8K (5-shot)
42
+ verified: true
43
+ - type: DROP (3-shot)
44
+ value: 50.43
45
+ name: DROP (3-shot)
46
+ verified: true
47
+ datasets:
48
+ - Open-Orca/SlimOrca
49
+ language:
50
+ - en
51
  ---
52
 
53
+ ## Model Details: Neural-Chat-v3
54
 
55
+ 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).
56
 
57
+ <p align="center">
58
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/6297f0e30bd2f58c647abb1d/ctASHUT5QYIxMsOFa-sHC.webp" width="500"/>
59
+ Photo by [Google DeepMind on Unsplash](https://unsplash.com/@googledeepmind?utm_source=medium&utm_medium=referral)
60
+ </p>
61
 
62
+ | Model Detail | Description |
63
+ | ----------- | ----------- |
64
+ | 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.|
65
+ | Date | October, 2023 |
66
+ | Version | v3 |
67
+ | Type | 7B Large Language Model |
68
+ | Paper or Other Resources | [Medium Blog](https://medium.com/@NeuralCompressor/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3) |
69
+ | License | Apache 2.0 |
70
+ | Questions or Comments | [Community Tab](https://huggingface.co/Intel/neural-chat-7b-v3/discussions) and [Intel DevHub Discord](https://discord.gg/rv2Gp55UJQ)|
71
 
72
+ | Intended Use | Description |
73
+ | ----------- | ----------- |
74
+ | 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. |
75
+ | Primary intended users | Anyone doing inference on language-related tasks. |
76
+ | 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.|
77
 
78
+ ## How To Use
 
 
 
 
 
 
79
 
80
  ### Training hyperparameters
81
 
 
94
  - lr_scheduler_warmup_ratio: 0.03
95
  - num_epochs: 2.0
96
 
97
+ ### Reproduce the model
98
+ 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:
99
+
100
+ ```bash
101
+ git clone https://github.com/intel/intel-extension-for-transformers.git
102
+ cd intel-extension-for-transformers
103
 
104
+ 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
105
+
106
+ 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
107
+
108
+ # after entering docker container
109
+ cd examples/finetuning/finetune_neuralchat_v3
110
 
111
  ```
112
+ We select the latest pretrained mistralai/Mistral-7B-v0.1 and the open source dataset Open-Orca/SlimOrca to conduct the experiment.
113
+
114
+ 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"`.
 
 
115
 
116
+ ```python
117
+ deepspeed --include localhost:0,1,2,3,4,5,6,7 \
118
+ --master_port 29501 \
119
+ finetune_neuralchat_v3.py
120
  ```
121
 
122
+ Merge the LoRA weights:
123
 
124
+ ```python
125
+ python apply_lora.py \
126
+ --base-model-path mistralai/Mistral-7B-v0.1 \
127
+ --lora-model-path finetuned_model/ \
128
+ --output-path finetuned_model_lora
129
+ ```
130
 
131
+ You can then align the model following the steps in the [GitHub sample code](https://github.com/intel/intel-extension-for-transformers/blob/main/intel_extension_for_transformers/neural_chat/examples/finetuning/finetune_neuralchat_v3).
 
 
 
132
 
133
+ ### Use the model
 
 
134
 
135
+ ### FP32 Inference with Transformers
136
+
137
+ ```python
138
+ import transformers
139
+
140
+
141
+ model_name = 'Intel/neural-chat-7b-v3'
142
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
143
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
144
+
145
+ def generate_response(system_input, user_input):
146
+
147
+ # Format the input using the provided template
148
+ prompt = f"### System:\n{system_input}\n### User:\n{user_input}\n### Assistant:\n"
149
+
150
+ # Tokenize and encode the prompt
151
+ inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False)
152
 
153
+ # Generate a response
154
+ outputs = model.generate(inputs, max_length=1000, num_return_sequences=1)
155
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
156
 
157
+ # Extract only the assistant's response
158
+ return response.split("### Assistant:\n")[-1]
159
+
160
+
161
+ # Example usage
162
+ 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."
163
+ user_input = "calculate 100 + 520 + 60"
164
+ response = generate_response(system_input, user_input)
165
+ print(response)
166
+
167
+ # expected response
168
+ """
169
+ To calculate the sum of 100, 520, and 60, we will follow these steps:
170
+
171
+ 1. Add the first two numbers: 100 + 520
172
+ 2. Add the result from step 1 to the third number: (100 + 520) + 60
173
+
174
+ Step 1: Add 100 and 520
175
+ 100 + 520 = 620
176
+
177
+ Step 2: Add the result from step 1 to the third number (60)
178
+ (620) + 60 = 680
179
+
180
+ So, the sum of 100, 520, and 60 is 680.
181
+ """
182
+ ```
183
+
184
+ ### INT4 Inference with Transformers and Intel Extension for Transformers
185
+ ```python
186
  from transformers import AutoTokenizer, TextStreamer
187
  from intel_extension_for_transformers.transformers import AutoModelForCausalLM, WeightOnlyQuantConfig
188
  model_name = "Intel/neural-chat-7b-v3"
189
  config = WeightOnlyQuantConfig(compute_dtype="int8", weight_dtype="int4")
190
+ prompt = "Once upon a time, there was a horse in the forest,"
191
 
192
  tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
193
  inputs = tokenizer(prompt, return_tensors="pt").input_ids
 
195
 
196
  model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=config)
197
  outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
198
+
199
  ```
200
 
201
+ | Factors | Description |
202
+ | ----------- | ----------- |
203
+ | 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. |
204
+ | 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. |
205
+ | Environment | The model was trained on the Intel Gaudi 2 processor (8 cards). |
206
+ | 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). |
207
 
208
+ | Metrics | Description |
209
+ | ----------- | ----------- |
210
+ | 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. |
211
+ | Decision thresholds | No decision thresholds were used. |
212
+ | Approaches to uncertainty and variability | - |
213
 
214
+ | Training and Evaluation Data | Description |
215
+ | ----------- | ----------- |
216
+ | 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.|
217
+ | Motivation | - |
218
+ | Preprocessing | - |
219
+
220
+ ## Quantitative Analyses
221
+ 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](https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3). The metrics can be found below and show that the model has significantly improved performance from Mistral-7B-v0.1.
222
 
223
+ | Model | Average ⬆️| ARC (25-s) ⬆️ | HellaSwag (10-s) ⬆️ | MMLU (5-s) ⬆️| TruthfulQA (MC) (0-s) ⬆️ | Winogrande (5-s) | GSM8K (5-s) | DROP (3-s) |
224
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- |
225
+ |[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 |
226
+ | [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 |
227
 
228
+ ## Ethical Considerations and Limitations
229
+ Neural-chat-7b-v3 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.
230
 
231
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
232
 
233
+ ## Caveats and Recommendations
234
+
235
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
236
+
237
+ Here are a couple of useful links to learn more about Intel's AI software:
238
  * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
239
  * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
240
+
241
+ ## Disclaimer
242
+
243
+ 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.