Snapshot¶
Hidden state capture and analysis.
SnapshotCapture¶
SnapshotCapture
¶
Capture hidden state snapshots during model inference.
Usage
capture = SnapshotCapture(model) snapshots = capture.run(input_ids, layers=["model.layers.0", "model.layers.15"]) for name, snap in snapshots.items(): print(f"{name}: mean={snap.mean_activation:.4f}, sparsity={snap.sparsity:.2%}")
Source code in src/model_garage/snapshot/capture.py
run
¶
Run inference and capture snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_ids
|
Tensor
|
Input token IDs |
required |
layers
|
Optional[List[str]]
|
Specific layer names to capture. If None, auto-detect. |
None
|
num_layers
|
Optional[int]
|
Number of layers to capture (evenly spaced). Used with auto-detect. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, LayerSnapshot]
|
Dict mapping layer names to LayerSnapshot objects |
Source code in src/model_garage/snapshot/capture.py
LayerSnapshot¶
LayerSnapshot
dataclass
¶
A snapshot of hidden states at a specific layer.
Source code in src/model_garage/snapshot/capture.py
from_tensor
classmethod
¶
Create a snapshot from a captured tensor.