rhscope.integrations.dpo¶
Offline monitor scoring for DPO-style preference datasets.
DPO (and its siblings IPO, KTO, ORPO, SimPO) optimize a policy against preference pairs - chosen / rejected completions for a shared prompt - with no online rollouts. There is no reward signal to penalize mid-training, so the natural integration point is before training: score both halves of each pair with the monitor and let the caller filter or re-weight preferences that reward hacking behaviors.
score_dpo_pairs() is the single entry point. Its return value carries
both score vectors plus per-pair metadata that downstream code can turn into
filter masks.
- class rhscope.integrations.dpo.DPOPairScores(chosen_scores, rejected_scores, threshold, preference_flips_to_hacker)[source]¶
Bases:
objectMonitor scores for a batch of DPO preference pairs.
- Variables:
chosen_scores (numpy.ndarray) –
(N,)scores for the preferred completion of each pair.rejected_scores (numpy.ndarray) –
(N,)scores for the dispreferred completion.threshold (float) – The monitor’s binary-decision threshold at scoring time.
preference_flips_to_hacker (numpy.ndarray) – Boolean mask;
Truewhere the chosen completion scores higher than the rejected - i.e. the preference data rewards more hacking. Prime candidates for filtering.
- Parameters:
- property hacking_rate_chosen: float¶
Fraction of chosen completions whose score is at or above threshold.
- rhscope.integrations.dpo.score_dpo_pairs(monitor, model, tokenizer, prompts, chosen, rejected, *, batch_size=8, max_length=1024)[source]¶
Score both halves of every preference pair with
monitor.The chosen and rejected completions are scored independently against the policy model that
monitorwas trained for - the caller is responsible for aligning themodelargument withmonitor.base_model.- Parameters:
monitor (HackMonitor) – Loaded
HackMonitor.model (Any) – Policy model whose activations the probe reads. Should match
monitor.base_model.tokenizer (Any) – Matching tokenizer.
prompts (Sequence[str]) – Shared prompts, one per preference pair.
chosen (Sequence[str]) – Preferred completions, aligned with
prompts.rejected (Sequence[str]) – Dispreferred completions, aligned with
prompts.batch_size (int) – Forward-pass batch size.
max_length (int) – Token truncation length.
- Returns:
DPOPairScorescarrying both score vectors.- Raises:
ValueError – If input lengths differ.
- Return type: