Files changed (1) hide show
  1. README.md +183 -31
README.md CHANGED
@@ -1,54 +1,206 @@
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"/>Photo by Google DeepMind on Unsplash
54
+ </p>
55
 
56
+ | Model Detail | Description |
57
+ | ----------- | ----------- |
58
+ | 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.|
59
+ | Date | December, 2023 |
60
+ | Version | v3-2 |
61
+ | Type | 7B Large Language Model |
62
+ | Paper or Other Resources | [Medium Blog](https://medium.com/@NeuralCompressor/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3) |
63
+ | License | Apache 2.0 |
64
+ | Questions or Comments | [Community Tab](https://huggingface.co/Intel/neural-chat-7b-v3-3/discussions) and [Intel Developers Discord](https://discord.gg/rv2Gp55UJQ)|
65
 
66
+ | Intended Use | Description |
67
+ | ----------- | ----------- |
68
+ | 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. |
69
+ | Primary intended users | Anyone doing inference on language-related tasks. |
70
+ | 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.|
71
+
72
+ ## How To Use
73
+ ### Reproduce the model
74
+ 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:
75
+
76
+ ```bash
77
+ git clone https://github.com/intel/intel-extension-for-transformers.git
78
+ cd intel-extension-for-transformers
79
+
80
+ 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
81
+
82
+ 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
83
+
84
+ # after entering docker container
85
+ cd examples/finetuning/finetune_neuralchat_v3
86
 
87
  ```
88
+ We select the latest pretrained mistralai/Mistral-7B-v0.1 and the open source dataset Open-Orca/SlimOrca to conduct the experiment.
89
+
90
+ 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"`.
 
 
91
 
92
+ ```python
93
+ deepspeed --include localhost:0,1,2,3,4,5,6,7 \
94
+ --master_port 29501 \
95
+ finetune_neuralchat_v3.py
96
  ```
97
 
98
+ Merge the LoRA weights:
 
99
 
100
+ ```python
101
+ python apply_lora.py \
102
+ --base-model-path mistralai/Mistral-7B-v0.1 \
103
+ --lora-model-path finetuned_model/ \
104
+ --output-path finetuned_model_lora
105
+ ```
106
 
107
+ ### Use the model
108
+ Here is sample code if you want to use the model.
109
 
110
+ ```python
111
+ import transformers
112
 
 
113
 
114
+ model_name = 'Intel/neural-chat-7b-v3-2'
115
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
116
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
117
+
118
+ def generate_response(system_input, user_input):
119
+
120
+ # Format the input using the provided template
121
+ prompt = f"### System:\n{system_input}\n### User:\n{user_input}\n### Assistant:\n"
122
+
123
+ # Tokenize and encode the prompt
124
+ inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False)
125
+
126
+ # Generate a response
127
+ outputs = model.generate(inputs, max_length=1000, num_return_sequences=1)
128
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
129
+
130
+ # Extract only the assistant's response
131
+ return response.split("### Assistant:\n")[-1]
132
+
133
+
134
+ # Example usage
135
+ 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."
136
+ user_input = "calculate 100 + 520 + 60"
137
+ response = generate_response(system_input, user_input)
138
+ print(response)
139
+
140
+ # expected response
141
+ """
142
+ To calculate the sum of 100, 520, and 60, we will follow these steps:
143
+
144
+ 1. Add the first two numbers: 100 + 520
145
+ 2. Add the result from step 1 to the third number: (100 + 520) + 60
146
+
147
+ Step 1: Add 100 and 520
148
+ 100 + 520 = 620
149
+
150
+ Step 2: Add the result from step 1 to the third number (60)
151
+ (620) + 60 = 680
152
+
153
+ So, the sum of 100, 520, and 60 is 680.
154
+ """
155
+ ```
156
+
157
+ | Factors | Description |
158
+ | ----------- | ----------- |
159
+ | 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. |
160
+ | 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. |
161
+ | Environment | The model was trained on the Intel Gaudi 2 processor (8 cards). |
162
+ | 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). |
163
+
164
+ | Metrics | Description |
165
+ | ----------- | ----------- |
166
+ | 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. |
167
+ | Decision thresholds | No decision thresholds were used. |
168
+ | Approaches to uncertainty and variability | - |
169
+
170
+ | Training and Evaluation Data | Description |
171
+ | ----------- | ----------- |
172
+ | 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.|
173
+ | Motivation | - |
174
+ | Preprocessing | - |
175
+
176
+ ## Quantitative Analyses
177
+ 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:
178
 
 
 
 
179
 
 
 
180
 
181
  | Metric | Value |
182
  |-----------------------|---------------------------|
183
+ | Avg. | 68.29 |
184
+ | ARC (25-shot) | 67.49 |
185
+ | HellaSwag (10-shot) | 83.92 |
186
+ | MMLU (5-shot) | 63.55 |
187
+ | TruthfulQA (0-shot) | 59.68 |
188
+ | Winogrande (5-shot) | 79.95 |
189
+ | GSM8K (5-shot) | 55.12 |
190
+
191
+ ## Ethical Considerations and Limitations
192
+ 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.
193
+
194
+ Therefore, before deploying any applications of neural-chat-7b-v3-2, developers should perform safety testing.
195
+
196
+ ## Caveats and Recommendations
197
+
198
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
199
+
200
+ Here are a couple of useful links to learn more about Intel's AI software:
201
+ * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
202
+ * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
203
+
204
+ ## Disclaimer
205
+
206
+ 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.