halbihn commited on
Commit
f4fdae8
1 Parent(s): 37a6e77

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +175 -0
README.md ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: teknium/OpenHermes-2.5-Mistral-7B
3
+ tags:
4
+ - mistral
5
+ - instruct
6
+ - finetune
7
+ - chatml
8
+ - gpt4
9
+ - synthetic data
10
+ - distillation
11
+ - dpo
12
+ - rlhf
13
+ license: apache-2.0
14
+ language:
15
+ - en
16
+ datasets:
17
+ - mlabonne/chatml_dpo_pairs
18
+ ---
19
+
20
+ <center><img src="https://i.imgur.com/qIhaFNM.png"></center>
21
+
22
+ # NeuralHermes 2.5 - Mistral 7B
23
+
24
+ NeuralHermes is based on the [teknium/OpenHermes-2.5-Mistral-7B](https://huggingface.co/teknium/OpenHermes-2.5-Mistral-7B) model that has been further fine-tuned with Direct Preference Optimization (DPO) using the [mlabonne/chatml_dpo_pairs](https://huggingface.co/datasets/mlabonne/chatml_dpo_pairs) dataset. It surpasses the original model on most benchmarks (see results).
25
+
26
+ It is directly inspired by the RLHF process described by [Intel/neural-chat-7b-v3-1](https://huggingface.co/Intel/neural-chat-7b-v3-1)'s authors to improve performance. I used the same dataset and reformatted it to apply the ChatML template.
27
+
28
+ The code to train this model is available on [Google Colab](https://colab.research.google.com/drive/1h4tAJStIef_BcO-OkY97X9_OFgKnFrLl). It required an A100 GPU for about an hour.
29
+
30
+ ## Quantized models
31
+
32
+ * **GGUF**: https://huggingface.co/TheBloke/NeuralHermes-2.5-Mistral-7B-GGUF
33
+ * **AWQ**: https://huggingface.co/TheBloke/NeuralHermes-2.5-Mistral-7B-AWQ
34
+ * **GPTQ**: https://huggingface.co/TheBloke/NeuralHermes-2.5-Mistral-7B-GPTQ
35
+ * **EXL2**:
36
+ * 3.0bpw: https://huggingface.co/LoneStriker/NeuralHermes-2.5-Mistral-7B-3.0bpw-h6-exl2
37
+ * 4.0bpw: https://huggingface.co/LoneStriker/NeuralHermes-2.5-Mistral-7B-4.0bpw-h6-exl2
38
+ * 5.0bpw: https://huggingface.co/LoneStriker/NeuralHermes-2.5-Mistral-7B-5.0bpw-h6-exl2
39
+ * 6.0bpw: https://huggingface.co/LoneStriker/NeuralHermes-2.5-Mistral-7B-6.0bpw-h6-exl2
40
+ * 8.0bpw: https://huggingface.co/LoneStriker/NeuralHermes-2.5-Mistral-7B-8.0bpw-h8-exl2
41
+
42
+ ## Results
43
+
44
+ **Update:** NeuralHermes-2.5 became the best Hermes-based model on the Open LLM leaderboard and one of the very best 7b models. 🎉
45
+
46
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/yWe6VBFxkHiuOlDVBXtGo.png)
47
+
48
+ Teknium (author of OpenHermes-2.5-Mistral-7B) benchmarked the model ([see his tweet](https://twitter.com/Teknium1/status/1729955709377503660)).
49
+
50
+ Results are improved on every benchmark: **AGIEval** (from 43.07% to 43.62%), **GPT4All** (from 73.12% to 73.25%), and **TruthfulQA**.
51
+
52
+ ### AGIEval
53
+ ![](https://i.imgur.com/7an3B1f.png)
54
+
55
+ ### GPT4All
56
+ ![](https://i.imgur.com/TLxZFi9.png)
57
+
58
+ ### TruthfulQA
59
+ ![](https://i.imgur.com/V380MqD.png)
60
+
61
+ You can view the Weights & Biases report [here](https://api.wandb.ai/links/halbihn/uem1q2dj).
62
+
63
+ ## Usage
64
+
65
+ You can run this model using [LM Studio](https://lmstudio.ai/) or any other frontend.
66
+
67
+ You can also run this model using the following code:
68
+
69
+ ```python
70
+ import transformers
71
+ from transformers import AutoTokenizer
72
+
73
+ model_id = "halbihn/NeuralHermes-2.5-Mistral-7B"
74
+
75
+ # Format prompt
76
+ message = [
77
+ {"role": "system", "content": "You are a helpful assistant chatbot."},
78
+ {"role": "user", "content": "What is a Large Language Model?"}
79
+ ]
80
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
81
+ prompt = tokenizer.apply_chat_template(message, add_generation_prompt=True, tokenize=False)
82
+
83
+ # Create pipeline
84
+ pipeline = transformers.pipeline(
85
+ "text-generation",
86
+ model=model_id,
87
+ tokenizer=tokenizer
88
+ )
89
+
90
+ # Generate text
91
+ sequences = pipeline(
92
+ prompt,
93
+ do_sample=True,
94
+ temperature=0.7,
95
+ top_p=0.9,
96
+ num_return_sequences=1,
97
+ max_length=200,
98
+ )
99
+ response = sequences[0]['generated_text'].split("<|im_start|>assistant")[-1].strip()
100
+ print(response)
101
+
102
+
103
+ # streaming example
104
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
105
+ import torch
106
+
107
+ model_id = "halbihn/NeuralHermes-2.5-Mistral-7B"
108
+
109
+ model = AutoModelForCausalLM.from_pretrained(model_id)
110
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
111
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
112
+ model.to(device)
113
+
114
+ def stream(
115
+ user_prompt: str,
116
+ max_tokens: int = 200,
117
+ ) -> None:
118
+ """Text streaming example
119
+ """
120
+
121
+ system_prompt = 'Below is a conversation between Human and AI assistant named Mistral\n'
122
+
123
+ message = [
124
+ {"role": "system", "content": system_prompt},
125
+ {"role": "user", "content": user_prompt}
126
+ ]
127
+ prompt = tokenizer.apply_chat_template(
128
+ message,
129
+ add_generation_prompt=True,
130
+ tokenize=False,
131
+ )
132
+
133
+ inputs = tokenizer([prompt], return_tensors="pt").to(device)
134
+
135
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
136
+
137
+ _ = model.generate(**inputs, streamer=streamer, max_new_tokens=max_tokens)
138
+
139
+ stream("Tell me about the future")
140
+
141
+ >>> The future is a vast and uncertain expanse, shaped by the collective actions and innovations of humanity. It is a blend of possibilities, technological advancements, and societal changes. Some potential aspects of the future include:
142
+ >>>
143
+ >>> 1. Technological advancements: Artificial intelligence, quantum computing, and biotechnology are expected to continue evolving, leading to breakthroughs in fields like medicine, energy, and communication.
144
+ >>>
145
+ >>> 2. Space exploration: As technology progresses, space travel may become more accessible, enabling humans to establish colonies on other planets and explore the cosmos further.
146
+ >>>
147
+ >>> 3. Climate change mitigation: The future will likely see increased efforts to combat climate change through renewable energy sources, carbon capture technologies, and sustainable practices.
148
+ >>>
149
+ >>> 4. Artificial intelligence integration: AI will likely become more integrated into daily life, assisting with tasks, automating jobs, and even influencing decision-making processes in various industries.
150
+ ```
151
+
152
+ ## Training hyperparameters
153
+
154
+ **LoRA**:
155
+ * r=16
156
+ * lora_alpha=16
157
+ * lora_dropout=0.05
158
+ * bias="none"
159
+ * task_type="CAUSAL_LM"
160
+ * target_modules=['k_proj', 'gate_proj', 'v_proj', 'up_proj', 'q_proj', 'o_proj', 'down_proj']
161
+
162
+ **Training arguments**:
163
+ * per_device_train_batch_size=4
164
+ * gradient_accumulation_steps=4
165
+ * gradient_checkpointing=True
166
+ * learning_rate=5e-5
167
+ * lr_scheduler_type="cosine"
168
+ * max_steps=200
169
+ * optim="paged_adamw_32bit"
170
+ * warmup_steps=100
171
+
172
+ **DPOTrainer**:
173
+ * beta=0.1
174
+ * max_prompt_length=1024
175
+ * max_length=1536