Analysis
Post-training feature analysis and interpretability tools.
FeatureAnalyzerConfig
pydantic-model
Bases: BaseConfig
Config:
arbitrary_types_allowed:True
Fields:
-
total_analyzing_tokens(int) -
ignore_token_ids(list[int] | None) -
subsamples(dict[str, dict[str, int | float]]) -
clt_layer(int | None)
ignore_token_ids
pydantic-field
Tokens to ignore in the activations.
subsamples
pydantic-field
Dictionary mapping subsample names to their parameters:
- proportion: Proportion of max activation to consider
- n_samples: Number of samples to keep
- max_length: Maximum length of the sample
FeatureAnalyzer
FeatureAnalyzer(cfg: FeatureAnalyzerConfig)
Analyzes feature activations from a sparse autoencoder.
This class processes activation data from a sparse autoencoder to: 1. Track activation statistics like frequency and magnitude 2. Sample and store representative activations 3. Organize results by feature for analysis
Initialize the feature analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
FeatureAnalyzerConfig
|
Analysis configuration specifying parameters like sample sizes and thresholds |
required |
Source code in src/lm_saes/analysis/feature_analyzer.py
compute_ignore_token_masks
compute_ignore_token_masks(
tokens: Tensor,
ignore_token_ids: Optional[list[int]] = None,
) -> Tensor
Compute ignore token masks for the given tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
Tensor
|
The tokens to compute the ignore token masks for |
required |
ignore_token_ids
|
Optional[list[int]]
|
The token IDs to ignore |
None
|
Source code in src/lm_saes/analysis/feature_analyzer.py
get_post_analysis_func
Get the post-analysis processor for the given SAE type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sae_type
|
str
|
The SAE type identifier |
required |
Returns:
| Type | Description |
|---|---|
|
The post-analysis processor instance |
Source code in src/lm_saes/analysis/feature_analyzer.py
analyze_chunk
analyze_chunk(
activation_factory: ActivationFactory,
sae: AbstractSparseAutoEncoder,
device_mesh: DeviceMesh | None = None,
activation_factory_process_kwargs: dict[str, Any] = {},
) -> list[dict[str, Any]]
Analyze feature activations for a chunk of the SAE.
Processes activation data to: 1. Track activation statistics 2. Sample representative activations 3. Organize results by feature
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activation_factory
|
ActivationFactory
|
The activation factory to use |
required |
sae
|
AbstractSparseAutoEncoder
|
The sparse autoencoder model |
required |
device_mesh
|
DeviceMesh | None
|
The device mesh to use |
None
|
activation_factory_process_kwargs
|
dict[str, Any]
|
Keyword arguments to pass to the activation factory's process method |
{}
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of dictionaries containing per-feature analysis results: |
list[dict[str, Any]]
|
|
list[dict[str, Any]]
|
|
Source code in src/lm_saes/analysis/feature_analyzer.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
DirectLogitAttributorConfig
pydantic-model
DirectLogitAttributor
DirectLogitAttributor(cfg: DirectLogitAttributorConfig)
Source code in src/lm_saes/analysis/direct_logit_attributor.py
direct_logit_attribute
Compute direct logit attribution for the given SAE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sae
|
The SAE model to attribute. |
required | |
model
|
LanguageModel
|
The language model backend. |
required |
layer_idx
|
int | None
|
The layer index (required for some SAE types like CrossLayerTranscoder). |
None
|
Returns:
| Type | Description |
|---|---|
|
A list of dictionaries containing top positive and negative logits for each feature. |