peal.sparse_dictionaries.ra_sae_decomposition.RASAEDecomposition¶
- class peal.sparse_dictionaries.ra_sae_decomposition.RASAEDecomposition[source]¶
Bases:
SparseDictionarySparse dictionary wrapper around a pretrained RA-SAE checkpoint.
Pretrained-only: fit/fit_from_dataloaders are deliberately not implemented, since the point of this dictionary is that it is not fitted on our activations.
Methods
Reconstruct token activations from sparse codes.
Sparse codes for [N, 768] tokens, as overcomplete computes them in eval.
Not supported: the dictionary is pretrained (raises
NotImplementedError).Not supported: the dictionary is pretrained (raises
NotImplementedError).Decoder atoms as [n_inputs, n_components], the layout PEAL expects.
RA-SAE ships no concept names -- unlike MSAE there is no text-space interpreter, so concepts are identified by ground-truth matching or by their maximally-activating images, never by a vocabulary lookup.
Restore tensors written by
save_on_disk(); a missing path is a no-op.Save the fused tensors and the threshold to
pathwithtorch.save.Attributes
config- __init__(config=pydantic.BaseModel)[source]¶
Pick the device, allocate the tensor slots and load the fused weights.
- Parameters:
config (
RASAEDecompositionConfig, optional) – Download/cache locations and the activation threshold. Itsn_componentsandact_sizeare overwritten by the values read from the checkpoint.
- get_components()[source]¶
Decoder atoms as [n_inputs, n_components], the layout PEAL expects.
- Return type:
- get_vocabulary()[source]¶
RA-SAE ships no concept names – unlike MSAE there is no text-space interpreter, so concepts are identified by ground-truth matching or by their maximally-activating images, never by a vocabulary lookup.
- encode(x)[source]¶
Sparse codes for [N, 768] tokens, as overcomplete computes them in eval.
- Parameters:
x (torch.Tensor)
- Return type:
- decode(codes)[source]¶
Reconstruct token activations from sparse codes.
- Parameters:
codes (torch.Tensor)
- Return type:
- fit(X, y=None)[source]¶
Not supported: the dictionary is pretrained (raises
NotImplementedError).- Parameters:
X (torch.Tensor)
y (torch.Tensor)
- fit_from_dataloaders(dataloaders, feature_extractor=<function RASAEDecomposition.<lambda>>)[source]¶
Not supported: the dictionary is pretrained (raises
NotImplementedError).
- save_on_disk(path)[source]¶
Save the fused tensors and the threshold to
pathwithtorch.save.- Parameters:
path (
str) – Destination file; parent directories are created.
- load_from_disk(path)[source]¶
Restore tensors written by
save_on_disk(); a missing path is a no-op.- Parameters:
path (
str) – File written bysave_on_disk(). Updatesconfig.n_components,config.act_sizeand, when stored, the threshold.