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