rhscope.monitor¶
User-facing monitor object.
HackMonitor wraps a trained Probe
with the base model it was trained on, providing the score_batch
surface the integrations (TRL, verl, DPO) consume. Everything downstream
goes through score_batch(prompts, responses).
Two load paths:
HackMonitor.from_probe()wraps a probe object you already hold.HackMonitor.from_pretrained()resolves a local stem or a Hugging Face Hub repo id, then loads the probe + its base model for you.
HackMonitor is deliberately tied to probes. If you want to compose
with a custom detector (an external judge, a rule you wrote, another
team’s probe), use CompositeDetector or wrap
your callable in CallableDetector - those
compose with the probe detector at the same level.
Example:
from rhscope import HackMonitor
monitor = HackMonitor.from_pretrained("my-org/my-probe")
scores = monitor.score_batch(prompts, completions)
- class rhscope.monitor.HackMonitor(detector, *, threshold=0.0)[source]¶
Bases:
objectA trained probe plus the base model it reads activations from.
- Parameters:
detector (Detector) – Typically a
ProbeDetector. Any otherDetectoralso works (aCompositeDetectorover several probes, say) but the probe-specific accessors (base_model,layer,pooling,score,require_base_model) will raiseAttributeError.threshold (float) – Score threshold for
predict()/predict_batch(). Probe scores sit on either side of zero after DoM / logistic training;0.0is the default.
- classmethod from_probe(probe, model, tokenizer, *, batch_size=8, max_length=1024, threshold=0.0)[source]¶
Wrap an already-loaded
Probe+ its base model as a monitor.Prefer
from_pretrained()when loading from disk / Hub.
- classmethod from_pretrained(path_or_hub_id, *, model=None, tokenizer=None, model_name_or_path=None, threshold=0.0, revision=None, cache_dir=None, device=None, dtype=torch.float32, trust_remote_code=False, batch_size=8, max_length=1024)[source]¶
Load a trained probe + its base model and wrap them as a monitor.
- Parameters:
path_or_hub_id (str | Path) – Local probe stem or Hugging Face Hub repo ID.
model (Any) – Optional pre-loaded policy model to probe. If omitted, the probe’s own
base_modelmetadata is loaded unlessmodel_name_or_pathoverrides it.tokenizer (Any) – Required when
modelis provided.model_name_or_path (str | None) – Override the model to load; default is the probe’s recorded
base_model. Overriding is allowed but emits a warning - probes rarely generalize across models.max_length (int) – Policy-model load + probe-scoring controls.
revision (str | None)
cache_dir
dtype (dtype)
trust_remote_code (bool)
batch_size (int)
max_length
- Returns:
A
HackMonitorwrapping aProbeDetector.- Return type:
- property requires_base_model: str | None¶
Return the base model this monitor is bound to, or
None.Probe-backed monitors return the probe’s recorded
base_model. Non-probe monitors (a user-suppliedCompositeDetectororCallableDetector) returnNonesince we cannot know their binding.
- score_batch(prompts, responses)[source]¶
Score a batch of
(prompt, response)pairs. Higher = more hack-like.
- property metadata: ProbeMetadata¶
Probe metadata (probe-backed monitors only).
- property pooling: Literal['last_token', 'mean', 'max']¶
Pooling strategy the probe uses (probe monitors only).
Expected hidden-state dim (probe monitors only).
- score(activations)[source]¶
Low-level activation scoring (probe-backed monitors only).
Equivalent to
monitor.probe.score(activations). Preferscore_batch()for most code - it handles the activation forward pass internally.
- require_base_model(model_name_or_path, *, strict=True)[source]¶
Verify the monitor is applicable to
model_name_or_path.Probe-backed monitors check
probe.metadata.base_model. Mismatches raiseValueErrorby default (setstrict=Falseto warn instead). Non-probe monitors are a no-op since we cannot reason about their binding.