Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriele committed Feb 13, 2025
1 parent be5edcf commit 4d75ff6
Showing 1 changed file with 119 additions and 0 deletions.
119 changes: 119 additions & 0 deletions suffix_decoding/helper.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from collections import OrderedDict\n",
"original_fp=\"/home/jovyan/pscratch/suffix-tree-decoding/trace/llama70b/cortex-llama3.1-70b.json\"\n",
"new_fp=\"/home/jovyan/pscratch/suffix-tree-decoding/trace/llama70b/cortex-llama3.1-70b_debug.json\"\n",
"\n",
"with open(original_fp, \"r\") as f:\n",
" original_data = json.load(f, object_pairs_hook=OrderedDict)\n",
"partitions = original_data[\"partitions\"]\n",
"# remove partitions whose partition_name does not match \"FEATURE_EXTRACTION\"\n",
"partitions = [p for p in partitions if p[\"partition_name\"] == \"FEATURE_EXTRACTION\"]\n",
"assert len(partitions) == 1\n",
"partitions[0][\"eval_entries\"] = [e for e in partitions[0][\"eval_entries\"] if e[\"prompt_length\"] == 967]\n",
"partitions[0][\"eval_entries\"] = partitions[0][\"eval_entries\"][:1]\n",
"\n",
"new_json = OrderedDict({\n",
" \"partitions\": partitions,\n",
" \"metadata\": original_data[\"metadata\"],\n",
"})\n",
"\n",
"# save data back to json\n",
"with open(new_fp, \"w\") as f:\n",
" json.dump(new_json, f, indent=2)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[720, 220, 330, 46458, 30015, 794, 905, 11, 720, 220, 330, 20693, 291, 794, 837, 345, 220, 330, 16608, 42394, 30015, 794, 905, 345, 220, 330, 13430, 39341, 2987, 794, 905, 198, 534, 74694]\n"
]
}
],
"source": [
"import os\n",
"os.environ[\"HF_HOME\"] = \"/home/jovyan/pscratch/.cache/huggingface\"\n",
"# tokenize a sentence with llama 3.1 70b\n",
"from transformers import AutoTokenizer\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(\"meta-llama/Llama-3.1-70B-Instruct\")\n",
"sentence = \" \\n \\\"ratio_question\\\": false, \\n \\\"timed\\\": true,\\n \\\"rolling_metric_question\\\": false,\\n \\\"rank_calculation\\\": false\\n}\\n```\"\n",
"correct_output=\" \\n \\\"ratio_question\\\": true, \\n \\\"last_period\\\": false, \\n \\\"timedimension_aggregation\\\": true, \\n \\\"missing_time_period\\\": false, \\n \\\"period_over_period_question\\\": true, \\n \\\"rolling_metric_question\\\": false, \\n \\\"consecutive_trend_question\\\": false, \\n \\\"rank_calculation\\\": false \\n}\\n```\"\n",
"tokens = tokenizer.encode(sentence, add_special_tokens=False)\n",
"print(tokens)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"' \\n \"ratio_question\": false, \\n \"tim'"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tokenizer.decode([720, 220, 330, 46458, 30015, 794, 905, 11, 720, 220, 330, 20693])"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[720, 220, 330, 46458, 30015, 794, 837, 11, 720, 220, 330, 4354, 21485, 794, 905, 11, 720, 220, 330, 20693, 291, 18658, 21233, 35542, 794, 837, 11, 720, 220, 330, 31716, 3084, 21485, 794, 905, 11, 720, 220, 330, 19862, 15793, 21485, 30015, 794, 837, 11, 720, 220, 330, 16608, 42394, 30015, 794, 905, 11, 720, 220, 330, 444, 86880, 530, 9484, 30015, 794, 905, 11, 720, 220, 330, 13430, 39341, 2987, 794, 905, 720, 534, 74694]\n"
]
}
],
"source": [
"tokens=tokenizer.encode(correct_output, add_special_tokens=False)\n",
"print(tokens)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 4d75ff6

Please sign in to comment.