rhscope.hub

Hugging Face Hub helpers for probe artifacts.

A probe artifact is two sibling files: probe.safetensors + probe.json. When published to the Hub, rhscope expects both files at the repo root under these canonical names, so loading a probe is identical regardless of whether it comes from a local path or a remote repo.

The public surface here is:

resolve_probe_stem(path_or_hub_id) -> Path # local or Hub -> local stem push_probe_to_hub(stem, repo_id) -> str # upload a local probe

rhscope.hub.PROBE_SAFETENSORS_FILENAME = 'probe.safetensors'

Canonical filename for the probe weights when stored on the Hub.

rhscope.hub.PROBE_METADATA_FILENAME = 'probe.json'

Canonical filename for the probe metadata when stored on the Hub.

rhscope.hub.resolve_probe_stem(path_or_hub_id, *, revision=None, cache_dir=None)[source]

Resolve a local stem or a Hugging Face Hub repo ID to a local stem.

Parameters:
  • path_or_hub_id (str | Path) – Either a local probe stem (with or without a .safetensors / .json suffix) or a Hub repo ID of the form "user-or-org/repo".

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

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

Returns:

A local filesystem path (without extension) suitable for rhscope.io.load_probe().

Raises:
  • FileNotFoundError – If path_or_hub_id is not a local probe stem and the corresponding Hub repo is unavailable.

  • RuntimeError – If huggingface_hub is not installed.

Return type:

Path

rhscope.hub.push_probe_to_hub(stem, repo_id, *, private=False, commit_message=None, token=None)[source]

Upload a local probe artifact to Hugging Face Hub.

Creates the repo if it does not already exist. Uploads the probe’s safetensors + metadata files under their canonical filenames so the probe is loadable by resolve_probe_stem().

Parameters:
  • stem (str | Path) – Local probe stem (or path with a .safetensors / .json suffix); the sibling files are both uploaded.

  • repo_id (str) – Target repo, e.g. "your-user/qwen3-1.5b-code_shortcut".

  • private (bool) – Create the repo as private if it doesn’t already exist.

  • commit_message (str | None) – Commit message. Defaults to a summary pulled from the probe’s metadata.

  • token (str | None) – Hub auth token. Defaults to the HF_TOKEN environment variable or the user’s cached login.

Returns:

The Hub URL of the uploaded repo.

Raises:
Return type:

str

rhscope.hub.read_hub_metadata(path_or_hub_id, *, revision=None)[source]

Peek at a probe’s metadata without downloading the weight tensors.

Useful for validation / discovery UIs that want to display a probe’s base model, category, and val AUROC before committing to downloading it.

Parameters:
  • path_or_hub_id (str | Path)

  • revision (str | None)

Return type:

ProbeMetadata