Skip to content

Io

I/O utilities: saving and loading Murano results.

def save_steering(steering_result: Any, path: Path) -> None:

Save a SteeringResult to a .pt file.

Args:

  • steering_result: SteeringResult to serialize.
  • path: Output path. Parent directory is created if missing.
def load_steering(path: str | Path) -> Any:

Load a SteeringResult from a .pt file.

Args:

  • path: Path to the steering.pt file.

Returns:

  • SteeringResult ready for use with model.generate(ablate=…).
def save_generations(intervene_result: Any, path: Path, prompts: list[str] | None = None) -> None:

Save an InterveneResult to a JSON file, paired per prompt.

Args:

  • intervene_result: GenerationComparison-compatible artifact with
  • clean_generations and modified_generations lists.
  • path: Output path for the JSON file. Parent directory is created
  • if missing.
  • prompts: Prompts to pair each entry with. Falls back to
  • intervene_result.prompts when None.
def save_metric_comparison(eval_result: Any, path: Path) -> None:

Save a MetricComparison to a JSON file.

Args:

  • eval_result: MetricComparison to serialize.
  • path: Output path. Parent directory is created if missing.
def save_metric_score(evaluation: MetricScore, path: Path) -> None:

Save a MetricScore (scalar forward-pass metric) to JSON.

Args:

  • evaluation: The MetricScore to serialize.
  • path: Output path. Parent directory is created if missing.
def load_metric_score(path: str | Path) -> MetricScore:

Load a MetricScore from a file written by :func:save_metric_score.

Args:

  • path: Path to the JSON file.

Returns:

  • The reconstructed MetricScore.
def save_ablated_model(model: ModelBackend, save_dir: str | Path) -> Path:

Save the current (ablated) model weights in HF format.

Saves model weights and tokenizer so the ablated model can be reloaded with transformers or MuranoModel.

Args:

  • model: MuranoModel with ablated weights (call after ablate_model_weights).
  • save_dir: Directory to save the model.

Returns:

  • Path to the saved model directory.
def save_probe(probe_result: Any, path: Path) -> None:

Save a ProbeResult to a JSON file (without classifiers).

Fitted classifier objects are not serialized; only per-layer accuracy, CV scores, and metadata are persisted.

Args:

  • probe_result: ProbeResult to serialize.
  • path: Output path. Parent directory is created if missing.
def save_logit_lens(logit_lens_result: Any, path: Path) -> None:

Save a LogitLensResult to a .pt file.

Persists every field on the dataclass. Per-layer probability tensors, argmax tokens, decoded words, input words, attention mask, and component addresses, so the result can be reloaded for downstream plotting or analysis without re-running the trace.

Args:

  • logit_lens_result: LogitLensResult to serialize.
  • path: Output path. Parent directory is created if missing.
def load_logit_lens(path: str | Path) -> Any:

Load a LogitLensResult from a .pt file.

Args:

  • path: Path to the logit_lens.pt file.

Returns:

  • LogitLensResult reconstructed from the saved tensors and lists,
  • ready for downstream plotting or analysis.
def save_attention(result: Any, path: Path) -> None:

Save an AttentionResult to a .pt file.

Persists every captured layer’s attention weights along with the mask, decoded tokens, layer indices, addresses, and metadata, so the reductions and pattern plots can run without re-tracing the model.

Args:

  • result: AttentionResult to serialize.
  • path: Output path. Parent directory is created if missing.
def load_attention(path: str | Path) -> Any:

Load an AttentionResult from a file written by :func:save_attention.

Args:

  • path: Path to the attention.pt file.

Returns:

  • AttentionResult with its captured patterns and metadata.
def save_logit_attribution(result: Any, path: Path) -> None:

Save a LogitAttributionResult to a JSON file.

Component contributions are keyed by their string address; the loader coerces them back to Node objects.

Args:

  • result: LogitAttributionResult to serialize.
  • path: Output path. Parent directory is created if missing.
def load_logit_attribution(path: str | Path) -> Any:

Load a LogitAttributionResult from a file written by :func:save_logit_attribution.

Args:

  • path: Path to the logit_attribution.json file.

Returns:

  • LogitAttributionResult with string addresses coerced back to Node keys.
def save_component_selection(selection: Any, path: Path) -> None:

Save a ComponentSelection to a JSON file.

Nodes and score keys are stored by their string address; the loader coerces them back to Node objects.

Args:

  • selection: ComponentSelection to serialize.
  • path: Output path. Parent directory is created if missing.
def load_component_selection(path: str | Path) -> Any:

Load a ComponentSelection from a file written by :func:save_component_selection.

Args:

  • path: Path to the selection.json file.

Returns:

  • ComponentSelection with string addresses coerced back to Node keys.
def save_sweep_result(sweep: Any, path: Path) -> None:

Save a SweepResult to a JSON file.

Swept items are stored by their string form, alongside the flag that says whether they were Node addresses, so the loader can rebuild a component sweep’s Node keys and leave any other sweep’s labels as plain strings.

Args:

  • sweep: SweepResult to serialize.
  • path: Output path. Parent directory is created if missing.
def load_sweep_result(path: str | Path) -> Any:

Load a SweepResult from a file written by :func:save_sweep_result.

Args:

  • path: Path to the sweep.json file.

Returns:

  • SweepResult. A component sweep’s item keys are coerced back to Node
  • objects; every other sweep keeps its string labels, because the original
  • item type (an int layer index, an ablation method name) is not recoverable
  • from the label and the scores do not depend on it.
def save_activation_store(activation_store: Any, path: Path) -> None:

Save an ActivationStore to a .pt file.

Interim on-disk format; the layout may change.

Args:

  • activation_store: ActivationStore to serialize.
  • path: Output path. Parent directory is created if missing.
def load_activation_store(path: str | Path) -> Any:

Load an ActivationStore from a .pt file.

Args:

  • path: Path to the saved activation-store .pt file.

Returns:

  • ActivationStore with positive and negative activation dicts.
def save_labeled_activation_store(labeled_store: Any, path: Path) -> None:

Save a LabeledActivationStore to a .pt file.

Interim on-disk format; the layout may change.

Args:

  • labeled_store: LabeledActivationStore to serialize.
  • path: Output path. Parent directory is created if missing.
def load_labeled_activation_store(path: str | Path) -> Any:

Load a LabeledActivationStore from a .pt file.

Args:

  • path: Path to the saved labeled-activation-store .pt file.

Returns:

  • LabeledActivationStore with activations dict and labels tensor.
def save_sae_activations(sae_store: Any, path: Path) -> None:

Save an SAEActivationStore to a .pt file.

Args:

  • sae_store: SAEActivationStore to serialize.
  • path: Output path. Parent directory is created if missing.
def load_sae_activations(path: str | Path) -> Any:

Load an SAEActivationStore from a .pt file.

Args:

  • path: Path to the sae_record.pt file.

Returns:

  • SAEActivationStore ready for downstream steps (SAETopActivations etc.).
def save_sae_examples(feature_examples: Any, path: Path) -> None:

Save an SAEFeatureExamples to a JSON file.

Integer feat_id keys are stringified on save (JSON requires string keys); :func:load_sae_examples casts them back.

Args:

  • feature_examples: SAEFeatureExamples to serialize.
  • path: Output path. Parent directory is created if missing.
def load_sae_examples(path: str | Path) -> Any:

Load an SAEFeatureExamples from a JSON file.

Stringified feat_id keys produced by :func:save_sae_examples are cast back to int.

Args:

  • path: Path to the feature_examples.json file.

Returns:

  • SAEFeatureExamples reconstructed from the JSON payload.
def save_sae_labels(feature_labels: Any, path: Path) -> None:

Save an SAEFeatureLabels to a JSON file.

Integer feat_id keys are stringified on save (JSON requires string keys); :func:load_sae_labels casts them back.

Args:

  • feature_labels: SAEFeatureLabels to serialize.
  • path: Output path. Parent directory is created if missing.
def load_sae_labels(path: str | Path) -> Any:

Load an SAEFeatureLabels from a JSON file.

Stringified feat_id keys produced by :func:save_sae_labels are cast back to int.

Args:

  • path: Path to the feature_labels.json file.

Returns:

  • SAEFeatureLabels reconstructed from the JSON payload.
def save_prompts(prompt_batch: PromptBatch, path: Path) -> None:

Save a PromptBatch to JSON.

Args:

  • prompt_batch: Prompts plus optional raw versions and metadata.
  • path: Output path. Parent directory is created if missing.
def save_metadata(metadata: dict, path: Path) -> None:

Save pipeline metadata to a JSON file.

murano_version and timestamp keys are filled in if absent.

Args:

  • metadata: Metadata dict to serialize. Mutated in place to add the
  • two default keys above.
  • path: Output path for the JSON file.
def register_artifact_serializer(registry: list[tuple[type, ArtifactSerializer]], artifact_type: type, serializer: ArtifactSerializer) -> None:

Append a (type, serializer) pair to a serializer registry.

Used by the Save step to dispatch each result-dict value to the right serializer based on its type.

Args:

  • registry: Mutable list of (type, serializer) pairs.
  • artifact_type: Class to dispatch on. isinstance is used at lookup
  • time, so subclasses match.
  • serializer: Callable that writes the artifact to disk. Signature:
  • (key, artifact, out_dir, results, metadata) -> None.
def save_results(results: Any, output_dir: str = keys.DEFAULT_OUTPUT_DIR, model_id: str = '', run_name: str | None = None) -> Path:

Save all available results to organized subdirectories.

Output structure: output_dir/ ├── direction/ # steering vectors │ └── steering.pt ├── evaluation/ # generations │ └── generations.json ├── logit_lens/ # logit-lens probabilities + decoded words │ └── logit_lens.pt ├── attention/ # captured per-head attention weights │ └── attention.pt ├── activations/ # recorded activation stores (transitional format) │ └── record.pt ├── sae/ # SAE activations + per-feature examples │ ├── sae_record.pt │ └── feature_examples.json └── metadata.json

Args:

  • results: Results object from a pipeline run.
  • output_dir: Base directory for outputs.
  • model_id: HuggingFace model identifier (e.g. “meta-llama/Llama-3.2-1B-Instruct”).
  • run_name: Optional subdirectory name inside output_dir.

Returns:

  • Path to the output directory.