-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'training-script' of https://github.com/delphi-suite/delphi
- Loading branch information
Showing
50 changed files
with
2,976 additions
and
332 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "src/delphi/train/llama2c"] | ||
path = src/delphi/train/llama2c | ||
[submodule "src/llama2c"] | ||
path = src/llama2c | ||
url = https://github.com/delphi-suite/llama2.c.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,3 @@ repos: | |
rev: 5.13.2 | ||
hooks: | ||
- id: isort | ||
name: isort (python) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Imports" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from typing import cast\n", | ||
"import pickle\n", | ||
"from collections import defaultdict\n", | ||
"\n", | ||
"from datasets import load_dataset, Dataset\n", | ||
"\n", | ||
"from delphi.constants import STATIC_ASSETS_DIR\n", | ||
"from delphi.eval import utils\n", | ||
"from delphi.eval import constants\n", | ||
"from delphi.eval.vis_per_token_model import visualize_per_token_category\n", | ||
"\n", | ||
"# from delphi.eval.calc_model_group_stats import calc_model_group_stats\n", | ||
"from delphi.eval.token_labelling import TOKEN_LABELS" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Data" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# load data\n", | ||
"tokenized_corpus_dataset = cast(Dataset, load_dataset(constants.tokenized_corpus_dataset))[\"validation\"]\n", | ||
"\n", | ||
"# TODO: convert to use static paths\n", | ||
"# with open(\"../src/delphi/eval/labelled_token_ids_dict.pkl\", \"rb\") as f:\n", | ||
"# token_groups = pickle.load(f)\n", | ||
"# model_group_stats = calc_model_group_stats(\n", | ||
"# tokenized_corpus_dataset, logprob_datasets, token_groups, token_groups[0].keys()\n", | ||
"# )\n", | ||
"with open(f\"{STATIC_ASSETS_DIR}/model_group_stats.pkl\", \"rb\") as f:\n", | ||
" model_group_stats = pickle.load(f)\n", | ||
"\n", | ||
"logprob_datasets = utils.load_logprob_datasets(\"validation\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Visualization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "0f8846898fbb4a1b9e872ff6511acd3d", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"VBox(children=(Dropdown(description='Token Category:', options=('Capitalized', 'Is Determiner', 'Is Interjunct…" | ||
] | ||
}, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"performance_data = defaultdict(dict)\n", | ||
"for model in constants.LLAMA2_MODELS:\n", | ||
" for token_group_desc in TOKEN_LABELS:\n", | ||
" if (model, token_group_desc) not in model_group_stats:\n", | ||
" continue\n", | ||
" stats = model_group_stats[(model, token_group_desc)]\n", | ||
" performance_data[model][token_group_desc] = (\n", | ||
" -stats[\"median\"],\n", | ||
" -stats[\"75th\"],\n", | ||
" -stats[\"25th\"],\n", | ||
" )\n", | ||
"\n", | ||
"visualize_per_token_category(\n", | ||
" performance_data,\n", | ||
" log_scale=True,\n", | ||
" bg_color=\"LightGrey\",\n", | ||
" line_color=\"Red\",\n", | ||
" marker_color=\"Orange\",\n", | ||
" bar_color=\"Green\",\n", | ||
")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "tinyevals", | ||
"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.10.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "696575431f65420e9dc22c3b3476bfbb", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"VBox(children=(Dropdown(description='Token Category:', options=('nouns', 'verbs', 'prepositions', 'adjectives'…" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from collections import defaultdict\n", | ||
"import math\n", | ||
"import random\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"from delphi.eval.vis_per_token_model import visualize_per_token_category\n", | ||
"\n", | ||
"\n", | ||
"random.seed(0)\n", | ||
"\n", | ||
"# generate mock data\n", | ||
"model_names = ['llama2-100k', 'llama2-200k', 'llama2-1m', 'llama2-10m']\n", | ||
"categories = ['nouns', 'verbs', 'prepositions', 'adjectives']\n", | ||
"entries = [200, 100, 150, 300]\n", | ||
"performance_data = defaultdict()\n", | ||
"for i, model in enumerate(model_names):\n", | ||
" performance_data[model] = defaultdict()\n", | ||
" for cat in categories:\n", | ||
" x = [math.log2(random.random()) for _ in range(entries[i])]\n", | ||
" means = np.mean(x)\n", | ||
" err_low = means - np.percentile(x, 25)\n", | ||
" err_hi = np.percentile(x, 75) - means\n", | ||
" performance_data[model][cat] = (-means, err_low, err_hi)\n", | ||
"\n", | ||
"\n", | ||
"visualize_per_token_category(performance_data, log_scale=True, bg_color='LightGrey', line_color=\"Red\", marker_color='Orange', bar_color='Green')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "cb3af5248a4a40118c36a527c927289d", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"VBox(children=(Dropdown(description='Token Category:', options=('nouns', 'verbs', 'prepositions', 'adjectives'…" | ||
] | ||
}, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"visualize_per_token_category(performance_data, log_scale=False)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": ".venv", | ||
"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.10.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.