mirror of
https://github.com/wassname/discovering_latent_knowledge.git
synced 2026-09-11 12:10:11 +08:00
misc
This commit is contained in:
Binary file not shown.
@@ -1776,3 +1776,12 @@ How does the intervention work?
|
||||
- https://github.com/davidbau/baukit/blob/main/baukit/nethook.py
|
||||
- `out = edit_out(out, layer_name)`
|
||||
- but **honest_llama seperates it's states by head**. But are the intervening on the hiddenstate after output... no they are intervening on the layers... so head. Yeah it makes sense now!
|
||||
|
||||
|
||||
# 2023-10-15 18:48:00
|
||||
|
||||
Ok so I got a center of mass intervention to the heads :)
|
||||
|
||||
Now I just need to debug the dataloading script... nesxt week
|
||||
|
||||
TODO: I need to split test train based on example_i, not row!
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -354,7 +354,7 @@ def create_intervention(ds_name, ds_tokens, model, layer_names, N=10):
|
||||
|
||||
ds_tokens_calib = ds_tokens.select(range(N-1))
|
||||
# TODO: do we need ds_name if we have the ds?
|
||||
ds_calibration = create_hs_ds(ds_name+'_calib', ds_tokens_calib, model, cfg, intervention_dicts = None, f=f)
|
||||
ds_calibration = create_hs_ds(ds_name+'_calib', ds_tokens_calib, model, cfg, intervention_dicts = None, f=None)
|
||||
|
||||
activations = np.array(ds_calibration['head_activation']).squeeze(-1)
|
||||
labels = np.array(ds_calibration["label_true"]).astype(int)==1
|
||||
@@ -366,6 +366,7 @@ def create_intervention(ds_name, ds_tokens, model, layer_names, N=10):
|
||||
def load_intervention(ds_name, cfg, model, tokenizer, model_name):
|
||||
num_heads = model.config.num_attention_heads
|
||||
intervention_f = root_folder / 'data' / 'interventions' / f'{model_name}.pkl'
|
||||
intervention_f.parent.mkdir(exist_ok=True, parents=True)
|
||||
if not intervention_f.exists():
|
||||
layer_names, layer_inds = ExtractHiddenStates(model, tokenizer, layer_stride=cfg.layer_stride, layer_padding=cfg.layer_padding).get_layer_names()
|
||||
ds_tokens = load_preproc_dataset(ds_name, cfg, tokenizer, N=10)
|
||||
@@ -416,8 +417,9 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
|
||||
sanitize = lambda s:s.replace('/', '').replace('-', '_') if s is not None else s
|
||||
ds_name = 'imdb'
|
||||
model_name = cfg.model
|
||||
model_name = sanitize(cfg.model)
|
||||
intervention, intervention_fn = load_intervention(ds_name, cfg, model, tokenizer, model_name)
|
||||
|
||||
for ds_name in ds_names:
|
||||
@@ -427,7 +429,6 @@ if __name__ == "__main__":
|
||||
# ## Save as Huggingface Dataset
|
||||
# get dataset filename
|
||||
N = len(ds_tokens)
|
||||
sanitize = lambda s:s.replace('/', '').replace('-', '_') if s is not None else s
|
||||
dataset_name = f"{sanitize(cfg.model)}_{ds_name}_{split_type}_{N}"
|
||||
f = f"../.ds/{dataset_name}"
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ from elk.utils import (
|
||||
import functools
|
||||
from elk.extraction.balanced_sampler import BalancedSampler, FewShotSampler
|
||||
import pandas as pd
|
||||
from loguru import logger
|
||||
|
||||
# Local path to the folder containing the templates
|
||||
TEMPLATES_FOLDER_PATH = Path(__file__).parent / "templates"
|
||||
@@ -183,7 +184,10 @@ def load_prompts(
|
||||
answer_choices = prompt['answer_choices']
|
||||
a = answer_choices[0][:3]
|
||||
b = answer_choices[1][:3]
|
||||
return (a != b) and ' ' not in a
|
||||
keep = (a != b) and ' ' not in a
|
||||
if not keep:
|
||||
logger.debug(f"removing prompt because it's answers are not unique: {prompt['ds_string']} {prompt['template_name']} {prompt['answer_choices']}")
|
||||
return keep
|
||||
|
||||
prompts = list(filter(prompt_ok, prompts))
|
||||
prompts = prompt_sampler(prompts, seed=42+j)
|
||||
|
||||
Reference in New Issue
Block a user