Skip to content

Commit

Permalink
Run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tvhong committed Apr 11, 2024
1 parent 9fa08e6 commit 0b5ef81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions obvs/patchscope_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,15 @@ def n_layers(self) -> int:

@property
def n_layers_source(self) -> int:
return len(getattr(getattr(self.source_model, self.MODEL_TARGET), self.LAYER_TARGET))
return len(
getattr(getattr(self.source_model, self.target_base_name), self.target_layer_name),
)

@property
def n_layers_target(self) -> int:
return len(getattr(getattr(self.target_model, self.MODEL_TARGET), self.LAYER_TARGET))
return len(
getattr(getattr(self.target_model, self.target_base_name), self.target_layer_name),
)

def compute_precision_at_1(self, estimated_probs: torch.Tensor, true_token_index):
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_patchscopes.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ def test_source_forward_pass_with_attention_head_patching(patchscope):
patchscope.source.head = 0
patchscope.source_forward_pass()

assert patchscope._source_hidden_state.value.shape[0] == 1 # Batch size, always 1
assert patchscope._source_hidden_state.value.shape[1] == len(
assert patchscope._source_hidden_state.shape[0] == 1 # Batch size, always 1
assert patchscope._source_hidden_state.shape[1] == len(
patchscope.source_tokens,
) # Number of tokens
assert (
patchscope._source_hidden_state.value.shape[2]
patchscope._source_hidden_state.shape[2]
== patchscope.source_model.transformer.h[0].attn.head_dim
) # Head dimension

0 comments on commit 0b5ef81

Please sign in to comment.