Views
No views yet

1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3device = "cuda"
4path = "nicolinho/QRM-Llama3.1-8B-v2"
5model = AutoModelForSequenceClassification.from_pretrained(path, torch_dtype=torch.bfloat16, device_map=device, trust_remote_code=True)
6tokenizer = AutoTokenizer.from_pretrained(path, use_fast=True)
7# We load a random sample from the validation set of the HelpSteer dataset
8prompt = 'Does pineapple belong on a Pizza?'
9response = "There are different opinions on this. Some people like pineapple on a Pizza while others condemn this."
10messages = [{"role": "user", "content": prompt},
11 {"role": "assistant", "content": response}]
12input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
13with torch.no_grad():
14 output = model(input_ids)
15 # Expectation of the reward distribution
16 reward = output.score.cpu().float()
17 # Quantile estimates for the quantiles 0.05, 0.1, ..., 0.9, 0.95 representing the distribution over rewards
18 reward_quantiles = output.reward_quantiles.cpu().float()
19
20# The attributes of the 5 reward objectives
21attributes = ['helpsteer-helpfulness','helpsteer-correctness','helpsteer-coherence',
22 'helpsteer-complexity','helpsteer-verbosity']@article{dorka2024quantile,
title={Quantile Regression for Distributional Reward Models in RLHF},
author={Dorka, Nicolai},
journal={arXiv preprint arXiv:2409.10164},
year={2024}
}