Update README.md
Browse files
README.md
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-v3.0>
|
35 |
+
- **Dataset:** <https://huggingface.co/datasets/PKU-Alignment/PKU-SafeRLHF>
|
36 |
+
- **Reward Model:** <https://huggingface.co/PKU-Alignment/beaver-7b-v3.0-reward>
|
37 |
+
- **Cost Model:** <https://huggingface.co/PKU-Alignment/beaver-7b-v3.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-v3.0-cost', torch_dtype=torch.bfloat16, device_map='auto')
|
49 |
+
tokenizer = AutoTokenizer.from_pretrained('PKU-Alignment/beaver-7b-v3.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([[[ 3.4844],
|
59 |
+
# [ 0.9414],
|
60 |
+
# [ 1.9766],
|
61 |
+
# [ 0.9688],
|
62 |
+
# [ 1.4219],
|
63 |
+
# [ 0.5781],
|
64 |
+
# [ 0.7500],
|
65 |
+
# [ 0.3516],
|
66 |
+
# [-0.2305],
|
67 |
+
# [-0.6055],
|
68 |
+
# [-1.0625],
|
69 |
+
# [-1.1875],
|
70 |
+
# [-0.5820],
|
71 |
+
# [ 0.0182],
|
72 |
+
# [-1.0000],
|
73 |
+
# [ 0.1279],
|
74 |
+
# [-0.5820],
|
75 |
+
# [-0.3691],
|
76 |
+
# [ 0.5430],
|
77 |
+
# [-0.2266],
|
78 |
+
# [ 0.6797],
|
79 |
+
# [ 1.0938],
|
80 |
+
# [ 0.7188],
|
81 |
+
# [ 0.6797],
|
82 |
+
# [ 0.3613],
|
83 |
+
# [ 0.1416],
|
84 |
+
# [ 0.4238],
|
85 |
+
# [ 0.4023]]], grad_fn=<ToCopyBackward0>),
|
86 |
+
# end_scores=tensor([[0.4023]], grad_fn=<ToCopyBackward0>),
|
87 |
+
# last_hidden_state=tensor([[[-0.2832, -0.0139, -0.1904, ..., 0.4141, -0.5859, -1.2734],
|
88 |
+
# [ 0.2168, -1.1953, -0.4707, ..., -0.0806, 0.2500, 0.6016],
|
89 |
+
# [ 0.5078, 0.2334, 0.1348, ..., -0.1416, -0.1699, -0.3008],
|
90 |
+
# ...,
|
91 |
+
# [ 0.6328, -0.0108, -0.7188, ..., -0.8828, 0.2812, 0.5352],
|
92 |
+
# [ 0.4434, 0.3281, -0.1245, ..., -0.7812, 0.7734, 0.8164],
|
93 |
+
# [ 0.5078, 0.2637, 0.5508, ..., 0.3477, 1.5625, 0.5547]]],
|
94 |
+
# dtype=torch.bfloat16, grad_fn=<ToCopyBackward0>),
|
95 |
+
# end_last_hidden_state=tensor([[0.5078, 0.2637, 0.5508, ..., 0.3477, 1.5625, 0.5547]],
|
96 |
+
# dtype=torch.bfloat16, grad_fn=<ToCopyBackward0>),
|
97 |
+
# end_index=tensor([27])
|
98 |
+
# )
|
99 |
+
```
|