-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from TomFrederik/develop/0.1.6
Develop/0.1.6
- Loading branch information
Showing
6 changed files
with
50 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from . import * | ||
|
||
__version__ = '0.1.5' | ||
__version__ = '0.1.6' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from . import common_hooks | ||
from . import util | ||
from . import rome_hooks | ||
from .commons import Hook, HookedModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,7 @@ | ||
# Some pre-implemented hooking functions to reproduce the experiments | ||
# from the ROME paper: https://openreview.net/forum?id=mMECu_poAs | ||
#TODO for version 1.0.0: Remove this file | ||
import logging | ||
|
||
# Some hooks that I've only used in the context of the ROME paper so far --> possibly migrate this to the unseal_experiments repo | ||
from typing import Callable, Optional | ||
from .common_hooks import additive_output_noise, hidden_patch_hook_fn | ||
|
||
import torch | ||
logging.warning("rome_hooks.py is deprecated and will be removed in version 1.0.0. Please use common_hooks.py instead.") | ||
|
||
from . import util | ||
from . import common_hooks | ||
|
||
|
||
def additive_output_noise( | ||
indices: str, | ||
mean: Optional[float] = 0, | ||
std: Optional[float] = 0.1 | ||
) -> Callable: | ||
slice_ = util.create_slice_from_str(indices) | ||
def func(save_ctx, input, output): | ||
noise = mean + std * torch.randn_like(output[slice_]) | ||
output[slice_] += noise | ||
return output | ||
return func | ||
|
||
def hidden_patch_hook_fn( | ||
position: int, | ||
replacement_tensor: torch.Tensor, | ||
) -> Callable: | ||
indices = "...," + str(position) + len(replacement_tensor.shape) * ",:" | ||
inner = common_hooks.replace_activation(indices, replacement_tensor) | ||
def func(save_ctx, input, output): | ||
output[0][...] = inner(save_ctx, input, output[0]) | ||
return output | ||
return func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters