Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions transformer_lens/hook_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def full_hook(
module_input: Any,
module_output: Any,
):
if (
dir == "bwd"
): # For a backwards hook, module_output is a tuple of (grad,) - I don't know why.
module_output = module_output[0]
return hook(module_output, hook=self)
# For a backwards hook, module_output is a tuple of (grad,)
hook_arg = module_output[0] if dir == "bwd" else module_output
result = hook(hook_arg, hook=self)
if dir == "bwd" and result is not None:
return result if isinstance(result, tuple) and len(result) == 1 else (result,)
return result

# annotate the `full_hook` with the string representation of the `hook` function
if isinstance(hook, partial):
Expand Down