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 AutoModelForSequenceClassification, AutoTokenizer
3device = "cuda"
4path = "SteveTran/ArmoRM-Llama3-8B-v0.1-4bit"
5model = AutoModelForSequenceClassification.from_pretrained(path, device_map=device,
6 trust_remote_code=True, torch_dtype=torch.bfloat16)
7tokenizer = AutoTokenizer.from_pretrained(path, use_fast=True)
8# We load a random sample from the validation set of the HelpSteer dataset
9prompt = 'What are some synonyms for the word "beautiful"?'
10response = "Nicely, Beautifully, Handsome, Stunning, Wonderful, Gorgeous, Pretty, Stunning, Elegant"
11messages = [{"role": "user", "content": prompt},
12 {"role": "assistant", "content": response}]
13input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
14with torch.no_grad():
15 output = model(input_ids)
16 # Multi-objective rewards for the response
17 multi_obj_rewards = output.rewards.cpu().float()
18 # The gating layer's output is conditioned on the prompt
19 gating_output = output.gating_output.cpu().float()
20 # The preference score for the response, aggregated from the
21 # multi-objective rewards with the gating layer
22 preference_score = output.score.cpu().float()
23# We apply a transformation matrix to the multi-objective rewards
24# before multiplying with the gating layer's output. This mainly aims
25# at reducing the verbosity bias of the original reward objectives
26obj_transform = model.reward_transform_matrix.data.cpu().float()
27# The final coefficients assigned to each reward objective
28multi_obj_coeffs = gating_output @ obj_transform.T
29# The preference score is the linear combination of the multi-objective rewards with
30# the multi-objective coefficients, which can be verified by the following assertion
31assert torch.isclose(torch.sum(multi_obj_rewards * multi_obj_coeffs, dim=1), preference_score, atol=1e-3)
32# Find the top-K reward objectives with coefficients of the highest magnitude
33K = 3
34top_obj_dims = torch.argsort(torch.abs(multi_obj_coeffs), dim=1, descending=True,)[:, :K]
35top_obj_coeffs = torch.gather(multi_obj_coeffs, dim=1, index=top_obj_dims)
36
37# The attributes of the 19 reward objectives
38attributes = ['helpsteer-helpfulness','helpsteer-correctness','helpsteer-coherence',
39 'helpsteer-complexity','helpsteer-verbosity','ultrafeedback-overall_score',
40 'ultrafeedback-instruction_following', 'ultrafeedback-truthfulness',
41 'ultrafeedback-honesty','ultrafeedback-helpfulness','beavertails-is_safe',
42 'prometheus-score','argilla-overall_quality','argilla-judge_lm','code-complexity',
43 'code-style','code-explanation','code-instruction-following','code-readability']
44
45example_index = 0
46for i in range(K):
47 attribute = attributes[top_obj_dims[example_index, i].item()]
48 coeff = top_obj_coeffs[example_index, i].item()
49 print(f"{attribute}: {round(coeff,5)}")
50
51# Float16
52# code-complexity: 0.19922
53# helpsteer-verbosity: -0.10864
54# ultrafeedback-instruction_following: 0.07861
55
56# 4bit
57# code-complexity: 0.19043
58# helpsteer-verbosity: -0.11304
59# ultrafeedback-instruction_following: 0.08203
60
61# The actual rewards of this example from the HelpSteer dataset
62# are [3,3,4,2,2] for the five helpsteer objectives:
63# helpfulness, correctness, coherence, complexity, verbosity
64# We can linearly transform our predicted rewards to the
65# original reward space to compare with the ground truth
66helpsteer_rewards_pred = multi_obj_rewards[0, :5] * 5 - 0.5
67print(helpsteer_rewards_pred)
68# float16 [2.78125 2.859375 3.484375 1.3847656 1.296875 ]
69# 4bit [1.7754, 1.9316, 3.4062, 1.2773, 1.8438]1from 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},
}