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:

  1. 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.

  2. 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: object

One 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
class rhscope.bench.leaderboard.Leaderboard(entries=<factory>, dataset_name='', dataset_version='')[source]

Bases: object

Collection of LeaderboardEntry with rendering helpers.

Entries are kept in the order they were added; sorted_by() returns a new leaderboard sorted by any numeric field of BenchResult.

Parameters:
entries: list[LeaderboardEntry]
dataset_name: str = ''
dataset_version: str = ''
add(entry)[source]

Append entry to the leaderboard in place.

Parameters:

entry (LeaderboardEntry)

Return type:

None

sorted_by(key='pooled_auroc', *, descending=True)[source]

Return a new Leaderboard sorted by a numeric result field.

Parameters:
  • key (str) – Attribute of BenchResult to sort on.

  • descending (bool) – Sort order. Defaults to descending (best first).

Return type:

Leaderboard

to_dict()[source]

Return a JSON-serializable dict representation of the leaderboard.

Return type:

dict[str, Any]

to_json(*, indent=2)[source]

Return the leaderboard as a JSON string.

Parameters:

indent (int | None)

Return type:

str

save_json(path, *, indent=2)[source]

Write the leaderboard JSON to path and return the resolved Path.

Parameters:
Return type:

Path

summary()[source]

Render the leaderboard as a markdown ranking table.

Return type:

str

save_summary(path)[source]

Write the markdown summary to path and return the resolved Path.

Parameters:

path (str | Path)

Return type:

Path

class rhscope.bench.leaderboard.ProbeHandle(name, probe, source, base_model_override=None)[source]

Bases: object

Pair 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.

Parameters:
  • name (str)

  • probe (Probe)

  • source (str)

  • base_model_override (str | None)

name: str
probe: Probe
source: str
base_model_override: str | None = None
property base_model: str

Effective base-model identifier (override if set, else from metadata).

rhscope.bench.leaderboard.run_probe_leaderboard(probes, bench, *, model_loader, limit=None, batch_size=8, max_length=1024)[source]

Evaluate every probe in probes against bench.

Probes sharing the same base model are grouped so the model is loaded exactly once per unique base model.

Parameters:
Returns:

Leaderboard with one entry per probe, in input order.

Return type:

Leaderboard

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 Probe to pass through. Non-probe monitors raise TypeError.

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:

list[ProbeHandle]