Introduction¶
Conceptual overview of rhscope: what it is, when to reach for it, what you need to feed it, and the trade-offs that come with the approach. For runnable code, go to the Quickstart or the Examples.
What rhscope is¶
rhscope is a Python library for detecting reward hacking in LLM reinforcement-learning post-training. Reward hacking is when a policy learns to maximise its reward signal through shortcuts the reward function did not intend to reward: hardcoding expected test outputs, deleting or skipping tests, padding responses to game a verbosity-sensitive grader, admitting the shortcut in a comment, and so on. Left unchecked it quietly corrupts a training run - your loss curve looks healthy while the policy learns something you did not ask for.
rhscope trains a linear probe on the policy’s own hidden-state activations and uses it as a running monitor during RL fine-tuning. Probes catch hacking at ~1000x less compute than an LLM-judge monitor and read the model’s internal representation of what it is doing rather than just the output text.
The library is intentionally focused on probes. Benchmark
infrastructure, TRL / verl integration, DPO scoring, evasion detection,
online probe adaptation, token-level attribution, a
reference-model-delta research detector - all of these are first-class.
LLM-as-judge and heuristic/rule-based detectors are not shipped; that
scope belongs elsewhere, and users who want to ensemble rhscope with an
external detector can do so through the
Detector protocol and
CompositeDetector.
When to reach for it¶
Three practical scenarios:
Monitoring an RL post-training run. Attach a probe-backed
HackMonitorto your TRLGRPOTraineras a reward function. Every rollout gets a score and those scores land in TensorBoard / wandb alongside your loss curves. You can watch the hacking rate rise before it shows up as a downstream regression.Penalising hacking during training. Same attachment, non-zero
penalty_coef. The monitor’s score is subtracted from the task reward, so the policy is incentivised to stop hacking. Works out of the box with GRPO/PPO/DPO via TRL’s native “sum of reward functions” composition - no subclassing, no fragile callbacks. The same pattern works with verl.Cleaning preference data for DPO / IPO / KTO.
score_dpo_pairs()scores the chosen and rejected completion of every preference pair and flags cases where the chosen completion is more hack-like than the rejected - i.e. your preference data is actively rewarding hacking. Filter those pairs out before training.
A fourth use is purely analytical: run the benchmark harness against a frozen checkpoint to measure its baseline hacking tendency on RH-Detect-style data before you start RL.
Where labelled training data comes from¶
A probe needs a few hundred (prompt, response, is_hack) examples per
(base_model, category) combination. Two paths:
You already have labelled data. RH-Detect-style JSONL (or any JSONL with
prompt,response,label,categoryfields) loads viaload_hack_examples(). Aliases likeis_hacking,behavior,input,outputare normalized at load time.You need to generate it. rhscope ships
CodeShortcutEnv- an MBPP-backed coding environment with a weak/strong test split. The reward function only sees the weak tests; the strong tests are held out as a ground-truth oracle. A response is labelled hacking iff it passes the weak set but fails the strong set - i.e. it gamed the visible grader without actually solving the problem. Code execution is sandboxed (subprocess or Docker, see limitations).
The env is also what the GRPO recipe
(run_grpo_recipe()) and the
rhscope env-eval CLI subcommand use to produce hacking behaviour on
demand for probe training and evaluation.
Why probes¶
A probe is a thin classifier fit on the policy’s hidden states at a chosen transformer layer. Training is cheap (minutes on a modest GPU), inference is nearly free (one dot product per rollout for a linear probe), and the signal is substantially stronger than text-based detection because the probe reads the model’s internal representation of hacking rather than just the generated text.
Trade-offs to know up front:
Needs labelled data. See the section above - either curate from an RH-Detect-style dataset or generate via
CodeShortcutEnv.Base-model bound. A probe trained on
Qwen3-1.5Bactivations is not valid forLlama-3.2-3B.require_base_model()enforces this loudly.Can be evaded under adversarial pressure. A policy trained against a probe penalty can learn to rotate its activation signature off the probe direction. This is exactly the failure mode
EvasionDetectorexists to catch - see the limitations page and related work.
The probes we ship¶
DoMProbe- difference-of-means direction, optional ZCA whitening. Default. Trains in seconds.LogisticProbe- L2 logistic regression via torch-native L-BFGS. Stronger separator on noisier data.MLPProbe- shallow two-layer MLP with early stopping. Use when the hacking concept is non-linear in activation space.OnlineProbe(research) - DoM probe withpartial_fitso you can update during streaming RL rollouts;snapshot()freezes it to a regularDoMProbeon demand.
All four speak the same fit, score, save, load surface and
round-trip through the same SafeTensors + JSON-sidecar persistence.
Research: telling reform from obfuscation¶
When you train against a probe-based reward penalty, two things can drive the monitored hacking rate down:
The policy genuinely stops hacking (reform).
The policy keeps hacking but changes its activation signature so the probe no longer fires (obfuscation / evasion).
Scalar hack-rate curves cannot distinguish them.
EvasionDetector anchors a baseline probe
direction, refits a fresh direction on new labelled activations at
each eval step, and tracks both the subspace angle and the AUROC of
baseline / current directions on held-out data. Classifies the
trajectory as reforming / obfuscating / stable / undecided.
A second research detector,
RefDeltaDetector, scores the per-token
log-probability delta between the trained policy and its frozen
reference model - a cheap signal that uses both models you already
have loaded for the KL penalty. Positioning against the
monitor-evasion literature is under
related work.
Where to go next¶
Quickstart - ten minutes from
pip installto a first hacking score, with every CLI and Python entry point you need.Examples - five self-contained runnable scripts, one per common workflow.
API overview - the complete public surface, module by module.
Related work - how rhscope positions against activation-probe literature and the monitor-evasion thread of alignment research.
Limitations - honest list of what rhscope does not do in v0.1 and which failure modes to watch for.