rhscope.probes.base

Abstract base class for reward-hacking probes.

All concrete probes (DoMProbe, LogisticProbe, …) subclass Probe and set a class-level probe_type discriminator. Subclasses implement five .. method:: fit(hack_activations, clean_activations) -> None

rhscope.probes.base.score(activations) → torch.Tensor
rhscope.probes.base.state_dict() → dict[str, torch.Tensor]
rhscope.probes.base._load_state_dict(state) → None
rhscope.probes.base._construct(metadata) → 'Probe'

With those in place, save and load are handled by this base class via the SafeTensors + JSON format from rhscope.io.

class rhscope.probes.base.Probe(metadata)[source]

Bases: ABC

Abstract base class for reward-hacking probes.

Subclasses must set probe_type at the class level and implement the five abstract methods. Serialization is provided by this base.

Example subclass skeleton:

class MyProbe(Probe):
    probe_type = "my_probe"

    def fit(self, hack, clean): ...
    def score(self, x): ...
    def state_dict(self): ...
    def _load_state_dict(self, state): ...

    @classmethod
    def _construct(cls, metadata):
        return cls(metadata=metadata)
Parameters:

metadata (ProbeMetadata)

probe_type: ClassVar[str] = ''
property metadata: ProbeMetadata

Read-only reference to the probe’s metadata.

abstractmethod fit(hack_activations, clean_activations)[source]

Fit the probe on hack-labeled and clean-labeled activations.

Parameters:
  • hack_activations (Tensor) – Tensor of shape (N_hack, hidden_dim).

  • clean_activations (Tensor) – Tensor of shape (N_clean, hidden_dim).

Return type:

None

abstractmethod score(activations)[source]

Score activations by likelihood of reward hacking.

Parameters:

activations (Tensor) – Tensor of shape (N, hidden_dim) or (hidden_dim,).

Returns:

Tensor of shape (N,) (or scalar for 1-D input) where higher values indicate stronger hacking signal. Scale is probe-specific and may not be a calibrated probability.

Return type:

Tensor

abstractmethod state_dict()[source]

Return the probe’s learned parameters for serialization.

Returns:

Mapping from parameter name to tensor. Tensors should be on CPU or will be moved there at save time.

Return type:

dict[str, Tensor]

save(stem)[source]

Serialize the probe to a stem shared with a sibling metadata file.

Parameters:

stem (str | Path) – Target path without extension; writes <stem>.safetensors and <stem>.json.

Returns:

Tuple of (safetensors_path, json_path).

Return type:

tuple[Path, Path]

classmethod load(stem)[source]

Load a probe artifact from a local stem, dispatching to the correct subclass.

Parameters:

stem (str | Path) – Path matching the one passed to save.

Returns:

A fully populated probe instance of the class registered against metadata.probe_type.

Raises:

KeyError – If the saved probe_type is not registered. This usually means the relevant concrete probe module was not imported before the load call.

Return type:

Probe

classmethod from_pretrained(path_or_hub_id, *, revision=None, cache_dir=None)[source]

Load a probe from a local stem or a Hugging Face Hub repo.

Equivalent to load() when path_or_hub_id refers to a local stem, and to a Hub download followed by load() otherwise. Pair with HackMonitor for the full monitoring surface (threshold, base-model safety checks).

Parameters:
  • path_or_hub_id (str | Path) – Either a local probe stem (with or without a .safetensors / .json suffix) or a Hub repo ID such as "<org>/<name>".

  • revision (str | None) – Optional Hub revision for reproducibility.

  • cache_dir (str | Path | None) – Optional override for the Hugging Face cache location.

Returns:

A fully populated probe instance.

Return type:

Probe

classmethod registered_types()[source]

Return the sorted list of currently-registered probe_type values.

Useful for CLI help and for users writing plug-in probes: after importing the module that defines a new subclass, that subclass’s probe_type will appear here.

Return type:

list[str]