RLHFlow / pair-preference-model-LLaMA3-8B

huggingface.co
Total runs: 212
24-hour runs: 0
7-day runs: -63
30-day runs: -123
Model's Last Updated: October 14 2024
text-generation

Introduction of pair-preference-model-LLaMA3-8B

Model Details of pair-preference-model-LLaMA3-8B

This preference model is trained from LLaMA3-8B-it with the training script at Reward Modeling .

The dataset is RLHFlow/pair_preference_model_dataset. It achieves Chat-98.6, Char-hard 65.8, Safety 89.6, and reasoning 94.9 in reward bench.

See our paper RLHF Workflow: From Reward Modeling to Online RLHF for more details of this model.

Service the RM

Here is an example to use the Preference Model to rank a pair. For n>2 responses, it is recommened to use the tournament style ranking strategy to get the best response so that the complexity is linear in n.

device = 0

model = AutoModelForCausalLM.from_pretrained(script_args.preference_name_or_path,
                                             torch_dtype=torch.bfloat16, attn_implementation="flash_attention_2").cuda()
tokenizer = AutoTokenizer.from_pretrained(script_args.preference_name_or_path, use_fast=True)
tokenizer_plain = AutoTokenizer.from_pretrained(script_args.preference_name_or_path, use_fast=True)
tokenizer_plain.chat_template = "\n{% for message in messages %}{% if loop.index0 % 2 == 0 %}\n\n<turn> user\n {{ message['content'] }}{% else %}\n\n<turn> assistant\n {{ message['content'] }}{% endif %}{% endfor %}\n\n\n"

prompt_template = "[CONTEXT] {context} [RESPONSE A] {response_A} [RESPONSE B] {response_B} \n"
token_id_A = tokenizer.encode("A", add_special_tokens=False)
token_id_B = tokenizer.encode("B", add_special_tokens=False)
assert len(token_id_A) == 1 and len(token_id_B) == 1
token_id_A = token_id_A[0]
token_id_B = token_id_B[0]
temperature = 1.0


model.eval()
response_chosen = "BBBB"
response_rejected = "CCCC"

## We can also handle multi-turn conversation.
instruction = [{"role": "user", "content": ...},
{"role": "assistant", "content": ...},
{"role": "user", "content": ...},
]
context = tokenizer_plain.apply_chat_template(instruction, tokenize=False)
responses = [response_chosen, response_rejected]
probs_chosen = []
    
for chosen_position in [0, 1]:
    # we swap order to mitigate position bias
    response_A = responses[chosen_position]
    response_B = responses[1 - chosen_position]
    prompt = prompt_template.format(context=context, response_A=response_A, response_B=response_B)
    message = [
        {"role": "user", "content": prompt},
    ]

    input_ids = tokenizer.encode(tokenizer.apply_chat_template(message, tokenize=False).replace(tokenizer.bos_token, ""), return_tensors='pt', add_special_tokens=False).cuda() 

    with torch.no_grad():
        output = model(input_ids)
    logit_A = output.logits[0, -1, token_id_A].item()
    logit_B = output.logits[0, -1, token_id_B].item()
    # take softmax to get the probability; using numpy
    Z = np.exp(logit_A / temperature) + np.exp(logit_B / temperature)
    logit_chosen = [logit_A, logit_B][chosen_position]
    prob_chosen = np.exp(logit_chosen / temperature) / Z
    probs_chosen.append(prob_chosen)

avg_prob_chosen = np.mean(probs_chosen)
correct = 0.5 if avg_prob_chosen == 0.5 else float(avg_prob_chosen > 0.5)
print(correct)
Citation

If you use this model in your research, please consider citing our paper

@misc{rlhflow,
      title={RLHF Workflow: From Reward Modeling to Online RLHF}, 
      author={Hanze Dong and Wei Xiong and Bo Pang and Haoxiang Wang and Han Zhao and Yingbo Zhou and Nan Jiang and Doyen Sahoo and Caiming Xiong and Tong Zhang},
      year={2024},
      eprint={2405.07863},
      archivePrefix={arXiv},
      primaryClass={cs.LG}
}

and Google's Slic paper (which initially proposes this pairwise preference model)

@article{zhao2023slic,
  title={Slic-hf: Sequence likelihood calibration with human feedback},
  author={Zhao, Yao and Joshi, Rishabh and Liu, Tianqi and Khalman, Misha and Saleh, Mohammad and Liu, Peter J},
  journal={arXiv preprint arXiv:2305.10425},
  year={2023}
}

Runs of RLHFlow pair-preference-model-LLaMA3-8B on huggingface.co

212
Total runs
0
24-hour runs
-4
3-day runs
-63
7-day runs
-123
30-day runs

More Information About pair-preference-model-LLaMA3-8B huggingface.co Model

More pair-preference-model-LLaMA3-8B license Visit here:

https://choosealicense.com/licenses/llama3

pair-preference-model-LLaMA3-8B huggingface.co

pair-preference-model-LLaMA3-8B huggingface.co is an AI model on huggingface.co that provides pair-preference-model-LLaMA3-8B's model effect (), which can be used instantly with this RLHFlow pair-preference-model-LLaMA3-8B model. huggingface.co supports a free trial of the pair-preference-model-LLaMA3-8B model, and also provides paid use of the pair-preference-model-LLaMA3-8B. Support call pair-preference-model-LLaMA3-8B model through api, including Node.js, Python, http.

pair-preference-model-LLaMA3-8B huggingface.co Url

https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B

RLHFlow pair-preference-model-LLaMA3-8B online free

pair-preference-model-LLaMA3-8B huggingface.co is an online trial and call api platform, which integrates pair-preference-model-LLaMA3-8B's modeling effects, including api services, and provides a free online trial of pair-preference-model-LLaMA3-8B, you can try pair-preference-model-LLaMA3-8B online for free by clicking the link below.

RLHFlow pair-preference-model-LLaMA3-8B online free url in huggingface.co:

https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B

pair-preference-model-LLaMA3-8B install

pair-preference-model-LLaMA3-8B is an open source model from GitHub that offers a free installation service, and any user can find pair-preference-model-LLaMA3-8B on GitHub to install. At the same time, huggingface.co provides the effect of pair-preference-model-LLaMA3-8B install, users can directly use pair-preference-model-LLaMA3-8B installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

pair-preference-model-LLaMA3-8B install url in huggingface.co:

https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B

Url of pair-preference-model-LLaMA3-8B

pair-preference-model-LLaMA3-8B huggingface.co Url

Provider of pair-preference-model-LLaMA3-8B huggingface.co

RLHFlow
ORGANIZATIONS

Other API from RLHFlow

huggingface.co

Total runs: 471
Run Growth: -1.5K
Growth Rate: -313.16%
Updated:November 04 2024
huggingface.co

Total runs: 20
Run Growth: -7
Growth Rate: -35.00%
Updated:November 04 2024