Use when a user wants to analyze higher-order information (HOI) interactions in PyTorch neural network layers, including synergy and redundancy patterns via O-information metrics.
Analyze higher-order information (HOI) interactions in PyTorch neural network layers. Use this skill when a user wants to understand synergy and redundancy patterns between or within model layers using O-information metrics.
references/phiid-future.md)Install the required Python packages:
# Option A: pip
pip install torch numpy matplotlib hoi
# Option B: uv
uv add torch numpy matplotlib hoi
No pip package installation is needed for this skill itself -- the scripts are
self-contained and run directly with python.
Follow these phases in order. Do NOT skip the information-gathering phase.
Ask the user these questions (one at a time, use the question tool):
Model location: "Where is your PyTorch model defined? I need a Python file
with a build_model() function that returns a torch.nn.Module."
build_model().model.py using references/model-template.py as a
starting point.Inference runner: "Do you have a script that runs inference on your model?
I need a Python file with a run(model, data_path, *, max_batches=None) function
that yields batch info during forward passes."
run() with the correct
signature.run.py using references/run-template.py as a
starting point.Data path: "Where is the data your model processes?"
Analysis goal (use question tool with choices):
Before running the pipeline, validate:
# 1. Check model loads and list layers
python scripts/probe.py --model <model.py>
AttributeError: model.py is missing build_model().
Help the user fix it.layers.txt (one per line).Layer selection guidance:
Choose the right mode based on Phase 1 analysis goal:
Cross-layer analysis (scalar mode):
python scripts/extract.py \
--model <model.py> \
--run <run.py> \
--data <data_path> \
--layers layers.txt \
--agg l2 \
--out outputs/<run_id>/ \
--repr scalar
Within-layer analysis (PCA mode):
python scripts/extract.py \
--model <model.py> \
--run <run.py> \
--data <data_path> \
--layers layers.txt \
--out outputs/<run_id>/ \
--repr pca \
--pca-k 5
--pca-k: number of PCA components per layer. Use 5 as default; increase for
wide layers, decrease if layers have low dimensionality.--max-batches N: limit inference batches for large datasets. Suggest 50-100
for initial exploration.--agg: only applies in scalar mode. l2 (default) uses L2 norm, mean uses
mean. Recommend l2 unless user has a reason to prefer mean.Common errors:
layers.txt don't match probe output.
Re-run probe and fix the file.--pca-k.Cross-layer:
python scripts/analyze.py \
--activations outputs/<run_id>/activations.npz \
--out outputs/<run_id>/ \
--n-best 10 \
--scope cross-layer
Within-layer:
python scripts/analyze.py \
--activations outputs/<run_id>/activations.npz \
--out outputs/<run_id>/ \
--n-best 10 \
--scope within-layer
Common errors:
--pca-k.--pca-k or exclude that layer.After analysis completes, read the outputs and explain them to the user:
Read report.md - summarize key findings.
Read top_multiplets.json - explain the top triplets:
Show plots if the user's environment supports it:
top_multiplets.png - bar chart of most redundant (red) and synergistic (blue)
triplets.oinfo_distribution.png - histogram showing the overall distribution of
O-information values.layer_comparison.png - comparison of max redundancy/synergy
across layers.Suggest next steps based on results:
references/phiid-future.md).For users who want to skip the step-by-step workflow (e.g., re-running with different parameters), use the pipeline script:
python scripts/run_pipeline.py \
--model <model.py> \
--run <run.py> \
--data <data_path> \
--out outputs/<run_id>/ \
--repr scalar \
--scope cross-layer \
--n-best 10
This chains probe -> extract -> analyze automatically. If --layers is omitted,
it uses the first 10 probed layers.
references/cli-contract.md - complete CLI interface specificationreferences/model-template.py - template for creating model.pyreferences/run-template.py - template for creating run.pyreferences/phiid-future.md - future PhiID extension roadmapexamples/mini_torch_model/ - minimal working example