Instructions to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="QuantFactory/pair-preference-model-LLaMA3-8B-GGUF") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("QuantFactory/pair-preference-model-LLaMA3-8B-GGUF", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M # Run inference directly in the terminal: llama cli -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
Use Docker
docker model run hf.co/QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "QuantFactory/pair-preference-model-LLaMA3-8B-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantFactory/pair-preference-model-LLaMA3-8B-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
- SGLang
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "QuantFactory/pair-preference-model-LLaMA3-8B-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantFactory/pair-preference-model-LLaMA3-8B-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "QuantFactory/pair-preference-model-LLaMA3-8B-GGUF" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantFactory/pair-preference-model-LLaMA3-8B-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with Ollama:
ollama run hf.co/QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
- Unsloth Studio
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for QuantFactory/pair-preference-model-LLaMA3-8B-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for QuantFactory/pair-preference-model-LLaMA3-8B-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for QuantFactory/pair-preference-model-LLaMA3-8B-GGUF to start chatting
- Docker Model Runner
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with Docker Model Runner:
docker model run hf.co/QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
- Lemonade
How to use QuantFactory/pair-preference-model-LLaMA3-8B-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull QuantFactory/pair-preference-model-LLaMA3-8B-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.pair-preference-model-LLaMA3-8B-GGUF-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: llama3
|
| 3 |
+
base_model: RLHFlow/pair-preference-model-LLaMA3-8B
|
| 4 |
+
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- llama
|
| 8 |
+
- conversational
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# pair-preference-model-LLaMA3-8B-GGUF
|
| 12 |
+
This is quantized version of [RLHFlow/pair-preference-model-LLaMA3-8B](https://huggingface.co/RLHFlow/pair-preference-model-LLaMA3-8B) created using llama.cpp
|
| 13 |
+
|
| 14 |
+
# Model Description
|
| 15 |
+
This preference model is trained from [LLaMA3-8B-it](meta-llama/Meta-Llama-3-8B-Instruct) with the training script at [Reward Modeling](https://github.com/RLHFlow/RLHF-Reward-Modeling/tree/pm_dev/pair-pm).
|
| 16 |
+
|
| 17 |
+
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.
|
| 18 |
+
|
| 19 |
+
See our paper [RLHF Workflow: From Reward Modeling to Online RLHF](https://arxiv.org/abs/2405.07863) for more details of this model.
|
| 20 |
+
|
| 21 |
+
## Service the RM
|
| 22 |
+
|
| 23 |
+
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.
|
| 24 |
+
|
| 25 |
+
```python
|
| 26 |
+
device = 0
|
| 27 |
+
|
| 28 |
+
model = AutoModelForCausalLM.from_pretrained(script_args.preference_name_or_path,
|
| 29 |
+
torch_dtype=torch.bfloat16, attn_implementation="flash_attention_2").cuda()
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(script_args.preference_name_or_path, use_fast=True)
|
| 31 |
+
tokenizer_plain = AutoTokenizer.from_pretrained(script_args.preference_name_or_path, use_fast=True)
|
| 32 |
+
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"
|
| 33 |
+
|
| 34 |
+
prompt_template = "[CONTEXT] {context} [RESPONSE A] {response_A} [RESPONSE B] {response_B} \n"
|
| 35 |
+
token_id_A = tokenizer.encode("A", add_special_tokens=False)
|
| 36 |
+
token_id_B = tokenizer.encode("B", add_special_tokens=False)
|
| 37 |
+
assert len(token_id_A) == 1 and len(token_id_B) == 1
|
| 38 |
+
token_id_A = token_id_A[0]
|
| 39 |
+
token_id_B = token_id_B[0]
|
| 40 |
+
temperature = 1.0
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
model.eval()
|
| 44 |
+
response_chosen = "BBBB"
|
| 45 |
+
response_rejected = "CCCC"
|
| 46 |
+
|
| 47 |
+
## We can also handle multi-turn conversation.
|
| 48 |
+
instruction = [{"role": "user", "content": ...},
|
| 49 |
+
{"role": "assistant", "content": ...},
|
| 50 |
+
{"role": "user", "content": ...},
|
| 51 |
+
]
|
| 52 |
+
context = tokenizer_plain.apply_chat_template(instruction, tokenize=False)
|
| 53 |
+
responses = [response_chosen, response_rejected]
|
| 54 |
+
probs_chosen = []
|
| 55 |
+
|
| 56 |
+
for chosen_position in [0, 1]:
|
| 57 |
+
# we swap order to mitigate position bias
|
| 58 |
+
response_A = responses[chosen_position]
|
| 59 |
+
response_B = responses[1 - chosen_position]
|
| 60 |
+
prompt = prompt_template.format(context=context, response_A=response_A, response_B=response_B)
|
| 61 |
+
message = [
|
| 62 |
+
{"role": "user", "content": prompt},
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
input_ids = tokenizer.encode(tokenizer.apply_chat_template(message, tokenize=False).replace(tokenizer.bos_token, ""), return_tensors='pt', add_special_tokens=False).cuda()
|
| 66 |
+
|
| 67 |
+
with torch.no_grad():
|
| 68 |
+
output = model(input_ids)
|
| 69 |
+
logit_A = output.logits[0, -1, token_id_A].item()
|
| 70 |
+
logit_B = output.logits[0, -1, token_id_B].item()
|
| 71 |
+
# take softmax to get the probability; using numpy
|
| 72 |
+
Z = np.exp(logit_A / temperature) + np.exp(logit_B / temperature)
|
| 73 |
+
logit_chosen = [logit_A, logit_B][chosen_position]
|
| 74 |
+
prob_chosen = np.exp(logit_chosen / temperature) / Z
|
| 75 |
+
probs_chosen.append(prob_chosen)
|
| 76 |
+
|
| 77 |
+
avg_prob_chosen = np.mean(probs_chosen)
|
| 78 |
+
correct = 0.5 if avg_prob_chosen == 0.5 else float(avg_prob_chosen > 0.5)
|
| 79 |
+
print(correct)
|
| 80 |
+
```
|