rhscope.bench.leaderboard¶
Multi-probe benchmark runner.
Scoring a single probe against a bench is the job of
RHDetectBench.evaluate(); running the same bench against many probes
- as happens when reporting a probe-grid result - introduces two concerns
that a single-probe runner does not need to solve:
Model sharing. Probes trained on the same base model should share the loaded model so we do not re-download and re-initialize for every probe. Doing so is both slow and would exhaust VRAM on any memory-constrained GPU.
Comparable output. A reviewer should be able to read a single markdown table that ranks probes head-to-head with identical benchmark settings.
Leaderboard is the result object; run_probe_leaderboard() is
the driver.
- class rhscope.bench.leaderboard.LeaderboardEntry(name, probe_source, result)[source]¶
Bases:
objectOne probe’s evaluation on the shared bench.
- Variables:
name (str) – Display name used in the leaderboard table. Usually the
<base_model>/<category>slug.probe_source (str) – Local stem or Hub ID the probe was loaded from.
result (rhscope.bench.result.BenchResult) – The full
BenchResult.
- Parameters:
name (str)
probe_source (str)
result (BenchResult)
- result: BenchResult¶
- class rhscope.bench.leaderboard.Leaderboard(entries=<factory>, dataset_name='', dataset_version='')[source]¶
Bases:
objectCollection of
LeaderboardEntrywith rendering helpers.Entries are kept in the order they were added;
sorted_by()returns a new leaderboard sorted by any numeric field ofBenchResult.- Parameters:
entries (list[LeaderboardEntry])
dataset_name (str)
dataset_version (str)
- entries: list[LeaderboardEntry]¶
- add(entry)[source]¶
Append
entryto the leaderboard in place.- Parameters:
entry (LeaderboardEntry)
- Return type:
None
- sorted_by(key='pooled_auroc', *, descending=True)[source]¶
Return a new
Leaderboardsorted by a numeric result field.- Parameters:
- Return type:
- class rhscope.bench.leaderboard.ProbeHandle(name, probe, source, base_model_override=None)[source]¶
Bases:
objectPair a probe with the base-model identifier it should be scored on.
The model identifier is used to batch probes sharing the same base model so each model is loaded at most once during a leaderboard run.
- rhscope.bench.leaderboard.run_probe_leaderboard(probes, bench, *, model_loader, limit=None, batch_size=8, max_length=1024)[source]¶
Evaluate every probe in
probesagainstbench.Probes sharing the same base model are grouped so the model is loaded exactly once per unique base model.
- Parameters:
probes (Iterable[ProbeHandle]) – Iterable of
ProbeHandle.bench (RHDetectBench) – The benchmark to evaluate on.
model_loader (Any) – Callable
(model_name_or_path) -> (model, tokenizer). Typicallyrhscope.training.trainer.load_model_for_probing(); the indirection lets tests pass a mock.limit (int | None) – Optional cap on examples per probe.
batch_size (int) – Mini-batch size for activation extraction.
max_length (int) – Token truncation length.
- Returns:
Leaderboardwith one entry per probe, in input order.- Return type:
- rhscope.bench.leaderboard.monitors_to_handles(monitors, *, sources=None)[source]¶
Convenience: turn a
{name: HackMonitor}mapping into probe handles.Only probe-backed monitors can be turned into leaderboard handles - heuristic and judge monitors have no activation-level
Probeto pass through. Non-probe monitors raiseTypeError.- Parameters:
monitors (Mapping[str, HackMonitor]) – Named monitors; the key becomes the leaderboard entry name.
sources (Mapping[str, str] | None) – Optional mapping of the same names to source paths (local stem or Hub ID) for provenance display. Defaults to
"local".
- Return type: