Views
No views yet
| Adapter folder | Pair scheme | What it captures |
|---|---|---|
style/ | Style-only | Markdown / verbose surface-style preferences (chosen = plain & short, rejected = bullet-heavy / markdown-rich), holding correctness equal. |
correctness/ | Correctness-only | Answer-correctness preferences (chosen = correct GSM8K solution, rejected = incorrect), holding surface style equal. |
cross/ | Cross | Crossed preferences where surface style and correctness disagree (chosen = correct-but-plain, rejected = wrong-but-stylish), the configuration on which base RMs most often err. |
Skywork/Skywork-Reward-V2-Llama-3.1-8Bxxccho/gsm8k_rmbench_style
— GSM8K math problems with 6 surface-style + correctness variants per question,
yielding ~23k pairs per pair_mode.1import torch
2from peft import PeftModel
3from transformers import AutoModelForSequenceClassification, AutoTokenizer
4
5# 1. Load the base reward model
6BASE = "Skywork/Skywork-Reward-V2-Llama-3.1-8B"
7SUB = None
8kwargs = dict(num_labels=1, torch_dtype=torch.bfloat16, device_map="auto")
9if SUB:
10 base = AutoModelForSequenceClassification.from_pretrained(BASE, subfolder=SUB, **kwargs)
11 tok = AutoTokenizer.from_pretrained(BASE, subfolder=SUB)
12else:
13 base = AutoModelForSequenceClassification.from_pretrained(BASE, **kwargs)
14 tok = AutoTokenizer.from_pretrained(BASE)
15
16# 2. Wrap with this LoRA (pick the pair_mode you want)
17PAIR_MODE = "cross" # one of: style, correctness, cross
18model = PeftModel.from_pretrained(base, "xxccho/rm-debias-loras-skywork-llama-3.1-8b", subfolder=PAIR_MODE)
19
20# 3. Use the standard PEFT scaling-trick to *subtract* the LoRA.
21# Forward of (base − λ·LoRA) is obtained by setting LoRA scaling to −λ·alpha.
22# For our setup (alpha=16, rank=8 → base_scaling=2.0), λ=1.0 means we
23# subtract the LoRA at full strength.
24LAMBDA = 0.5
25for name, module in model.named_modules():
26 if hasattr(module, "scaling") and isinstance(module.scaling, dict):
27 for k in module.scaling:
28 module.scaling[k] = -LAMBDA * 2.0 # alpha / r = 16/8 = 2.0
29
30# 4. Score a (prompt, response) pair
31messages = [
32 {"role": "user", "content": "What is 7 × 8?"},
33 {"role": "assistant", "content": "7 × 8 = 56."},
34]
35text = tok.apply_chat_template(messages, tokenize=False)
36inputs = tok(text, return_tensors="pt").to(model.device)
37with torch.no_grad():
38 reward = model(**inputs).logits.squeeze(-1).item()
39print(f"reward = {reward:.3f}")| Pair mode | Reasonable λ range (subtract) |
|---|---|
| style | 0.2 – 0.7 |
| correctness | 0.2 – 0.5 |
| cross | 0.3 – 1.0 |
base_RM: prefers chosen over rejected (correct)
LoRA: prefers rejected over chosen (bias direction)
debiased: base − λ · LoRA ⇒ same correctness, less style biastrain_style_lora_gsm8k.py script in the source repo):1python scripts/train_style_lora_gsm8k.py \
2 --model "Skywork/Skywork-Reward-V2-Llama-3.1-8B" \
3 --data "rm_gsm8k_dataset_builder/generated/gsm8k_rmbench_train_clean.jsonl" \
4 --pair-mode <style | correctness | cross> \
5 --direction undesired \
6 --epochs 3 \
7 --learning-rate 1e-5adapter_config.json):q_proj, k_proj, v_proj, o_proj (attention only)r=8, alpha=16 (base scaling α/r = 2.0)1python scripts/eval_reward_bench2.py \
2 --base_model "Skywork/Skywork-Reward-V2-Llama-3.1-8B" \
3 --lora_path <local clone of this repo>/<pair_mode> \
4 --output_path rb2_<pair_mode>.json \
5 --lambdas -1.0 -0.5 -0.2 0.0 0.1 0.2 0.3 0.5 0.7 1.0 2.0 3.0λ = +x in this script means "subtract x·LoRA"; sign convention matches
the script's --lambdas arg.)Skywork/Skywork-Reward-V2-Llama-3.1-8B is governed by
its own license — please review that before redistribution.