Skip to content

Commit

Permalink
move vit functionality into derandomised smoothing toolset
Browse files Browse the repository at this point in the history
Signed-off-by: GiulioZizzo <giulio.zizzo@yahoo.co.uk>
  • Loading branch information
GiulioZizzo committed Jun 27, 2023
1 parent b154580 commit f7dae57
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"""

from typing import Optional, Tuple
import random

import torch

Expand Down Expand Up @@ -101,6 +102,9 @@ def ablate(self, x: torch.Tensor, column_pos: int) -> torch.Tensor:
:return: The ablated input with 0s where the ablation occurred
"""
k = self.ablation_size
if column_pos is None:
column_pos = random.randint(0, x.shape[3])

if column_pos + k > x.shape[-1]:
x[:, :, :, (column_pos + k) % x.shape[-1] : column_pos] = 0.0
else:
Expand Down

0 comments on commit f7dae57

Please sign in to comment.