Update README.md
Browse files
README.md
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
datasets:
|
3 |
+
- PKU-Alignment/PKU-SafeRLHF
|
4 |
+
language:
|
5 |
+
- en
|
6 |
+
tags:
|
7 |
+
- reinforcement-learning-from-human-feedback
|
8 |
+
- reinforcement-learning
|
9 |
+
- beaver
|
10 |
+
- safety
|
11 |
+
- llama
|
12 |
+
- ai-safety
|
13 |
+
- deepspeed
|
14 |
+
- rlhf
|
15 |
+
- alpaca
|
16 |
+
library_name: safe-rlhf
|
17 |
+
---
|
18 |
+
|
19 |
+
# 🦫 Beaver's Cost Model
|
20 |
+
|
21 |
+
## Model Details
|
22 |
+
|
23 |
+
The Beaver cost model is a preference model trained using the [PKU-SafeRLHF](https://huggingface.co/datasets/PKU-Alignment/PKU-SafeRLHF) dataset.
|
24 |
+
It can play a role in the safe RLHF algorithm, helping the Beaver model become more safe and harmless.
|
25 |
+
|
26 |
+
- **Developed by:** the [PKU-Alignment](https://github.com/PKU-Alignment) Team.
|
27 |
+
- **Model Type:** An auto-regressive language model based on the transformer architecture.
|
28 |
+
- **License:** Non-commercial license.
|
29 |
+
- **Fine-tuned from model:** [LLaMA](https://arxiv.org/abs/2302.13971), [Alpaca](https://github.com/tatsu-lab/stanford_alpaca).
|
30 |
+
|
31 |
+
## Model Sources
|
32 |
+
|
33 |
+
- **Repository:** <https://github.com/PKU-Alignment/safe-rlhf>
|
34 |
+
- **Beaver:** <https://huggingface.co/PKU-Alignment/beaver-7b-v2.0>
|
35 |
+
- **Dataset:** <https://huggingface.co/datasets/PKU-Alignment/PKU-SafeRLHF>
|
36 |
+
- **Reward Model:** <https://huggingface.co/PKU-Alignment/beaver-7b-v2.0-reward>
|
37 |
+
- **Cost Model:** <https://huggingface.co/PKU-Alignment/beaver-7b-v2.0-cost>
|
38 |
+
- **Dataset Paper:** <https://arxiv.org/abs/2307.04657>
|
39 |
+
- **Paper:** <https://arxiv.org/abs/2310.12773>
|
40 |
+
|
41 |
+
## How to Use the Cost Model
|
42 |
+
|
43 |
+
```python
|
44 |
+
import torch
|
45 |
+
from transformers import AutoTokenizer
|
46 |
+
from safe_rlhf.models import AutoModelForScore
|
47 |
+
|
48 |
+
model = AutoModelForScore.from_pretrained('PKU-Alignment/beaver-7b-v2.0-cost', torch_dtype=torch.bfloat16, device_map='auto')
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained('PKU-Alignment/beaver-7b-v2.0-cost')
|
50 |
+
|
51 |
+
input = 'BEGINNING OF CONVERSATION: USER: hello ASSISTANT:Hello! How can I help you today?'
|
52 |
+
|
53 |
+
input_ids = tokenizer(input, return_tensors='pt')
|
54 |
+
output = model(**input_ids)
|
55 |
+
print(output)
|
56 |
+
|
57 |
+
# ScoreModelOutput(
|
58 |
+
# scores=tensor([[[ 1.2031],
|
59 |
+
# [ 2.0469],
|
60 |
+
# [ 2.1875],
|
61 |
+
# [ 2.0938],
|
62 |
+
# [ 2.9219],
|
63 |
+
# [ 2.2656],
|
64 |
+
# [ 3.1250],
|
65 |
+
# [ 2.4219],
|
66 |
+
# [ 3.6406],
|
67 |
+
# [ 2.4062],
|
68 |
+
# [ 0.7383],
|
69 |
+
# [ 0.6719],
|
70 |
+
# [-0.4414],
|
71 |
+
# [-1.2734],
|
72 |
+
# [-1.6562],
|
73 |
+
# [ 0.3340],
|
74 |
+
# [ 0.2432],
|
75 |
+
# [-0.6914],
|
76 |
+
# [-1.0938],
|
77 |
+
# [-1.9453],
|
78 |
+
# [-3.0469],
|
79 |
+
# [-2.7812],
|
80 |
+
# [-2.2188],
|
81 |
+
# [-1.6250],
|
82 |
+
# [-1.5000],
|
83 |
+
# [-1.9922],
|
84 |
+
# [-2.6562],
|
85 |
+
# [-9.4375]]], grad_fn=<ToCopyBackward0>),
|
86 |
+
# end_scores=tensor([[-9.4375]], grad_fn=<ToCopyBackward0>),
|
87 |
+
# last_hidden_state=tensor([[[ 7.4219e-02, 3.6865e-02, -2.4414e-01, ..., -5.7129e-02,
|
88 |
+
# 1.1963e-01, 2.7734e-01],
|
89 |
+
# [-7.0703e-01, 1.0234e+00, 9.8145e-02, ..., 2.6719e+00,
|
90 |
+
# 8.2422e-01, 4.7119e-02],
|
91 |
+
# [-1.5332e-01, 1.0938e+00, -5.0000e-01, ..., -1.6699e-01,
|
92 |
+
# -6.0156e-01, 5.3516e-01],
|
93 |
+
# ...,
|
94 |
+
# [-1.0469e+00, 3.5858e-03, -1.1094e+00, ..., -1.1094e+00,
|
95 |
+
# 9.2578e-01, 1.3750e+00],
|
96 |
+
# [ 3.1445e-01, -9.7266e-01, -1.8984e+00, ..., -9.4141e-01,
|
97 |
+
# 2.0703e-01, 9.4531e-01],
|
98 |
+
# [ 5.5625e+00, -1.8672e+00, -1.3359e+00, ..., 8.0078e-01,
|
99 |
+
# -1.8906e+00, -1.3516e+00]]], dtype=torch.bfloat16,
|
100 |
+
# grad_fn=<ToCopyBackward0>),
|
101 |
+
# end_last_hidden_state=tensor([[ 5.5625, -1.8672, -1.3359, ..., 0.8008, -1.8906, -1.3516]],
|
102 |
+
# dtype=torch.bfloat16, grad_fn=<ToCopyBackward0>),
|
103 |
+
# end_index=tensor([27])
|
104 |
+
# )
|
105 |
+
```
|