Views
No views yet

1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3device = "cuda"
4path = "nicolinho/QRM-Llama3-8B"
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 = 'Does pineapple belong on a Pizza?'
10response = "There are different opinions on this. Some people like pineapple on a Pizza while others condemn this."
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 # Expectation of the reward distribution
17 reward = output.score.cpu().float()
18 # Quantile estimates for the quantiles 0.05, 0.1, ..., 0.9, 0.95 representing the distribution over rewards
19 reward_quantiles = output.reward_quantiles.cpu().float()
20
21# The attributes of the 19 reward objectives
22attributes = ['helpsteer-helpfulness','helpsteer-correctness','helpsteer-coherence',
23 'helpsteer-complexity','helpsteer-verbosity','ultrafeedback-overall_score',
24 'ultrafeedback-instruction_following', 'ultrafeedback-truthfulness',
25 'ultrafeedback-honesty','ultrafeedback-helpfulness','beavertails-is_safe',
26 'prometheus-score','argilla-overall_quality','argilla-judge_lm','code-complexity',
27 'code-style','code-explanation','code-instruction-following','code-readability']@article{dorka2024quantile,
title={Quantile Regression for Distributional Reward Models in RLHF},
author={Dorka, Nicolai},
journal={arXiv preprint arXiv:2409.10164},
year={2024}
}