Io
I/O utilities: saving and loading Murano results.
save_steering
Section titled “save_steering”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.
load_steering
Section titled “load_steering”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=…).
save_generations
Section titled “save_generations”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 withclean_generationsandmodified_generationslists.path: Output path for the JSON file. Parent directory is created- if missing.
prompts: Prompts to pair each entry with. Falls back tointervene_result.promptswhen None.
save_metric_comparison
Section titled “save_metric_comparison”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.
save_metric_score
Section titled “save_metric_score”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.
load_metric_score
Section titled “load_metric_score”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.
save_ablated_model
Section titled “save_ablated_model”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.
save_probe
Section titled “save_probe”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.
save_logit_lens
Section titled “save_logit_lens”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.
load_logit_lens
Section titled “load_logit_lens”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.
save_attention
Section titled “save_attention”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.
load_attention
Section titled “load_attention”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.
save_logit_attribution
Section titled “save_logit_attribution”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.
load_logit_attribution
Section titled “load_logit_attribution”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.
save_component_selection
Section titled “save_component_selection”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.
load_component_selection
Section titled “load_component_selection”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.
save_sweep_result
Section titled “save_sweep_result”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.
load_sweep_result
Section titled “load_sweep_result”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.
save_activation_store
Section titled “save_activation_store”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.
load_activation_store
Section titled “load_activation_store”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
positiveandnegativeactivation dicts.
save_labeled_activation_store
Section titled “save_labeled_activation_store”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.
load_labeled_activation_store
Section titled “load_labeled_activation_store”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
activationsdict andlabelstensor.
save_sae_activations
Section titled “save_sae_activations”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.
load_sae_activations
Section titled “load_sae_activations”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.).
save_sae_examples
Section titled “save_sae_examples”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.
load_sae_examples
Section titled “load_sae_examples”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.
save_sae_labels
Section titled “save_sae_labels”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.
load_sae_labels
Section titled “load_sae_labels”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.
save_prompts
Section titled “save_prompts”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.
save_metadata
Section titled “save_metadata”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.
register_artifact_serializer
Section titled “register_artifact_serializer”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.isinstanceis used at lookup- time, so subclasses match.
serializer: Callable that writes the artifact to disk. Signature:(key, artifact, out_dir, results, metadata) -> None.
save_results
Section titled “save_results”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 insideoutput_dir.
Returns:
- Path to the output directory.