mirror of
https://github.com/wassname/discovering_latent_knowledge.git
synced 2026-09-10 12:00:13 +08:00
misc
This commit is contained in:
+106
@@ -1309,9 +1309,115 @@ I would also like to work out which parts I need to save to get a good predictio
|
||||
|
||||
hmm looks at this, in they use torch.autograd to backpropr to noise on the embeddings https://github.com/microsoft/KEAR/blob/7376a3d190e5c04d5da9b99873abe621ae562edf/model/perturbation.py#L60
|
||||
|
||||
https://github.com/deeplearning2012/ecco/blob/40ff4cd3661a202d4ad5bfb9bbc0e54701c1dd29/src/ecco/attribution.py#L59
|
||||
|
||||
# 2023-09-10 13:04:00
|
||||
|
||||
wow I got 96% wit ha lienar prob and head_activation_and_grad !!
|
||||
|
||||
oh but in the breakdown it's not getting the lies? or is that just my label?
|
||||
|
||||
|
||||
# 2023-09-10 19:04:13
|
||||
|
||||
:bug: oh so in the amazon polarity ones, the prompt has an extra \n... that doesn't fit for me. I have an example with two \n, but then a prompt with one...
|
||||
|
||||
hmm I need to dive into this, maybe if I always use a blank answer
|
||||
|
||||
|
||||
:star: ah I was truncating the prompt. 1 shot seems better
|
||||
|
||||
UPTO redo imdb but with 1 shot, and therefore less mem and truncating of sys instructions...
|
||||
|
||||
# 2023-09-11 06:38:05
|
||||
|
||||
So I get almost 100% somehow, even with a linear probe!. Where is it cheating? It's cutting a lot based on ones it doesn't know... is it unbalancing it?
|
||||
|
||||
Without cutting the 50% it doesn't know we get 78-85%, which is about how many it knows?
|
||||
|
||||
# 2023-09-11 20:35:32
|
||||
|
||||
Huh I can get near 100% on either imdb or amazon polarity but not both (more like 60%). Why is that?
|
||||
|
||||
# 2023-09-15 12:51:01
|
||||
|
||||
https://www.lesswrong.com/posts/nmxzr2zsjNtjaHh7x/actually-othello-gpt-has-a-linear-emergent-world#Intervening
|
||||
|
||||
Ideas:
|
||||
- maybe I didn't need grads, just the outputs?
|
||||
- [x] OK with a linear prob: residual head gets 0% on lies. grads get 50%, so grads seems important but I should try mlp. It's worth together
|
||||
- maybe I can use state representations like neel nanda does? he seems to use post_residual, what is what. oh wait's it's what I'm using but added together
|
||||
- [x] maybe I can use a linear probe like https://github.com/likenneth/othello_world/blob/f23bb5696cf30b93bd8af8a391ee33fc3aac417e/mechanistic_interpretability/tl_probing_v1.py#L97
|
||||
- meh it's just my model with one layer and no activation
|
||||
|
||||
# 2023-09-15 18:03:17
|
||||
|
||||
Experiment!
|
||||
|
||||
| feats | val acc | test acc |
|
||||
| ------------------------------ | ------- | -------- |
|
||||
| w_grads_mlp[0] | 0.31 | 0.26 |
|
||||
| head_activation_and_grad[0] | 0.92 | 0.73 |
|
||||
| head_activation_and_grad[1] | 0.5 | 0.47 |
|
||||
| head_activation_and_grad[0, 1] | 1 | 0.94 |
|
||||
| mlp_activation_and_grad[0] | 0.89 | 0.81 |
|
||||
| mlp_activation_and_grad[1] | 0.5 | 0.47 |
|
||||
| mlp_activation_and_grad[0, 1] | 1 | 0.89 |
|
||||
| residual_stream[0] | 0.86 | 0.84 |
|
||||
| residual_stream[1] | 0.5 | 0.47 |
|
||||
| residual_stream[0, 1] | 1 | 0.92 |
|
||||
|
||||
|
||||
| feats | val acc | test acc |
|
||||
| ----------------------------- | ------- | -------- |
|
||||
| weight_grads_mlp | 0.31 | 0.26 |
|
||||
| **head_activation_and_grad** | 1 | 0.94 |
|
||||
| **head_activation** | 0.92 | 0.73 |
|
||||
| head_grad | 0.5 | 0.47 |
|
||||
| mlp_activation_and_grad[0, 1] | 1 | 0.89 |
|
||||
| **mlp_activation** | 0.89 | 0.81 |
|
||||
| mlp_grad | 0.5 | 0.47 |
|
||||
| **residual_stream_and_grads** | 1 | 0.92 |
|
||||
| residual_stream | 0.86 | 0.84 |
|
||||
| residual_stream_grads | 0.5 | 0.47 |
|
||||
|
||||
conclusions:
|
||||
- weight grads don't help
|
||||
- head > residual > mlp
|
||||
- grad_and_act > act > grad
|
||||
|
||||
So the best is head_grad_and_act
|
||||
|
||||
But given that head activation is good, and residual stream is good... perhaps I should use them? As they let me use a 4x larger model or batch
|
||||
|
||||
|
||||
And yes the activation stream one get's 92%.11!
|
||||
but the residual stream on gets 84% but that's not much when the balance is not even
|
||||
|
||||
|
||||
OK so dice is better for loss and measuring acc like peformance.
|
||||
|
||||
But when I used multiple datasets the performance degrades a lot! why is that?
|
||||
|
||||
# what datasets can I use?
|
||||
|
||||
right now just boolean as the binarize thing isn't working for either the sampler or fewshot
|
||||
|
||||
# 2023-09-16 13:32:00
|
||||
|
||||
Next I think I need to sanity check the datasets!
|
||||
- normalize? or at least check dist
|
||||
- visualize all data
|
||||
- check key statistics: acc
|
||||
|
||||
|
||||
then decidce on what we need to gather
|
||||
|
||||
|
||||
FIXME:bug: :idea: OMG is the bug that I'm messing up the known question index?
|
||||
|
||||
- [x] f
|
||||
- [/] test
|
||||
- [.] f
|
||||
- [>] f
|
||||
- [o] d
|
||||
|
||||
+276
-954
File diff suppressed because it is too large
Load Diff
+1399
-618
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -155,18 +155,110 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"# promtps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'Title: {{title}}\\nReview: {{content}}\\nIs the review positive or negative? |||\\n{{answer_choices[label]}}'"
|
||||
]
|
||||
},
|
||||
"execution_count": 39,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from src.prompts.prompt_loading import DatasetTemplates, _convert_to_prompts, Random, default_sys_instructions\n",
|
||||
"ds_name = 'imdb'\n",
|
||||
"example = dict(label=0, text= 'text', content=\"content\", title='title', response=\"Negative\")\n",
|
||||
"ds_name = 'amazon_polarity'\n",
|
||||
"example = dict(label=0, text= 'text', content=\"content\", title='title', response=\"Negative\")\n",
|
||||
"prompter = DatasetTemplates(ds_name)\n",
|
||||
"templates = list(prompter.templates.values())\n",
|
||||
"template = templates[0]\n",
|
||||
"template.jinja"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 40,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['Title: title\\nReview: content\\nIs the review positive or negative?',\n",
|
||||
" '\\nNegative']"
|
||||
]
|
||||
},
|
||||
"execution_count": 40,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"template.apply(example)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'answer': 'Negative',\n",
|
||||
" 'question': 'Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\\n\\n### Instruction\\nTitle: title\\nReview: content\\nIs the review positive or negative?\\n\\n### Response:\\n',\n",
|
||||
" 'answer_choices': ['Negative', 'Positive'],\n",
|
||||
" 'template_name': 'Is_this_review',\n",
|
||||
" 'label_true': 0,\n",
|
||||
" 'label_instructed': 0,\n",
|
||||
" 'instructed_to_lie': False,\n",
|
||||
" 'sys_instr_name': 'truth'}"
|
||||
]
|
||||
},
|
||||
"execution_count": 35,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"\n",
|
||||
"sys_instructions = 'say a lie'\n",
|
||||
"rng = Random(42)\n",
|
||||
"prompts = _convert_to_prompts(\n",
|
||||
" example,\n",
|
||||
" binarize=True,\n",
|
||||
" label_column='label',\n",
|
||||
" label_choices=['No', 'Yes'], # type: ignore[arg-type]\n",
|
||||
" prompter=prompter,\n",
|
||||
" rng=rng,\n",
|
||||
" # sys_instructions=default_sys_instructions,\n",
|
||||
" # fewshot_iter=fewshot_iter,\n",
|
||||
" prompt_format='llama',\n",
|
||||
")\n",
|
||||
"prompts[0]"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 19,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
"source": [
|
||||
"# %debug"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
|
||||
+9
-5
@@ -161,6 +161,8 @@ class ExtractHiddenStates:
|
||||
w_grads_mlp_cfc = w_grads_mlp_cfc[:, layers]
|
||||
w_grads_attn = w_grads_attn[:, layers]
|
||||
w_grads_mlp = w_grads_mlp[:, layers]
|
||||
|
||||
residual_stream = head_activation_and_grad + mlp_activation_and_grad
|
||||
|
||||
# collect outputs
|
||||
out = dict(
|
||||
@@ -168,18 +170,20 @@ class ExtractHiddenStates:
|
||||
scores=outputs["scores"],
|
||||
layers=layers,
|
||||
|
||||
# hidden_states=hidden_states,
|
||||
hidden_states=hidden_states,
|
||||
|
||||
# head_activation=head_activation,
|
||||
# mlp_activation=mlp_activation,
|
||||
|
||||
# mlp_activation=mlp_activation,
|
||||
# head_activation_grads = head_activation_grads,
|
||||
|
||||
head_activation_and_grad=head_activation_and_grad,
|
||||
# mlp_activation_and_grad=mlp_activation_and_grad,
|
||||
mlp_activation_and_grad=mlp_activation_and_grad,
|
||||
|
||||
residual_stream=residual_stream,
|
||||
|
||||
# w_grads_mlp=w_grads_mlp,
|
||||
# w_grads_mlp_cfc=w_grads_mlp_cfc,
|
||||
# w_grads_attn=w_grads_attn,
|
||||
w_grads_attn=w_grads_attn,
|
||||
)
|
||||
out = {k: detachcpu(v) for k, v in out.items()}
|
||||
if debug:
|
||||
|
||||
Reference in New Issue
Block a user