Skip to content

Commit

Permalink
Upload dead feature stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
hijohnnylin committed Apr 15, 2024
1 parent 8230570 commit 9067380
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 44 deletions.
38 changes: 13 additions & 25 deletions tutorials/neuronpedia/generating_neuronpedia_outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@
"import os\n",
"import requests\n",
"\n",
"folder_path = \"../../neuronpedia_outputs/gpt2-small_blocks.0.hook_resid_pre_24576\" #runner.neuronpedia_folder\n",
"\n",
"FEATURE_OUTPUTS_FOLDER = runner.outputs_folder\n",
"\n",
"def nanToNeg999(obj: Any) -> Any:\n",
" if isinstance(obj, dict):\n",
Expand All @@ -110,13 +109,12 @@
"\n",
"# Server info\n",
"host = \"http://localhost:3000\"\n",
"sourceName = str(LAYER) + \"-\" + SOURCE\n",
"\n",
"# Upload alive features\n",
"for file_name in os.listdir(folder_path):\n",
"for file_name in os.listdir(FEATURE_OUTPUTS_FOLDER):\n",
" if file_name.startswith(\"batch-\") and file_name.endswith(\".json\"):\n",
" print(\"Uploading file: \" + file_name)\n",
" file_path = os.path.join(folder_path, file_name)\n",
" file_path = os.path.join(FEATURE_OUTPUTS_FOLDER, file_name)\n",
" f = open(file_path, \"r\")\n",
" data = json.load(f)\n",
"\n",
Expand All @@ -127,28 +125,18 @@
" url = host + \"/api/local/upload-features\"\n",
" resp = requests.post(\n",
" url,\n",
" json={\n",
" \"modelId\": MODEL,\n",
" \"layer\": sourceName,\n",
" \"features\": data,\n",
" },\n",
" json=data,\n",
" )\n",
"\n",
"# Upload dead features (just makes blanks features)\n",
"# We want this for completeness\n",
"# skipped_path = os.path.join(folder_path, \"skipped_indexes.json\")\n",
"# f = open(skipped_path, \"r\")\n",
"# data = json.load(f)\n",
"# skipped_indexes = data[\"skipped_indexes\"]\n",
"# url = host + \"/api/internal/upload-dead-features\"\n",
"# resp = requests.post(\n",
"# url,\n",
"# json={\n",
"# \"modelId\": MODEL,\n",
"# \"layer\": sourceName,\n",
"# \"deadIndexes\": skipped_indexes,\n",
"# },\n",
"# )"
"# Upload dead feature stubs\n",
"skipped_path = os.path.join(FEATURE_OUTPUTS_FOLDER, \"skipped_indexes.json\")\n",
"f = open(skipped_path, \"r\")\n",
"data = json.load(f)\n",
"url = host + \"/api/local/upload-dead-features\"\n",
"resp = requests.post(\n",
" url,\n",
" json=data,\n",
")"
]
},
{
Expand Down
16 changes: 0 additions & 16 deletions tutorials/neuronpedia/upload_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,3 @@ def encode(self, o: Any, *args: Any, **kwargs: Any):
url,
json=data,
)

# Upload dead features (just makes blanks features)
# We want this for completeness
# skipped_path = os.path.join(folder_path, "skipped_indexes.json")
# f = open(skipped_path, "r")
# data = json.load(f)
# skipped_indexes = data["skipped_indexes"]
# url = host + "/api/internal/upload-dead-features"
# resp = requests.post(
# url,
# json={
# "modelId": MODEL,
# "layer": sourceName,
# "deadIndexes": skipped_indexes,
# },
# )
18 changes: 18 additions & 0 deletions tutorials/neuronpedia/upload_dead_feature_stubs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
import os
import requests
import sys

FEATURE_OUTPUTS_FOLDER = sys.argv[1]

# Server info
host = "http://localhost:3000"

skipped_path = os.path.join(FEATURE_OUTPUTS_FOLDER, "skipped_indexes.json")
f = open(skipped_path, "r")
data = json.load(f)
url = host + "/api/local/upload-dead-features"
resp = requests.post(
url,
json=data,
)
19 changes: 19 additions & 0 deletions tutorials/neuronpedia/upload_dead_feature_stubs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

echo "===== This will create stubs for dead features using skipped_indexes.json."
echo "===== You'll need Neuronpedia running at localhost:3000 for this to work."

echo ""
echo "(Step 1 of 1)"
echo "What is the absolute, full local DIRECTORY PATH to your Neuronpedia batch outputs?"
read outputfilesdir

echo ""
read -p "===== Hit ENTER to start uploading!" start

echo "RUNNING: python upload_dead_feature_stubs.py $outputfilesdir"
python upload_dead_feature_stubs.py $outputfilesdir

echo ""
echo "===== ALL DONE."
echo "===== Go to http://localhost:3000 to browse your features"
3 changes: 0 additions & 3 deletions tutorials/neuronpedia/upload_features.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash

# we use a script around python to work around OOM issues - this ensures every batch gets the whole system available memory
# better fix is to investigate and fix the memory issues

echo "===== This will start upload the feature batch files to Neuronpedia."
echo "===== You'll need Neuronpedia running at localhost:3000 for this to work."

Expand Down

0 comments on commit 9067380

Please sign in to comment.