rhscope.probes.online¶
Streaming DoM probe fit incrementally with partial_fit() updates.
The standard DoMProbe is trained once on a
labelled dataset and then held frozen for monitoring. OnlineProbe
is the streaming counterpart: it maintains running means over hack and
clean activations across many partial_fit calls, so it can be refit
every eval step during a long RL run without re-materialising the full
activation matrix.
Use cases:
Live monitoring of a policy whose distribution drifts during training.
Feeding the running direction to
EvasionDetectoras the “current” direction at every step.Ablations that need to roll the probe forward one batch at a time.
Mathematically equivalent to a plain DoM probe refit on every sample
seen so far (no forgetting factor). Serialisation goes through the same
SafeTensors + JSON-sidecar path as every other probe; snapshot(...)
is a convenience that returns a plain DoMProbe with the same
direction for callers that want the simpler object.
Example:
from rhscope import OnlineProbe
probe = OnlineProbe.empty(
base_model="Qwen/Qwen3-1.5B",
hidden_dim=1536,
layer=14,
)
for step in training_loop:
hack_acts, clean_acts = collect_fresh_activations(step)
probe.partial_fit(hack_acts, clean_acts)
probe.save("my-online-probe") # SafeTensors + JSON round-trip
snapshot = probe.snapshot() # or get a plain DoMProbe
- class rhscope.probes.online.OnlineProbe(metadata)[source]¶
Bases:
ProbeDoM-style probe fit incrementally through
partial_fit().Maintains per-class running means plus their counts. The probe direction is the normalised difference of the two means, recomputed on demand.
- Parameters:
metadata (ProbeMetadata) – Standard
ProbeMetadata;probe_typemust be"online_dom". Useempty()if you only have a base-model name and hidden dim.
- classmethod empty(*, base_model, hidden_dim, layer=0, pooling='last_token', category='general')[source]¶
Build an unfit online probe with sensible default metadata.
- property direction: Tensor¶
Normalised
mean_hack - mean_cleanas a 1-D float64 tensor.- Raises:
RuntimeError – Before any successful
partial_fit()call.
- fit(hack_activations, clean_activations)[source]¶
Reset running state and fit on one batch.
Equivalent to
reset()followed bypartial_fit(). Preferpartial_fit()directly for streaming use.
- partial_fit(hack_activations, clean_activations)[source]¶
Update running means with a fresh batch.
Either argument may be
Noneor empty if a step only produces one class. A step with nothing is a no-op.- Raises:
ValueError – On shape or dim mismatch.
- Parameters:
- Return type:
None
- snapshot()[source]¶
Freeze the current direction into a plain
DoMProbe.Useful when downstream code expects the simpler probe (for example, as the anchor for
EvasionDetector) or when you want to publish a one-shot artifact without the running-state metadata.- Return type: