Update README.md
Browse files
README.md
CHANGED
@@ -48,11 +48,13 @@ Anima模型基于QLoRA开源的[33B guanaco](https://huggingface.co/timdettmers/
|
|
48 |
|
49 |
使用以下步骤可以重现Anima 33B模型:
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
56 |
|
57 |
|
58 |
|
@@ -87,47 +89,51 @@ Anima模型只通过10000 steps的训练,并没有深度优化训练数据的
|
|
87 |
|
88 |
首先保证依赖都已经安装:
|
89 |
|
90 |
-
|
91 |
-
|
|
|
|
|
92 |
可以参考:[inferrence.ipynb](https://github.com/lyogavin/Anima/blob/main/examples/inferrence.ipynb)
|
93 |
|
94 |
或者使用如下代码:
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
131 |
|
132 |
## 📚 模型使用例子
|
133 |
|
|
|
48 |
|
49 |
使用以下步骤可以重现Anima 33B模型:
|
50 |
|
51 |
+
``` bash
|
52 |
+
# 1. install dependencies
|
53 |
+
pip install -r requirements.txt
|
54 |
+
# 2.
|
55 |
+
cd training
|
56 |
+
./run_Amina_training.sh
|
57 |
+
```
|
58 |
|
59 |
|
60 |
|
|
|
89 |
|
90 |
首先保证依赖都已经安装:
|
91 |
|
92 |
+
``` bash
|
93 |
+
pip install -r https://github.com/lyogavin/Anima/blob/main/requirements.txt?raw=true
|
94 |
+
```
|
95 |
+
|
96 |
可以参考:[inferrence.ipynb](https://github.com/lyogavin/Anima/blob/main/examples/inferrence.ipynb)
|
97 |
|
98 |
或者使用如下代码:
|
99 |
+
|
100 |
+
``` python
|
101 |
+
# imports
|
102 |
+
from peft import PeftModel
|
103 |
+
from transformers import GenerationConfig, LlamaForCausalLM, LlamaTokenizer
|
104 |
+
import torch
|
105 |
+
|
106 |
+
# create tokenizer
|
107 |
+
base_model = "timdettmers/guanaco-33b-merged"
|
108 |
+
tokenizer = LlamaTokenizer.from_pretrained(base_model)
|
109 |
+
|
110 |
+
# base model
|
111 |
+
model = LlamaForCausalLM.from_pretrained(
|
112 |
+
base_model,
|
113 |
+
torch_dtype=torch.float16,
|
114 |
+
device_map="auto",
|
115 |
+
)
|
116 |
+
|
117 |
+
# LORA PEFT adapters
|
118 |
+
adapter_model = "lyogavin/Anima33B"
|
119 |
+
|
120 |
+
model = PeftModel.from_pretrained(
|
121 |
+
model,
|
122 |
+
adapter_model,
|
123 |
+
#torch_dtype=torch.float16,
|
124 |
+
)
|
125 |
+
model.eval()
|
126 |
+
|
127 |
+
# prompt
|
128 |
+
prompt = "中国的首都是哪里?"
|
129 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
130 |
+
|
131 |
+
# Generate
|
132 |
+
generate_ids = model.generate(**inputs, max_new_tokens=30)
|
133 |
+
print(tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0])
|
134 |
+
|
135 |
+
# output: '中国的首都是哪里?\n中国的首都是北京。\n北京位于中国北部,是中国历史悠'
|
136 |
+
```
|
137 |
|
138 |
## 📚 模型使用例子
|
139 |
|