Metadata-Version: 2.5
Name: reward-lens
Version: 3.2.0
Summary: Audit a reward system, trace what it teaches, and write the result down as a record anyone can check
Project-URL: Homepage, https://github.com/reward-lens/reward-lens
Project-URL: Documentation, https://reward-lens.github.io
Project-URL: Changelog, https://github.com/reward-lens/reward-lens/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/reward-lens/reward-lens/issues
Author: Mohammed Suhail B Nadaf
License-Expression: MIT
License-File: LICENSE
Keywords: RLHF,RLVR,alignment,evaluation,measurement,reward-design,reward-hacking,reward-model
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: click>=8.5
Requires-Dist: coverage>=7.15.0
Requires-Dist: cryptography>=50.0.1
Requires-Dist: jsonschema-rs>=0.29
Requires-Dist: libcst>=1.9
Requires-Dist: pydantic-settings>=2.13
Requires-Dist: pydantic>=2.12
Requires-Dist: pyyaml>=6.0
Requires-Dist: rfc8785>=0.1.4
Provides-Extra: all
Requires-Dist: accelerate>=0.25.0; extra == 'all'
Requires-Dist: anyio>=4.9; extra == 'all'
Requires-Dist: cosmic-ray>=8.4.0; extra == 'all'
Requires-Dist: coverage>=7.15.0; extra == 'all'
Requires-Dist: crosshair-tool<0.1,>=0.0.109; extra == 'all'
Requires-Dist: datasets>=2.16.0; extra == 'all'
Requires-Dist: httpx2>=2.5.0; extra == 'all'
Requires-Dist: hypothesis>=6.100.0; extra == 'all'
Requires-Dist: jsonschema>=4.20.0; extra == 'all'
Requires-Dist: matplotlib>=3.7.0; extra == 'all'
Requires-Dist: mcp-types==2.2.0; extra == 'all'
Requires-Dist: mlflow<4,>=3.11; extra == 'all'
Requires-Dist: mutmut<4.0,>=3.6.0; extra == 'all'
Requires-Dist: numpy>=1.24.0; extra == 'all'
Requires-Dist: openenv==0.6.0; extra == 'all'
Requires-Dist: opentelemetry-api>=1.28.0; extra == 'all'
Requires-Dist: pandas>=2.0.0; extra == 'all'
Requires-Dist: peft>=0.7.0; extra == 'all'
Requires-Dist: pyarrow>=15.0; extra == 'all'
Requires-Dist: pydantic>=2.12.0; extra == 'all'
Requires-Dist: pyjwt[crypto]>=2.10.1; extra == 'all'
Requires-Dist: python-multipart>=0.0.9; extra == 'all'
Requires-Dist: safetensors>=0.4.0; extra == 'all'
Requires-Dist: salib>=1.5.0; extra == 'all'
Requires-Dist: scikit-learn>=1.3.0; extra == 'all'
Requires-Dist: scipy>=1.10.0; extra == 'all'
Requires-Dist: seaborn>=0.13.0; extra == 'all'
Requires-Dist: sigstore>=3.0; extra == 'all'
Requires-Dist: sse-starlette>=3.0.0; extra == 'all'
Requires-Dist: starlette>=0.27; extra == 'all'
Requires-Dist: torch<3.0,>=2.1.0; extra == 'all'
Requires-Dist: tqdm>=4.65.0; extra == 'all'
Requires-Dist: transformers<6.0,>=4.36.0; extra == 'all'
Requires-Dist: trl<2.0,>=1.9; extra == 'all'
Requires-Dist: typing-extensions>=4.13.0; extra == 'all'
Requires-Dist: typing-inspection>=0.4.1; extra == 'all'
Requires-Dist: uvicorn>=0.31.1; extra == 'all'
Requires-Dist: wandb<1,>=0.23; extra == 'all'
Provides-Extra: judge
Provides-Extra: mcp
Requires-Dist: anyio>=4.9; extra == 'mcp'
Requires-Dist: httpx2>=2.5.0; extra == 'mcp'
Requires-Dist: jsonschema>=4.20.0; extra == 'mcp'
Requires-Dist: mcp-types==2.2.0; extra == 'mcp'
Requires-Dist: opentelemetry-api>=1.28.0; extra == 'mcp'
Requires-Dist: pydantic>=2.12.0; extra == 'mcp'
Requires-Dist: pyjwt[crypto]>=2.10.1; extra == 'mcp'
Requires-Dist: python-multipart>=0.0.9; extra == 'mcp'
Requires-Dist: sse-starlette>=3.0.0; extra == 'mcp'
Requires-Dist: starlette>=0.27; extra == 'mcp'
Requires-Dist: typing-extensions>=4.13.0; extra == 'mcp'
Requires-Dist: typing-inspection>=0.4.1; extra == 'mcp'
Requires-Dist: uvicorn>=0.31.1; extra == 'mcp'
Provides-Extra: openenv
Requires-Dist: openenv==0.6.0; extra == 'openenv'
Provides-Extra: organisms
Requires-Dist: accelerate>=0.25.0; extra == 'organisms'
Requires-Dist: datasets>=2.16.0; extra == 'organisms'
Requires-Dist: numpy>=1.24.0; extra == 'organisms'
Requires-Dist: peft>=0.7.0; extra == 'organisms'
Requires-Dist: safetensors>=0.4.0; extra == 'organisms'
Requires-Dist: scikit-learn>=1.3.0; extra == 'organisms'
Requires-Dist: scipy>=1.10.0; extra == 'organisms'
Requires-Dist: torch<3.0,>=2.1.0; extra == 'organisms'
Requires-Dist: tqdm>=4.65.0; extra == 'organisms'
Requires-Dist: transformers<6.0,>=4.36.0; extra == 'organisms'
Provides-Extra: record
Requires-Dist: numpy>=1.24.0; extra == 'record'
Requires-Dist: pyarrow>=15.0; extra == 'record'
Requires-Dist: safetensors>=0.4.0; extra == 'record'
Provides-Extra: sigstore
Requires-Dist: sigstore>=3.0; extra == 'sigstore'
Provides-Extra: trace
Requires-Dist: numpy>=1.24.0; extra == 'trace'
Requires-Dist: pyarrow>=15.0; extra == 'trace'
Requires-Dist: scipy>=1.10.0; extra == 'trace'
Provides-Extra: trackers
Requires-Dist: mlflow<4,>=3.11; extra == 'trackers'
Requires-Dist: wandb<1,>=0.23; extra == 'trackers'
Provides-Extra: train
Requires-Dist: accelerate>=0.25.0; extra == 'train'
Requires-Dist: safetensors>=0.4.0; extra == 'train'
Requires-Dist: torch<3.0,>=2.1.0; extra == 'train'
Requires-Dist: transformers<6.0,>=4.36.0; extra == 'train'
Requires-Dist: trl<2.0,>=1.9; extra == 'train'
Provides-Extra: verifier
Requires-Dist: cosmic-ray>=8.4.0; extra == 'verifier'
Requires-Dist: coverage>=7.15.0; extra == 'verifier'
Requires-Dist: crosshair-tool<0.1,>=0.0.109; extra == 'verifier'
Requires-Dist: hypothesis>=6.100.0; extra == 'verifier'
Requires-Dist: mutmut<4.0,>=3.6.0; extra == 'verifier'
Requires-Dist: numpy>=1.24.0; extra == 'verifier'
Requires-Dist: salib>=1.5.0; extra == 'verifier'
Provides-Extra: viz
Requires-Dist: matplotlib>=3.7.0; extra == 'viz'
Requires-Dist: pandas>=2.0.0; extra == 'viz'
Requires-Dist: seaborn>=0.13.0; extra == 'viz'
Provides-Extra: white-box
Requires-Dist: accelerate>=0.25.0; extra == 'white-box'
Requires-Dist: numpy>=1.24.0; extra == 'white-box'
Requires-Dist: safetensors>=0.4.0; extra == 'white-box'
Requires-Dist: scikit-learn>=1.3.0; extra == 'white-box'
Requires-Dist: scipy>=1.10.0; extra == 'white-box'
Requires-Dist: torch<3.0,>=2.1.0; extra == 'white-box'
Requires-Dist: tqdm>=4.65.0; extra == 'white-box'
Requires-Dist: transformers<6.0,>=4.36.0; extra == 'white-box'
Description-Content-Type: text/markdown

# reward-lens

A model trained on a reward learns whatever the reward pays for. If a grader gives full marks to a wrong answer, training finds that answer, and the score climbs while the task stays undone. The reward is the only description of the task a training loop ever reads, so checking the reward is checking what will be learned.

reward-lens is a set of instruments for that check. Give it a grader and it looks for wrong replies the grader pays in full, and for what the code being graded can reach. Give it a training log and it checks that the updates followed the rewards the log recorded. Give it a learned reward model and its research layer, which is experimental, reads the score out of the network layer by layer. Each result is written down as a record someone else can check, and when reward-lens cannot measure something it refuses and names what is missing.

One real case. Until 5 March 2025 the Countdown scorer in reasoning-gym gave full credit to any arithmetic expression that evaluated to the target, whatever numbers the expression used, so a reply could reach full marks while ignoring the numbers the puzzle gave it. reward-lens ships that grader as an example and rejects it in about a minute on a laptop.

<!-- release-route -->
## Start here: audit a reward

```bash
python -m pip install reward-lens==3.2.0
reward-lens init --example code-reward demo   # exit 0
reward-lens audit demo                        # exit 2: unresolved
```

`init` writes a small project whose grader has a real flaw. `audit` runs that grader in a sandbox with the network denied, on replies already marked right or wrong, and prints what it found. It calls no model, costs nothing and takes about half a minute. It leaves two files: an assay record, which holds the evidence as JSON, and a report that opens in any browser. A script can pass `--format json` and read the same result as an envelope.

The run ends `unresolved`, exit 2. The audit read the flaw in the grader's code without reproducing it, and it rejects only what it has confirmed. Auditing is one of five commands: `compare`, `trace`, `improve` and `forecast` each ask a different question of a reward, and the sections below go through them.

reward-lens is Beta, and this release states no accuracy figure for its own audit. [Known limits](https://github.com/reward-lens/reward-lens/blob/main/docs/content/caveats.md) says what was measured, what was not, and what is known wrong.
<!-- /release-route -->

## What each command answers

| Command | The question | What you give it |
|---|---|---|
| [`audit`](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/audit.md) | Does this grader give credit to replies that are wrong, and what can the code it grades reach? | A grader file with a `score(task, response)` function, a file of tasks, and a file of replies marked right or wrong. A project can add an independent check of whether a reply is right. |
| [`compare`](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/compare.md) | How do the scores of the same replies change between two versions of the grader? | A bank of replies that holds each reply's score under both versions. |
| [`trace`](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/trace.md) | Did a training run use the rewards it logged? | The record of a TRL GRPO run. Needs the `trace` extra. |
| [`improve`](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/improve.md) | Is a proposed edit to the grader a real fix, judged by a rule written down before anything is measured? | A candidate file that names the edit, the competing explanations of what it changes and the acceptance rule. |
| [`forecast`](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/forecast.md) | Did a prediction, written down before the outcome was known, beat simple baselines? It records, seals and scores, and claims no forecasting skill. | A forecast you declare before the run, and the outcome once it is known. |

Each command prints text on a terminal and a JSON envelope when its output is piped. Each ends with an exit code that means the same thing everywhere: 0 when the work completed and any decision it was asked for qualified, 1 for rejected, 2 for unresolved. The [error pages](https://github.com/reward-lens/reward-lens/blob/main/docs/errors/README.md) list the other codes, and `reward-lens explain` prints what any of them means and what to do about it.

## What the first audit found

<!-- first-run -->
```bash
reward-lens init --example code-reward demo   # exit 0
reward-lens audit demo                        # exit 2: unresolved
reward-lens explain RL0201                    # exit 0
```

`init` writes `demo/`: the grader (`grader.py`, tests passed plus a format term), 40 code tasks, 120 replies sampled from a small model, and a protected test suite under `outcome/` that serves as the independent check. The audit took 20 to 31 seconds on a laptop. Its screen ends with the finding and the verdict:

```text
  This reward reads a file the graded process can write.
  ...
  Verdict   unresolved   ·   under stock-audit-v1
  ...
            Exit code 2. To decide under another policy: --policy FILE.
            Unresolved is a verdict. It is not a pass and it is not a failure.
```

The grader runs its tests from `outcome/`, and that folder sits inside the directory the graded code runs in, so a reply could rewrite the tests that judge it. The audit read this in the grader's code (finding RL0201) and filed it as needing review, because it did not confirm it by running a reply that does so. With no `--policy`, the stock policy `stock-audit-v1` decides, and under it only a confirmed finding rejects.

The record (`*.assay.json`) and the report (`*.assay.html`) are in `demo/assays/`. The report is one file of about 500 KB that opens in any browser, with no install and no network.

## A grader bug that shipped: the Countdown example

The second example is the Countdown scorer described at the top, as it stood before its fix. The project holds that grader, the fixed one, 60 tasks, 607 replies marked right or wrong, and the first 30 steps of a training run on the grader before the fix. `trace` needs the `trace` extra (`python -m pip install "reward-lens[trace]==3.2.0"`).

<!-- first-run -->
```bash
reward-lens init --example countdown countdown   # exit 0
reward-lens audit countdown                      # exit 1: rejected
reward-lens compare before-fix fixed --rung 1 --bank countdown/bank.jsonl --project countdown   # exit 0
reward-lens trace countdown/run-record --out countdown/trace   # exit 0
```

`audit` rejects the grader in about a minute, with eleven confirmed findings. Ten are wrong replies the example keeps as controls, one file each in `countdown/outcome/execution_controls/known_wrong/`, and the grader gave each full credit. The eleventh is a right reply whose final answer the audit swapped for another task's, and it still scored 1.0. The audit found this bug through those known-wrong controls. The check that builds wrong replies with no labels to go on filed nothing on this grader.

![The report of the Countdown audit: eleven blocking findings and the verdict rejected.](https://raw.githubusercontent.com/reward-lens/reward-lens/main/.github/assets/report-countdown.png)

`compare` scores the same replies under both graders and prints the difference:

```text
  Comparison  before-fix to fixed  ·  rung 1
              intended task success: -0.518949 [-0.536028, -0.501870] score difference, n 60
```

Over the 60 tasks the fixed grader gives these replies a mean score 0.52 lower. `compare` decides nothing unless you give it a policy, so it exits 0.

`trace` reads the run record, 1,920 rows over 30 steps, and checks the trainer against its own logs: the recorded advantages follow from the recorded rewards on all 30 steps, and the logged loss is rebuilt from per-token terms on the 3 steps that recorded them. The verdict is `qualified`, which says the trainer did what its logs say. It does not say the reward was right. It also cannot say whether training selected for the bug, because this record has no column of whether each reply was right, and the screen reports that as `INCONCLUSIVE_INPUTS`.

`improve` asks whether `grader_fixed.py` is a real fix:

<!-- first-run -->
```bash
reward-lens improve countdown --describe "credit only expressions that use the given numbers" --candidate-source owner_edit --candidate countdown/candidate.json   # exit 0: qualified
```

`candidate.json` names the edit, two explanations of what it changes, and an acceptance rule written before anything is measured. `improve` takes the comparison of the two graders that `compare` wrote above, runs the fixed grader on the 634 replies under `owner/` that the rule names, and returns `qualified` under that rule in about a minute.

## Audit your own grader

You need three files. The grader is any Python file with a `score(task, response)` function that returns a number. This one is `mine/grader.py`:

<!-- first-run file: mine/grader.py -->
```python
def score(task: dict, response: str) -> float:
    """Full credit when the last line of the reply holds the expected number."""
    lines = [line.strip() for line in response.strip().splitlines() if line.strip()]
    return 1.0 if lines and str(task["answer"]) in lines[-1] else 0.0
```

`mine/tasks.jsonl` has one task on each line, with a `task_id` and whatever keys your grader reads:

<!-- first-run file: mine/tasks.jsonl -->
```json
{"task_id": "t1", "prompt": "What is 2 + 3? Give the number on the last line.", "answer": "5"}
```

`mine/responses.jsonl` is the response bank, one reply on each line. `honest` says whether the reply is right. The replies you label wrong are the controls the audit holds the grader to:

<!-- first-run file: mine/responses.jsonl -->
```json
{"response_id": "t1-right", "task_id": "t1", "text": "2 + 3 = 5\n5", "honest": true}
{"response_id": "t1-wrong", "task_id": "t1", "text": "I think it is\n1000", "honest": false}
{"response_id": "t1-hedge", "task_id": "t1", "text": "One of these:\n1 2 3 4 5 6", "honest": false}
```

<!-- first-run -->
```bash
reward-lens audit mine/grader.py --tasks mine/tasks.jsonl --responses mine/responses.jsonl   # exit 1: rejected
```

The audit rejects this grader and prints why. RL0221: it gave full credit to `t1-hedge`, a reply labelled wrong. RL0232: the audit built wrong final answers from the task's own answer (55, -5 and 0.5 among them), the grader gave each one full credit, and the audit reproduced each in a fresh process. Both come from one flaw, `in` where the grader should test for equality. With `lines[-1] == str(task["answer"])` on the last line, no confirmed finding is left and the verdict is `unresolved`, exit 2: a bare grader has no independent check of whether a reply is right, so a plain audit cannot say `qualified`. A row with no `honest` label is left out of the checks, and the audit says how many such rows it saw.

## Inside a learned reward: the research layer

A grader written as code is one kind of reward. Many rewards are learned instead: a reward model, a judge model, the implicit reward of a DPO checkpoint. Reading the source tells you little about those, and the questions move inside the network. Along which direction does the model score? At which layer does it make up its mind? Which components cause a preference, and which only correlate with it?

The rest of the package is a Python library of instruments for those questions: a layer-by-layer readout of the score, attribution, activation patching, bias probes and interventions. It needs the `white-box` extra (`python -m pip install "reward-lens[white-box]==3.2.0"`). This example builds a miniature reward model with random weights on CPU and measures it:

```python
from reward_lens.signals import from_tiny
from reward_lens.measure import base as mb
from reward_lens.measure.battery import DirectLinearAttribution
from reward_lens.data.builtin.diagnostic_v3 import load_diagnostic_v3
from reward_lens.data.schema import DataView

signal = from_tiny(seed=0)
view = DataView(list(load_diagnostic_v3()["helpfulness"].items)[:8])

ev = mb.run(DirectLinearAttribution(), mb.Context(signal=signal, view=view))
print(ev.value["dominant_component"])   # which components wrote the reward difference
print(ev.trust)                         # EXPLORATORY
```

The last line is the one to notice. A measurement comes back as evidence with a trust level attached, and the library computes that level instead of letting the caller claim it: a result stays `EXPLORATORY` until its instrument has been scored against a model whose answer is known. In this release every instrument reports `EXPLORATORY`. The layer is experimental, it was checked on real weights in one narrow way (the attribution terms of one small reward model sum to its score), and the Skywork and ArmoRM results in the documentation come from earlier builds.

[Measurement you can trust](https://github.com/reward-lens/reward-lens/blob/main/docs/content/concepts/measurement-you-can-trust.md) explains the trust levels, the [instrument pages](https://github.com/reward-lens/reward-lens/blob/main/docs/content/instruments/index.md) cover each tool with its math and when not to use it, and the [guided tour](https://colab.research.google.com/drive/1x5zG07HdsWlNsJmkl2ddJ1yalmwwujfY?usp=sharing) runs the library in a browser.

## What comes with it

- Every command writes its result as a JSON record under a published schema, and the same record renders as a one-file HTML report. `reward-lens open` shows a report, and with `--workbench` it serves the record in a local workbench.
- Grader code runs contained, with the network denied: inside bubblewrap, or under Landlock with a seccomp filter, on Linux, and under `sandbox-exec` on macOS. On a machine that cannot contain a grader the audit refuses before the first grader call, and in this release that is every Windows machine. `reward-lens doctor` prints what yours can do. CI runs on Linux only.
- `TRLTap` records a TRL `GRPOTrainer` run in the form `trace` reads. The [trace page](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/trace.md) shows the code.
- [`action.yml`](https://github.com/reward-lens/reward-lens/blob/main/action.yml) is a GitHub Action that audits a reward under a policy file and saves the findings as SARIF for code scanning. It expects reward-lens to be installed in the job already.
- `reward-lens mcp` serves the commands to an agent over the Model Context Protocol. Needs the `mcp` extra.
- Each of the 79 documented error codes has a cause and a remedy, and `reward-lens explain` prints them offline.

## What this release has not shown

No measurement of how often the audit is right on graders it had never seen was made for 3.2.0. The closest thing is a set of 18 graders used while building it: the default audit confirmed a finding on 6 of the 8 defective graders and on 2 of the 10 clean ones. Because the set shaped the tool, those counts are not an accuracy figure.

reward-lens 3.2.0 audits Python graders. Adapters for other kinds of grader (a judge model, a neural reward model, a remote service) have run on fixtures only. No forecasting method here has beaten the base-rate rule on a test registered in advance. [Known limits](https://github.com/reward-lens/reward-lens/blob/main/docs/content/caveats.md) lists what was run on real inputs, what is experimental and what is known wrong, and the [changelog](https://github.com/reward-lens/reward-lens/blob/main/CHANGELOG.md) lists every change to results and interfaces since the previous release.

## Install

Version 3.2.0 is on [PyPI](https://pypi.org/project/reward-lens/3.2.0/) and in the [GitHub release](https://github.com/reward-lens/reward-lens/releases/tag/v3.2.0).

```bash
python -m pip install reward-lens==3.2.0
```

Python `3.11` or newer is required, and CI covers 3.11 to 3.13 on Linux. The base install is small: the command line, records, static analysis and offline signatures, with no NumPy, torch or Node. Extras add what a task needs, and the [installation page](https://github.com/reward-lens/reward-lens/blob/main/docs/content/getting-started/install.md) lists all of them. The import name is `reward_lens`, and `rlens` is a short alias for the command. To install from a checkout, run `python -m pip install .` in it.

## Docs, help and contributing

- The documentation is at [reward-lens.github.io](https://reward-lens.github.io), and its source is under [`docs/content`](https://github.com/reward-lens/reward-lens/blob/main/docs/content/index.md). [Getting started](https://github.com/reward-lens/reward-lens/blob/main/docs/content/getting-started/index.md) and the [command pages](https://github.com/reward-lens/reward-lens/blob/main/docs/content/commands/index.md) are the places to go from here.
- Questions and bug reports go to the [issue tracker](https://github.com/reward-lens/reward-lens/issues). A report is easiest to act on with the output of `reward-lens --version`, your Python and OS, and the command that went wrong.
- A security problem, such as grader code getting out of its sandbox, should be reported privately. [SECURITY.md](https://github.com/reward-lens/reward-lens/blob/main/SECURITY.md) says how.
- To work on the code, `uv sync --group dev` installs the development group. [CONTRIBUTING.md](https://github.com/reward-lens/reward-lens/blob/main/CONTRIBUTING.md) and [TEST_STATUS.md](https://github.com/reward-lens/reward-lens/blob/main/TEST_STATUS.md) say which checks to run.
- If reward-lens contributes to published work, cite the version you ran. [CITATION.cff](https://github.com/reward-lens/reward-lens/blob/main/CITATION.cff) holds the entry, and GitHub's "Cite this repository" button reads it.
- The history of this repository was assembled from reviewed work before publication. [Publication history](https://github.com/reward-lens/reward-lens/blob/main/docs/publication-history.md) says what its commit dates do and do not mean.

reward-lens is released under the [MIT license](https://github.com/reward-lens/reward-lens/blob/main/LICENSE).
