# Test TL Detector

This detector demonstrates how to extract intermediate activations from a TransformerLens model organism using utility functions and hooks.

## Utility-Based Implementation

The detector modifies the model organism in `get_new_model_and_environment()` using provided utilities:

1. **Accessing the model**: Extract the `HookedTransformer` from `original_model_organism.model.model_args["tl_model"]`

2. **Using the activation hook utility**: Import and use `get_store_activations_hook(activation_cache)`:
   - Pass your `self.activation_cache` dictionary to the utility
   - The returned hook function automatically stores activations with proper detachment and CPU transfer
   - No need to manually implement activation storage logic

3. **Adding the hook**: Use `tl_model.add_hook(layer_name, get_store_activations_hook(self.activation_cache))` where:
   - `layer_name` specifies the target layer (e.g., `"blocks.5.attn.hook_z"` for attention outputs)
   - The utility handles activation processing automatically

4. **Updating model organism**: Use `update_model_organism_with_new_tl_model(model_organism, tl_model)`:
   - Automatically creates a new ModelOrganism with the hooked model
   - Preserves all original configuration while updating the transformer model

The stored activations are accessible in `get_prediction()` via `self.activation_cache[layer_name]` for analysis.

## Reproduction

To adapt this pattern:
- Import utilities: `from util import get_store_activations_hook, update_model_organism_with_new_tl_model`
- Replace `"blocks.5.attn.hook_z"` with your target layer
- Initialize `self.activation_cache: dict[str, torch.Tensor] = {}` in `__init__()`
