Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
datasets:
|
4 |
+
- databricks/databricks-dolly-15k
|
5 |
+
language:
|
6 |
+
- en
|
7 |
+
---
|
8 |
+
## 模型介绍
|
9 |
+
- 使用模型:LLaMA2-7B
|
10 |
+
- 微调方法:QLoRA
|
11 |
+
- 数据集:databricks/databricks-dolly-15k
|
12 |
+
- 目标:对模型进行指令微调
|
13 |
+
## 使用方法
|
14 |
+
- 加载数据
|
15 |
+
```
|
16 |
+
from datasets import load_dataset
|
17 |
+
from random import randrange
|
18 |
+
|
19 |
+
|
20 |
+
# 从hub加载数据集并得到一个样本
|
21 |
+
dataset = load_dataset("databricks/databricks-dolly-15k", split="train")
|
22 |
+
sample = dataset[randrange(len(dataset))]
|
23 |
+
```
|
24 |
+
- 模型使用
|
25 |
+
```
|
26 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
27 |
+
import torch
|
28 |
+
|
29 |
+
model_name_or_path = "snowfly/llama2-7b-QLoRA-dolly"
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_name_or_path, trust_remote_code=True)
|
31 |
+
model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path=model_name_or_path,
|
32 |
+
trust_remote_code=True,
|
33 |
+
low_cpu_mem_usage=True,
|
34 |
+
torch_dtype=torch.float16,
|
35 |
+
load_in_4bit=True)
|
36 |
+
model = model.eval()
|
37 |
+
|
38 |
+
|
39 |
+
prompt = f"""### Instruction:
|
40 |
+
Use the Input below to create an instruction, which could have been used to generate the input using an LLM.
|
41 |
+
|
42 |
+
### Input:
|
43 |
+
{sample['response']}
|
44 |
+
|
45 |
+
### Response:
|
46 |
+
"""
|
47 |
+
|
48 |
+
input_ids = tokenizer(prompt, return_tensors="pt", truncation=True).input_ids.cuda()
|
49 |
+
|
50 |
+
outputs = model.generate(input_ids=input_ids, max_new_tokens=100, do_sample=True, top_p=0.9,temperature=0.9)
|
51 |
+
|
52 |
+
print(f"Prompt:\n{sample['response']}\n")
|
53 |
+
print(f"Generated instruction:\n{tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True)[0][len(prompt):]}")
|
54 |
+
print(f"Ground truth:\n{sample['instruction']}")
|
55 |
+
```
|