bconsolvo commited on
Commit
39c9d01
1 Parent(s): 558b0ef

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +183 -30
README.md CHANGED
@@ -1,17 +1,58 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
4
 
5
  ## Model Details: Neural-Chat-v3-3
6
 
7
- 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 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
- **Note:** Adjust lora modules to trade off truthfulqa and gsm8k performance on DPO stage.
10
 
 
 
 
 
11
 
12
  | Model Detail | Description |
13
  | ----------- | ----------- |
14
- | Model Authors - Company | Intel. 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.|
15
  | Date | December, 2023 |
16
  | Version | v3-3 |
17
  | Type | 7B Large Language Model |
@@ -21,47 +62,159 @@ This model is a fine-tuned 7B parameter LLM on the Intel Gaudi 2 processor from
21
 
22
  | Intended Use | Description |
23
  | ----------- | ----------- |
24
- | 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 and others from Intel are doing. |
25
  | Primary intended users | Anyone doing inference on language-related tasks. |
26
  | 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.|
27
 
28
- ## How to use and Sample Code
29
- 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).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- ## Prompt Template
32
- ```plaintext
33
- ### System:
34
- {system}
35
- ### User:
36
- {usr}
37
- ### Assistant:
38
 
 
 
 
 
 
39
  ```
40
 
41
- ## [Quantitative Analyses: Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
42
- Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-3) (**note:** the leaderboard removed drop task)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  | Metric | Value |
45
  |-----------------------|---------------------------|
46
- | Avg. | 69.83 |
47
- | ARC (25-shot) | 66.89 |
48
- | HellaSwag (10-shot) | 85.26 |
49
- | MMLU (5-shot) | 63.07 |
50
- | TruthfulQA (0-shot) | 63.01 |
51
- | Winogrande (5-shot) | 79.64 |
52
- | GSM8K (5-shot) | 61.11 |
53
-
54
- ## Useful links
55
- * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
56
- * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
57
 
58
  ## Ethical Considerations and Limitations
59
- neural-chat-7b-v3-3 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.
60
 
61
  Therefore, before deploying any applications of neural-chat-7b-v3-3, developers should perform safety testing.
62
 
63
- ## Disclaimer
64
 
65
- 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.
66
 
 
 
 
 
 
67
 
 
 
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-3
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: 66.89
20
+ name: ARC (25-shot)
21
+ verified: true
22
+ - type: HellaSwag (10-shot)
23
+ value: 85.26
24
+ name: HellaSwag (10-shot)
25
+ verified: true
26
+ - type: MMLU (5-shot)
27
+ value: 63.07
28
+ name: MMLU (5-shot)
29
+ verified: true
30
+ - type: TruthfulQA (0-shot)
31
+ value: 63.01
32
+ name: TruthfulQA (0-shot)
33
+ verified: true
34
+ - type: Winogrande (5-shot)
35
+ value: 79.64
36
+ name: Winogrande (5-shot)
37
+ verified: true
38
+ - type: GSM8K (5-shot)
39
+ value: 61.11
40
+ name: GSM8K (5-shot)
41
+ verified: true
42
  ---
43
 
44
  ## Model Details: Neural-Chat-v3-3
45
 
46
+ 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 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).
 
 
47
 
48
+ <p align="center">
49
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/6297f0e30bd2f58c647abb1d/ctASHUT5QYIxMsOFa-sHC.webp" width="500"/>
50
+ Photo by Google DeepMind on Unsplash
51
+ </p>
52
 
53
  | Model Detail | Description |
54
  | ----------- | ----------- |
55
+ | 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.|
56
  | Date | December, 2023 |
57
  | Version | v3-3 |
58
  | Type | 7B Large Language Model |
 
62
 
63
  | Intended Use | Description |
64
  | ----------- | ----------- |
65
+ | 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. |
66
  | Primary intended users | Anyone doing inference on language-related tasks. |
67
  | 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.|
68
 
69
+ ## How To Use
70
+ ### Reproduce the model
71
+ 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:
72
+
73
+ ```bash
74
+ git clone https://github.com/intel/intel-extension-for-transformers.git
75
+ cd intel-extension-for-transformers
76
+
77
+ 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
78
+
79
+ 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
80
+
81
+ # after entering docker container
82
+ cd examples/finetuning/finetune_neuralchat_v3
83
+
84
+ ```
85
+ We select the latest pretrained mistralai/Mistral-7B-v0.1 and the open source dataset Open-Orca/SlimOrca to conduct the experiment.
86
+
87
+ 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"`.
88
+
89
+ ```python
90
+ deepspeed --include localhost:0,1,2,3,4,5,6,7 \
91
+ --master_port 29501 \
92
+ finetune_neuralchat_v3.py
93
+ ```
94
 
95
+ Merge the LoRA weights:
 
 
 
 
 
 
96
 
97
+ ```python
98
+ python apply_lora.py \
99
+ --base-model-path mistralai/Mistral-7B-v0.1 \
100
+ --lora-model-path finetuned_model/ \
101
+ --output-path finetuned_model_lora
102
  ```
103
 
104
+ ### Use the model
105
+
106
+ ### FP32 Inference with Transformers
107
+
108
+ ```python
109
+ import transformers
110
+
111
+
112
+ model_name = 'Intel/neural-chat-7b-v3-3'
113
+ model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
114
+ tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
115
+
116
+ def generate_response(system_input, user_input):
117
+
118
+ # Format the input using the provided template
119
+ prompt = f"### System:\n{system_input}\n### User:\n{user_input}\n### Assistant:\n"
120
+
121
+ # Tokenize and encode the prompt
122
+ inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False)
123
+
124
+ # Generate a response
125
+ outputs = model.generate(inputs, max_length=1000, num_return_sequences=1)
126
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
127
+
128
+ # Extract only the assistant's response
129
+ return response.split("### Assistant:\n")[-1]
130
+
131
+
132
+ # Example usage
133
+ 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."
134
+ user_input = "calculate 100 + 520 + 60"
135
+ response = generate_response(system_input, user_input)
136
+ print(response)
137
+
138
+ # expected response
139
+ """
140
+ To calculate the sum of 100, 520, and 60, we will follow these steps:
141
+
142
+ 1. Add the first two numbers: 100 + 520
143
+ 2. Add the result from step 1 to the third number: (100 + 520) + 60
144
+
145
+ Step 1: Add 100 and 520
146
+ 100 + 520 = 620
147
+
148
+ Step 2: Add the result from step 1 to the third number (60)
149
+ (620) + 60 = 680
150
+
151
+ So, the sum of 100, 520, and 60 is 680.
152
+ """
153
+ ```
154
+
155
+ ### INT4 Inference with Transformers and Intel Extension for Transformers
156
+ ```python
157
+ from transformers import AutoTokenizer, TextStreamer
158
+ from intel_extension_for_transformers.transformers import AutoModelForCausalLM, WeightOnlyQuantConfig
159
+ model_name = "Intel/neural-chat-7b-v3-3"
160
+ config = WeightOnlyQuantConfig(compute_dtype="int8", weight_dtype="int4")
161
+ prompt = "Once upon a time, there existed a little girl,"
162
+
163
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
164
+ inputs = tokenizer(prompt, return_tensors="pt").input_ids
165
+ streamer = TextStreamer(tokenizer)
166
+
167
+ model = AutoModelForCausalLM.from_pretrained(model_name, quantization_config=config)
168
+ outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)
169
+
170
+ ```
171
+
172
+
173
+ | Factors | Description |
174
+ | ----------- | ----------- |
175
+ | 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. |
176
+ | 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. |
177
+ | Environment | The model was trained on the Intel Gaudi 2 processor (8 cards). |
178
+ | 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). |
179
+
180
+ | Metrics | Description |
181
+ | ----------- | ----------- |
182
+ | 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. |
183
+ | Decision thresholds | No decision thresholds were used. |
184
+ | Approaches to uncertainty and variability | - |
185
+
186
+ | Training and Evaluation Data | Description |
187
+ | ----------- | ----------- |
188
+ | 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.|
189
+ | Motivation | - |
190
+ | Preprocessing | - |
191
+
192
+ ## Quantitative Analyses
193
+ The Open LLM Leaderboard results can be found here: [https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-3](https://huggingface.co/datasets/open-llm-leaderboard/details_Intel__neural-chat-7b-v3-3). The metrics came out to:
194
 
195
  | Metric | Value |
196
  |-----------------------|---------------------------|
197
+ | Avg. | 69.83 |
198
+ | ARC (25-shot) | 66.89 |
199
+ | HellaSwag (10-shot) | 85.26 |
200
+ | MMLU (5-shot) | 63.07 |
201
+ | TruthfulQA (0-shot) | 63.01 |
202
+ | Winogrande (5-shot) | 79.64 |
203
+ | GSM8K (5-shot) | 61.11 |
 
 
 
 
204
 
205
  ## Ethical Considerations and Limitations
206
+ Neural-chat-7b-v3-3 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.
207
 
208
  Therefore, before deploying any applications of neural-chat-7b-v3-3, developers should perform safety testing.
209
 
210
+ ## Caveats and Recommendations
211
 
212
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
213
 
214
+ Here are a couple of useful links to learn more about Intel's AI software:
215
+ * Intel Neural Compressor [link](https://github.com/intel/neural-compressor)
216
+ * Intel Extension for Transformers [link](https://github.com/intel/intel-extension-for-transformers)
217
+
218
+ ## Disclaimer
219
 
220
+ 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.