rhscope.io

Low-level I/O for probe artifacts.

A probe artifact is two sibling files:

foo.safetensors - tensor weights (SafeTensors format) foo.json - ProbeMetadata serialized as JSON

Users should normally call Probe.save / Probe.load from rhscope.probes.base instead of these helpers directly. The separation lets us round-trip raw tensor dicts in tests and makes the on-disk format trivially inspectable (SafeTensors is well-supported; JSON is plain text).

rhscope.io.save_probe(stem, tensors, metadata)[source]

Save a probe’s tensors and metadata to disk.

Parameters:
  • stem (str | Path) – Target path without extension (or ending in .safetensors); two files are written sharing this stem.

  • tensors (dict[str, Tensor]) – Dict of named tensors comprising the probe’s state. Must be non-empty; all tensors are moved to CPU and converted to contiguous memory before writing.

  • metadata (ProbeMetadata) – Validated ProbeMetadata instance to serialize alongside.

Returns:

A (safetensors_path, json_path) tuple of the files written.

Raises:

ValueError – If tensors is empty.

Return type:

tuple[Path, Path]

rhscope.io.load_probe(stem)[source]

Load a probe’s tensors and metadata from disk.

Parameters:

stem (str | Path) – Path matching the one passed to save_probe; accepts a bare stem, a .safetensors path, or a .json path.

Returns:

A (tensors, metadata) tuple.

Raises:

FileNotFoundError – If either sibling file is missing.

Return type:

tuple[dict[str, Tensor], ProbeMetadata]