tdhook.latent.activation_patching#

Classes#

ActivationPatching

Causal mediation analysis [17] and latent editing [18, 19].

Module Contents#

class tdhook.latent.activation_patching.ActivationPatching(modules_to_patch, patch_key='patched', clean_intermediate_keys=True, patch_fn=None, cache_callback=None)[source]#

Bases: tdhook.contexts.HookingContextFactory

Causal mediation analysis [17] and latent editing [18, 19].

Parameters:
  • modules_to_patch (List[str])

  • patch_key (tdhook._types.UnraveledKey)

  • clean_intermediate_keys (bool)

  • patch_fn (Optional[Callable])

  • cache_callback (Optional[Callable])

_modules_to_patch[source]#
_patch_key = 'patched'[source]#
_clean_intermediate_keys = True[source]#
_patch_fn = None[source]#
_cache_callback = None[source]#
_prepare_module(module, in_keys, out_keys, extra_relative_path)[source]#
Parameters:
Return type:

tensordict.nn.TensorDictModuleBase

_hook_module(module)[source]#
Parameters:

module (tdhook.modules.HookedModule)

Return type:

tdhook.hooks.MultiHookHandle