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:
@@ -2241,3 +2241,17 @@ output[0][:, intervention_idx, :] += direction * alpha
|
||||
- but in the representation engineering one, they use diff(hidden_states) to get std and direction. Then apply slightly differently? Still trying to work this out https://github.com/andyzoujm/representation-engineering
|
||||
- oh wait it looks like the same? https://github.com/wassname/representation-engineering/blob/acd14ab15f6d37710dd9a3b47caa2900ce5c2569/repe/rep_control_reading_vec.py#L64
|
||||
- and manually https://github.com/wassname/representation-engineering/blob/acd14ab15f6d37710dd9a3b47caa2900ce5c2569/examples/honesty/honesty_control_TQA.ipynb
|
||||
|
||||
|
||||
# 2023-12-16 21:06:50
|
||||
|
||||
I need more small experiments I can verify
|
||||
|
||||
Why do I need ranking AND SAE AND importance matrix AND intervention?
|
||||
|
||||
Some haven't worked along:
|
||||
- ranking (maybe because dropout doesnt give enougth variation? or the variation is useless), it needs intervention, but intervention might work on it's own. And then all ranking does it possibly help avoid overfitting!
|
||||
- intervention... it's hard to find a good one. It's either too little to matter or too much and the model is incoherent, meaning it's a implausible intervention. Plus all my interventions so far have been for the word true, not true or deception.
|
||||
- [ ] Try doing MMProbe with deception vs truth?
|
||||
- [ ] Try SGD only on bias! trying to flip the probabilities on a large batch (can use grad accum)
|
||||
- SAE... no one has solved this. Maybe with an important matrix (which can come from an intervention)
|
||||
|
||||
+1078
-340
File diff suppressed because one or more lines are too long
+2
-4
@@ -25,7 +25,7 @@ def verbose_change_param(tokenizer, path, after):
|
||||
return tokenizer
|
||||
|
||||
|
||||
def load_model(model_repo = "microsoft/phi-2", pad_token_id=0) -> Tuple[AutoModelForCausalLM, PreTrainedTokenizerBase]:
|
||||
def load_model(model_repo = "microsoft/phi-2", pad_token_id=0, disable_exllama=True) -> Tuple[AutoModelForCausalLM, PreTrainedTokenizerBase]:
|
||||
"""
|
||||
A uncensored and large coding ones might be best for lying.
|
||||
|
||||
@@ -58,11 +58,9 @@ def load_model(model_repo = "microsoft/phi-2", pad_token_id=0) -> Tuple[AutoMod
|
||||
model = AutoModelForCausalLM.from_pretrained(model_repo, config=config,
|
||||
**model_options)
|
||||
|
||||
try:
|
||||
if disable_exllama:
|
||||
from auto_gptq import exllama_set_max_input_length
|
||||
model = exllama_set_max_input_length(model, max_input_length=5000)
|
||||
except Exception as e:
|
||||
logger.exception("could not set exllama max input length")
|
||||
|
||||
return model, tokenizer
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class Intervention(nn.Module):
|
||||
diff = (true_mean - false_mean) @ direction
|
||||
self.norm_direction = t.nn.Parameter(diff * direction, requires_grad=False)
|
||||
|
||||
def edit(self, x, alpha=1):
|
||||
def edit(self, x, alpha=0.25):
|
||||
self.to(x.device).to(x.dtype)
|
||||
|
||||
# how do we actually edit? here is how two project do it
|
||||
|
||||
@@ -33,7 +33,7 @@ def hacky_sanitize_outputs(o):
|
||||
def row_choice_ids(answer_choices, tokenizer):
|
||||
return choice2ids([c for c in answer_choices], tokenizer)
|
||||
|
||||
def intervention_fn(outputs: torch.Tensor, layer_name: str, intervention: Intervention) -> torch.Tensor:
|
||||
def intervention_fn(outputs: torch.Tensor, layer_name: str, intervention: Intervention, alpha=0.25) -> torch.Tensor:
|
||||
"""
|
||||
This adapts and intervention function for baukit Tracdict
|
||||
|
||||
@@ -48,10 +48,10 @@ def intervention_fn(outputs: torch.Tensor, layer_name: str, intervention: Interv
|
||||
|
||||
# different transformer have different formats of layer returns
|
||||
if type(outputs) is tuple:
|
||||
output0 = fn.edit(outputs[0])
|
||||
output0 = fn.edit(outputs[0], alpha=alpha)
|
||||
return (output0, *outputs[1:])
|
||||
elif type(outputs) is torch.Tensor:
|
||||
return fn.edit(outputs)
|
||||
return fn.edit(outputs, alpha=alpha)
|
||||
else:
|
||||
raise ValueError(f"layer outputs must be tuple or tensor, got {type(outputs)}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user