shenzhi-wang
commited on
Commit
•
3409be9
1
Parent(s):
a7031f7
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,101 @@
|
|
1 |
-
---
|
2 |
-
license: gemma
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: gemma
|
3 |
+
library_name: transformers
|
4 |
+
pipeline_tag: text-generation
|
5 |
+
base_model: google/gemma-2-27b-it
|
6 |
+
language:
|
7 |
+
- en
|
8 |
+
- zh
|
9 |
+
tags:
|
10 |
+
- llama-factory
|
11 |
+
- orpo
|
12 |
+
---
|
13 |
+
|
14 |
+
❗️❗️❗️NOTICE: For optimal performance, we refrain from fine-tuning the model's identity. Thus, inquiries such as "Who are you" or "Who developed you" may yield random responses that are not necessarily accurate.
|
15 |
+
|
16 |
+
|
17 |
+
# Updates
|
18 |
+
|
19 |
+
- 🚀🚀🚀 [Jul 2, 2024] We now introduce Gemma-2-27B-Chinese-Chat, which is **the first instruction-tuned language model built upon [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it) for Chinese & English users** with various abilities such as roleplaying & tool-using.
|
20 |
+
|
21 |
+
|
22 |
+
# Model Summary
|
23 |
+
|
24 |
+
Gemma-2-27B-Chinese-Chat is **the first instruction-tuned language model built upon [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it) for Chinese & English users** with various abilities such as roleplaying & tool-using.
|
25 |
+
|
26 |
+
Developed by: [Shenzhi Wang](https://shenzhi-wang.netlify.app) (王慎执) and [Yaowei Zheng](https://github.com/hiyouga) (郑耀威)
|
27 |
+
|
28 |
+
- License: [Gemma License](https://ai.google.dev/gemma/terms)
|
29 |
+
- Base Model: [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it)
|
30 |
+
- Model Size: 27.2B
|
31 |
+
- Context length: 8K
|
32 |
+
|
33 |
+
# 1. Introduction
|
34 |
+
|
35 |
+
This is the first model specifically fine-tuned for Chinese & English users based on the [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it) with a preference dataset with more than 100K preference pairs. The fine-tuning algorithm we employ is ORPO [1].
|
36 |
+
|
37 |
+
**Compared to the original [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it), our Gemma-2-27B-Chinese-Chat model significantly reduces the issues of "Chinese questions with English answers" and the mixing of Chinese and English in responses, with enhanced performance in roleplay, tool-using, and math.**
|
38 |
+
|
39 |
+
[1] Hong, Jiwoo, Noah Lee, and James Thorne. "Reference-free Monolithic Preference Optimization with Odds Ratio." arXiv preprint arXiv:2403.07691 (2024).
|
40 |
+
|
41 |
+
Training framework: [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory).
|
42 |
+
|
43 |
+
Training details:
|
44 |
+
|
45 |
+
- epochs: 3
|
46 |
+
- learning rate: 3e-6
|
47 |
+
- learning rate scheduler type: cosine
|
48 |
+
- Warmup ratio: 0.1
|
49 |
+
- cutoff len (i.e. context length): 8192
|
50 |
+
- orpo beta (i.e. $\lambda$ in the ORPO paper): 0.05
|
51 |
+
- global batch size: 128
|
52 |
+
- fine-tuning type: full parameters
|
53 |
+
- optimizer: paged_adamw_32bit
|
54 |
+
|
55 |
+
# 2. Usage
|
56 |
+
|
57 |
+
## 2.1 Usage of Our BF16 Model
|
58 |
+
|
59 |
+
1. Please upgrade the `transformers` package to ensure it supports Gemma-2 models. The current version we are using is `4.42.2`.
|
60 |
+
|
61 |
+
2. Use the following Python script to download our BF16 model
|
62 |
+
|
63 |
+
```python
|
64 |
+
from huggingface_hub import snapshot_download
|
65 |
+
snapshot_download(repo_id="shenzhi-wang/Gemma-2-27B-Chinese-Chat", ignore_patterns=["*.gguf"]) # Download our BF16 model without downloading GGUF models.
|
66 |
+
```
|
67 |
+
|
68 |
+
3. Inference with the BF16 model
|
69 |
+
|
70 |
+
```python
|
71 |
+
import torch
|
72 |
+
import transformers
|
73 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
74 |
+
|
75 |
+
model_id = "/Your/Local/Path/to/Gemma-2-27B-Chinese-Chat"
|
76 |
+
dtype = torch.bfloat16
|
77 |
+
|
78 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
79 |
+
model = AutoModelForCausalLM.from_pretrained(
|
80 |
+
model_id,
|
81 |
+
device_map="cuda",
|
82 |
+
torch_dtype=dtype,
|
83 |
+
)
|
84 |
+
|
85 |
+
chat = [
|
86 |
+
{"role": "user", "content": "写一首关于机器学习的诗。"},
|
87 |
+
]
|
88 |
+
input_ids = tokenizer.apply_chat_template(
|
89 |
+
chat, tokenize=True, add_generation_prompt=True, return_tensors="pt"
|
90 |
+
).to(model.device)
|
91 |
+
|
92 |
+
outputs = model.generate(
|
93 |
+
input_ids,
|
94 |
+
max_new_tokens=8192,
|
95 |
+
do_sample=True,
|
96 |
+
temperature=0.6,
|
97 |
+
top_p=0.9,
|
98 |
+
)
|
99 |
+
response = outputs[0][input_ids.shape[-1] :]
|
100 |
+
print(tokenizer.decode(response, skip_special_tokens=True))
|
101 |
+
```
|