Views
No views yet

| Model | Base Model | Method | Score | Chat | Chat Hard | Safety | Reasoning | Prior Sets (0.5 weight) |
|---|---|---|---|---|---|---|---|---|
| ArmoRM-Llama3-8B-v0.1 | Llama-3 8B | ArmoRM + MoE | 89.0 | 96.9 | 76.8 | 92.2 | 97.3 | 74.3 |
| Cohere May 2024 | Unknown | Unknown | 88.3 | 96.4 | 71.3 | 92.7 | 97.7 | 78.2 |
| pair-preference-model | Llama-3 8B | SliC-HF | 85.7 | 98.3 | 65.8 | 89.7 | 94.7 | 74.6 |
| GPT-4 Turbo (0125 version) | GPT-4 Turbo | LLM-as-a-Judge | 84.3 | 95.3 | 74.3 | 87.2 | 86.9 | 70.9 |
| FsfairX-LLaMA3-RM-v0.1 | Llama-3 8B | Bradley-Terry | 83.6 | 99.4 | 65.1 | 87.8 | 86.4 | 74.9 |
| Starling-RM-34B | Yi-34B | Bradley-Terry | 81.4 | 96.9 | 57.2 | 88.2 | 88.5 | 71.4 |
1import torch
2from transformers import AutoConfig, AutoModelForSequenceClassification
3from transformers import BitsAndBytesConfig
4from transformers import AutoTokenizer, pipeline
5
6device = "cuda"
7path = "SteveTran/ArmoRM-Llama3-8B-v0.1-8bit"
8tokenizer = AutoTokenizer.from_pretrained(new_weights_location, use_fast=True)
9model = AutoModelForSequenceClassification.from_pretrained(
10 new_weights_location,
11 device_map="auto",
12 torch_dtype=torch.bfloat16,
13 trust_remote_code=True,
14)
15# We load a random sample from the validation set of the HelpSteer dataset
16prompt = 'What are some synonyms for the word "beautiful"?'
17response = "Nicely, Beautifully, Handsome, Stunning, Wonderful, Gorgeous, Pretty, Stunning, Elegant"
18messages = [{"role": "user", "content": prompt},
19 {"role": "assistant", "content": response}]
20input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
21with torch.no_grad():
22 output = model(input_ids)
23 # Multi-objective rewards for the response
24 multi_obj_rewards = output.rewards.cpu().float()
25 # The gating layer's output is conditioned on the prompt
26 gating_output = output.gating_output.cpu().float()
27 # The preference score for the response, aggregated from the
28 # multi-objective rewards with the gating layer
29 preference_score = output.score.cpu().float()
30# We apply a transformation matrix to the multi-objective rewards
31# before multiplying with the gating layer's output. This mainly aims
32# at reducing the verbosity bias of the original reward objectives
33obj_transform = model.reward_transform_matrix.data.cpu().float()
34# The final coefficients assigned to each reward objective
35multi_obj_coeffs = gating_output @ obj_transform.T
36# The preference score is the linear combination of the multi-objective rewards with
37# the multi-objective coefficients, which can be verified by the following assertion
38assert torch.isclose(torch.sum(multi_obj_rewards * multi_obj_coeffs, dim=1), preference_score, atol=1e-3)
39# Find the top-K reward objectives with coefficients of the highest magnitude
40K = 3
41top_obj_dims = torch.argsort(torch.abs(multi_obj_coeffs), dim=1, descending=True,)[:, :K]
42top_obj_coeffs = torch.gather(multi_obj_coeffs, dim=1, index=top_obj_dims)
43
44# The attributes of the 19 reward objectives
45attributes = ['helpsteer-helpfulness','helpsteer-correctness','helpsteer-coherence',
46 'helpsteer-complexity','helpsteer-verbosity','ultrafeedback-overall_score',
47 'ultrafeedback-instruction_following', 'ultrafeedback-truthfulness',
48 'ultrafeedback-honesty','ultrafeedback-helpfulness','beavertails-is_safe',
49 'prometheus-score','argilla-overall_quality','argilla-judge_lm','code-complexity',
50 'code-style','code-explanation','code-instruction-following','code-readability']
51
52example_index = 0
53for i in range(K):
54 attribute = attributes[top_obj_dims[example_index, i].item()]
55 coeff = top_obj_coeffs[example_index, i].item()
56 print(f"{attribute}: {round(coeff,5)}")
57
58# code-complexity: 0.19727
59# helpsteer-verbosity: -0.10918
60# ultrafeedback-instruction_following: 0.07861
61
62# The actual rewards of this example from the HelpSteer dataset
63# are [3,3,4,2,2] for the five helpsteer objectives:
64# helpfulness, correctness, coherence, complexity, verbosity
65# We can linearly transform our predicted rewards to the
66# original reward space to compare with the ground truth
67helpsteer_rewards_pred = multi_obj_rewards[0, :5] * 5 - 0.5
68print(helpsteer_rewards_pred)
69# [2.78125 2.859375 3.484375 1.3847656 1.296875 ] float16
70# [2.8008, 2.9570, 3.5430, 1.5703, 1.3555] 8-bit
711from typing import Dict, List
2import torch
3from transformers import AutoModelForSequenceClassification, AutoTokenizer
4
5
6class ArmoRMPipeline:
7 def __init__(self, model_id, device_map="auto", torch_dtype=torch.bfloat16, truncation=True, trust_remote_code=False, max_length=4096):
8 self.model = AutoModelForSequenceClassification.from_pretrained(
9 model_id,
10 device_map=device_map,
11 trust_remote_code=trust_remote_code,
12 torch_dtype=torch_dtype,
13 )
14 self.tokenizer = AutoTokenizer.from_pretrained(
15 model_id,
16 use_fast=True,
17 )
18 self.truncation = truncation
19 self.device = self.model.device
20 self.max_length = max_length
21
22 def __call__(self, messages: List[Dict[str, str]]) -> Dict[str, float]:
23 """
24 messages: OpenAI chat messages to be scored
25 Note: no batching since due to length differences, the model will have to pad to the max length which is not efficient
26 Returns: a dictionary with the score between 0 and 1
27 """
28 input_ids = self.tokenizer.apply_chat_template(
29 messages,
30 return_tensors="pt",
31 padding=True,
32 truncation=self.truncation,
33 max_length=self.max_length,
34 ).to(self.device)
35 with torch.no_grad():
36 output = self.model(input_ids)
37 score = output.score.float().item()
38 return {"score": score}
39
40# Create Reward Model Pipeline
41prompt = 'What are some synonyms for the word "beautiful"?'
42rm = ArmoRMPipeline("RLHFlow/ArmoRM-Llama3-8B-v0.1", trust_remote_code=True)
43# score the messages
44response1 = 'Nicely, Beautifully, Handsome, Stunning, Wonderful, Gorgeous, Pretty, Stunning, Elegant'
45score1 = rm([{"role": "user", "content": prompt}, {"role": "assistant", "content": response1}])
46print(score1)
47
48response2 = '''Certainly! Here are some synonyms for the word "beautiful":
49
501. Gorgeous
512. Lovely
523. Stunning
534. Attractive
545. Pretty
556. Elegant
567. Exquisite
578. Handsome
589. Charming
5910. Alluring
6011. Radiant
6112. Magnificent
6213. Graceful
6314. Enchanting
6415. Dazzling
65
66These synonyms can be used in various contexts to convey the idea of beauty.'''
67score2 = rm([{"role": "user", "content": prompt}, {"role": "assistant", "content": response2}])
68print(score2)
69
70response3 = 'Sorry i cannot answer this.'
71score3 = rm([{"role": "user", "content": prompt}, {"role": "assistant", "content": response3}])
72print(score3)
73@article{ArmoRM,
title={Interpretable Preferences via Multi-Objective Reward Modeling and Mixture-of-Experts},
author={Haoxiang Wang and Wei Xiong and Tengyang Xie and Han Zhao and Tong Zhang},
journal={arXiv preprint arXiv:2406.12845},
}
@inproceedings{wang2024arithmetic,
title={Arithmetic Control of LLMs for Diverse User Preferences: Directional Preference Alignment with Multi-Objective Rewards},
author={Haoxiang Wang and Yong Lin and Wei Xiong and Rui Yang and Shizhe Diao and Shuang Qiu and Han Zhao and Tong Zhang},
year={2024},
booktitle={ACL},
}