Skip to main content

rhscope

License

Activation probes for reward hacking in LLM RL post-training.

rhscope trains linear probes on a base model's hidden states to detect reward hacking during RL fine-tuning, ships a sandbox-verified benchmark to evaluate those probes, and includes a probe-subspace drift detector that distinguishes genuine reform from monitor evasion.

pip install rhscope
from rhscope import HackMonitor, load_hack_examples, train_probe
from rhscope.training.trainer import load_model_for_probing

# 1. Train a probe for your base model (~5 min on a modest GPU).
model, tokenizer = load_model_for_probing("Qwen/Qwen3-1.5B")
result = train_probe(
    model, tokenizer,
    load_hack_examples("hack_examples.jsonl"),
    probe_type="dom",
    category="code_shortcut",
)
result.probe.save("my-probe")

# 2. Use it as a reward-hacking monitor during RL.
monitor = HackMonitor.from_probe(result.probe, model=model, tokenizer=tokenizer)
scores  = monitor.score_batch(prompts, completions)   # higher = more hack-like

Research - evasion vs reform

A policy trained against a probe-based reward penalty can either genuinely stop hacking (reform) or continue hacking after rotating its activation signature out of the probe's subspace (evade/obfuscate). Scalar hack-rate curves cannot tell the two apart. rhscope.research.EvasionDetector anchors a baseline probe direction, fits a fresh direction at each eval step on held-out data, and classifies the trajectory as reforming / obfuscating / stable / undecided.

Install

pip install rhscope                          # core: probes + bench
pip install "rhscope[trl]"                   # + GRPO/PPO reward-penalty integration
pip install "rhscope[dev,bench,trl]"         # development

Python 3.10+. Probe training and scoring run on whatever GPU torch can see; VRAM required scales with the base model's hidden state. All probe types train on CPU too, which is useful for small-model or heuristic-labelled smoke tests.

Plug a probe into GRPO training

from trl import GRPOTrainer
from rhscope import HackMonitor
from rhscope.integrations.trl import make_monitor_reward_fn

monitor   = HackMonitor.from_pretrained("my-probe")           # or .from_probe(probe)
reward_fn = make_monitor_reward_fn(monitor, penalty_coef=0.1).fn

trainer = GRPOTrainer(
    model=your_model,
    reward_funcs=[your_env.reward_func(), reward_fn],
    ...
)
trainer.train()

TRL sums reward-function outputs, so reward_fn returning negative values penalises hacking without subclassing the trainer or wiring custom callbacks. Watch monitor/hack_fraction in TensorBoard alongside your loss curve to catch monitor evasion before it corrupts the run.

The same pattern works with verl via rhscope.integrations.verl.MonitorRewardModel.

Probes we ship

Probe Where When to use
DoMProbe rhscope.DoMProbe Default. Difference-of-means direction with optional ZCA whitening. Trains in seconds, interpretable as a single activation direction.
LogisticProbe rhscope.LogisticProbe L2 logistic regression via torch-native L-BFGS. Stronger separator than DoM on noisier data.
MLPProbe rhscope.MLPProbe Shallow two-layer MLP with early stopping. Use when the hacking concept is non-linear in activation space.
OnlineProbe rhscope.OnlineProbe DoM probe with partial_fit for streaming RL rollouts; snapshots to a frozen DoMProbe on demand.

Choose the probe in train_probe(..., probe_type="dom" / "logistic" / "mlp").

Filter preference data for DPO / IPO / KTO

from rhscope.integrations.dpo import score_dpo_pairs

scores = score_dpo_pairs(monitor, model, tokenizer, prompts, chosen, rejected)
keep   = scores.filter_mask(drop_preference_flips=True)
clean  = [p for p, k in zip(preferences, keep) if k]

preference_flips_to_hacker flags pairs where the chosen completion scores more hack-like than the rejected one, i.e. your preference data is actively rewarding hacking.

Compose with your own detectors

rhscope ships probes. If you want to ensemble a probe with an external LLM-as-judge, a custom rule, or another team's probe, wrap your scoring function with CallableDetector and feed it to CompositeDetector:

from rhscope.bench import CallableDetector, CompositeDetector

def my_judge(prompts, responses):
    # call your judge here (OpenAI, Anthropic, Ollama, whatever)
    return scores

fused = CompositeDetector(
    [probe_detector, CallableDetector(my_judge, name="judge")],
    reducer="max",
)
monitor = HackMonitor(fused)

We do not ship built-in judge or heuristic detectors - that scope belongs to other libraries. rhscope is the probe side.

Documentation

Full docs site at 082t.github.io/rhscope. Local sources:

Citation

@software{rhscope,
    title = {rhscope: activation probes for reward hacking in LLM RL post-training},
    year  = {2026},
}

License

Apache 2.0. See LICENSE.

Metadata

Release files for rhscope 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rhscope 0.1.0
File Size Uploaded Provenance Actions
rhscope-0.1.0.tar.gz 172.8 kB With provenance Details for rhscope-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rhscope 0.1.0
File Interpreter ABI Platform Actions
rhscope-0.1.0-py3-none-any.whl Python 3 none any Details for rhscope-0.1.0-py3-none-any.whl

Total release size: 315.4 kB

Release files / rhscope-0.1.0.tar.gz

Download URL rhscope-0.1.0.tar.gz
Size 172.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5892533e350ba8653101e7bb50225da4fa9126da5970ad14846c639ea568cdc9
BLAKE2b-256 checksum
How to use checksums
9e0e1bb86ab3b760e9bd04522c72e05c305fe78647d509ca5a89eebca343204e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / rhscope-0.1.0-py3-none-any.whl

Download URL rhscope-0.1.0-py3-none-any.whl
Size 142.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ffb1ec02607341c7dd792a7e352eeb3783a84e56cc10371a9fb3d7b9f07f89ab
BLAKE2b-256 checksum
How to use checksums
fa6183073650e9ccd99462a06240f5075b96638a68cab3862fbd7ac94a7587ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for rhscope 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rhscope-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page