Skip to content

Commit 3cc28f9

Browse files
committed
Fix tutorial error
1 parent 6f26260 commit 3cc28f9

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tutorials/code_intervention.ipynb

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
18-
"! pip install codebook-features\n",
19-
"# restart runtime after installing if running on Colab\n",
20-
"from IPython import get_ipython\n",
18+
"try:\n",
19+
" import codebook_features\n",
20+
"except:\n",
21+
" ! pip install codebook-features\n",
22+
" # restart runtime after installing if running on Colab\n",
23+
" from IPython import get_ipython\n",
2124
"\n",
22-
"if \"google.colab\" in str(get_ipython()):\n",
23-
" exit(0)"
25+
" if \"google.colab\" in str(get_ipython()):\n",
26+
" exit(0)"
2427
]
2528
},
2629
{
@@ -106,6 +109,7 @@
106109
"source": [
107110
"sentence = \"this is a random sentence to test.\"\n",
108111
"input_tensor = tokenizer(sentence, return_tensors=\"pt\")[\"input_ids\"]\n",
112+
"input_tensor = input_tensor.to(device)\n",
109113
"output = orig_cb_model(input_tensor)[\"logits\"]\n",
110114
"hooked_output = cb_model(input_tensor)\n",
111115
"assert torch.allclose(output, hooked_output, atol=1e-4)"

0 commit comments

Comments
 (0)