Commit
·
7c45bed
1
Parent(s):
f3d801d
update readme.
Browse files
README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
base_model:
|
| 6 |
+
- meta-llama/Llama-3.2-3B-Instruct
|
| 7 |
+
tags:
|
| 8 |
+
- rewardmodel
|
| 9 |
+
- GRAM
|
| 10 |
+
- RLHF
|
| 11 |
+
- reward
|
| 12 |
---
|
| 13 |
+
|
| 14 |
+
# Introduction
|
| 15 |
+
|
| 16 |
+
This repository contains the released models for the paper [GRAM: A Generative Foundation Reward Model for Reward Generalization 📝]().
|
| 17 |
+
|
| 18 |
+
## Evaluation
|
| 19 |
+
|
| 20 |
+
| Model | Average | Chat | Chat Hard | Safety | Reasoning |
|
| 21 |
+
|:-------------------------:|:-------------:|:---------:|:---------:|:--------:|:-----------:|
|
| 22 |
+
|**Ray2333/GRM-Gemma-2B-rewardmodel-ft (Ours, 2B)**| **84.7** | 89.4 | 75.2 | 85.5 | 88.8 |
|
| 23 |
+
| openai/gpt-4o-2024-05-13 | 84.6| 96.6 | 70.4 | 86.5 | 84.9 |
|
| 24 |
+
| sfairXC/FsfairX-LLaMA3-RM-v0.1 (8B) | 84.4 | 99.4 | 65.1 | 86.8 | 86.4 |
|
| 25 |
+
| Nexusflow/Starling-RM-34B | 82.6 |96.9 |57.2 |87.7 |88.5|
|
| 26 |
+
| [**Ray2333/GRM-Gemma-2B-sftreg**](https://huggingface.co/Ray2333/GRM-Gemma-2B-sftreg)**(Ours, 2B)** | 75.3 | 95.5 | 48.7 | 80.0 | 76.8 |
|
| 27 |
+
| berkeley-nest/Starling-RM-7B-alpha (7B) | 74.6 | 98 | 43.4 | 88.6 | 74.6 |
|
| 28 |
+
| **Ray2333/Gemma-2B-rewardmodel-baseline**(Ours, 2B) | 73.7 | 94.1 | 46.1 | 79.6 | 75.0 |
|
| 29 |
+
| stabilityai/stablelm-zephyr-3b (3B) | 73.1 | 86.3 | 60.1 | 70.3 | 75.7 |
|
| 30 |
+
| openbmb/UltraRM-13b (13B) | 71.3 | 96.1 | 55.3 | 45.8 | 82 |
|
| 31 |
+
|
| 32 |
+
## Usage
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
import torch
|
| 36 |
+
import accelerate
|
| 37 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 38 |
+
|
| 39 |
+
prompt = """Please act as an impartial judge and evaluate the quality of the responses provided by two AI assistants to the user question displayed below. You should choose the assistant that follows the user\'s instructions and answers the user\'s question better.
|
| 40 |
+
Your evaluation should consider factors such as the helpfulness, relevance, accuracy, depth, creativity, and level of detail of their responses. Avoid any position biases and ensure that the order in which the responses were presented does not influence your decision. Do not allow the length of the responses to influence your evaluation. Do not favor certain names of the assistants. Be as objective as possible.
|
| 41 |
+
Please directly output your final verdict by strictly following this format: "A" if assistant A is better, "B" if assistant B is better.
|
| 42 |
+
|
| 43 |
+
[User Question]
|
| 44 |
+
{input}
|
| 45 |
+
|
| 46 |
+
[The Start of Assistant A's Answer]
|
| 47 |
+
{response_a}
|
| 48 |
+
[The End of Assistant A's Answer]
|
| 49 |
+
|
| 50 |
+
[The Start of Assistant B's Answer]
|
| 51 |
+
{response_b}
|
| 52 |
+
[The End of Assistant B's Answer]
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
query = "What is the Russian word for frog?"
|
| 56 |
+
response1 = "The Russian word for frog is \"лягушка\" (pronounced \"lyagushka\")."
|
| 57 |
+
response2 = "The Russian word for frog is \"жаба\" (pronounced as \"zhaba\"). This word can also be written in Cyrillic as жа́ба. If you're learning Russian, here's a sentence with the word: Меня зовут Иван, и я люблю лезечку на спину жабы, which translates to \"My name is Ivan, and I like sitting on the back of a frog.\" (Keep in mind that in real life, it is best not to disturb or harm frogs.)"
|
| 58 |
+
|
| 59 |
+
model_name_or_path = "gram-open-source/GRAM-Qwen3-1.7B-RewardModel"
|
| 60 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
| 61 |
+
tokenizer.padding_side = "left"
|
| 62 |
+
if not tokenizer.pad_token:
|
| 63 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 64 |
+
|
| 65 |
+
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, torch_dtype=torch.bfloat16, device_map="auto")
|
| 66 |
+
|
| 67 |
+
messages = [
|
| 68 |
+
[{"role": "user", "content": prompt.format(input=query, response_a=response1, response_b=response2)}],
|
| 69 |
+
[{"role": "user", "content": prompt.format(input=query, response_a=response2, response_b=response1)}],
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
# target at response1, response2 respectively
|
| 73 |
+
target_choices_response1 = ["A", "B"]
|
| 74 |
+
target_choices_response1_token_ids = torch.tensor([tokenizer(item, add_special_tokens=False).input_ids for item in target_choices_response1], device=model.device)
|
| 75 |
+
target_choices_response2_token_ids = torch.flip(target_choices_response1_token_ids, dims=(0,))
|
| 76 |
+
target_choices_token_ids = torch.cat((target_choices_response1_token_ids, target_choices_response2_token_ids), dim=1)
|
| 77 |
+
|
| 78 |
+
prompt = [tokenizer.apply_chat_template(message, tokenize=False, add_generation_prompt=True) for message in messages]
|
| 79 |
+
inputs = tokenizer(prompt, return_tensors="pt", padding=True).to(model.device)
|
| 80 |
+
|
| 81 |
+
with torch.no_grad():
|
| 82 |
+
output = model(**inputs)
|
| 83 |
+
logits = torch.gather(output.logits[..., -1, :], 1, target_choices_token_ids)
|
| 84 |
+
p = torch.nn.Softmax(dim=0)(logits)
|
| 85 |
+
score_response1, score_response2 = torch.mean(p, dim=1).tolist()
|
| 86 |
+
|
| 87 |
+
print({
|
| 88 |
+
"query": query,
|
| 89 |
+
"response1": response1,
|
| 90 |
+
"response2": response2,
|
| 91 |
+
"score_response1": score_response1,
|
| 92 |
+
"score_response2": score_response2,
|
| 93 |
+
"response1_is_better": score_response1 > score_response2,
|
| 94 |
+
})
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
## Citation
|
| 98 |
+
|
| 99 |
+
If you find this model helpful for your research, please cite GRAM
|
| 100 |
+
|