Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep Visualizations #245

Merged
merged 25 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
37002b1
create heatmap-visualizations for sweeps
lauritofzi May 5, 2023
e552f55
fix viz path + cleanup
lauritofzi May 7, 2023
199c8d5
initial
derpyplops May 14, 2023
1568cd0
refactoring
derpyplops May 14, 2023
181283f
code fix
derpyplops May 14, 2023
2908c0f
fix deps
derpyplops May 14, 2023
6ab281e
fix elk sweep viz flag usage
derpyplops May 15, 2023
ee6e14b
fix typo
derpyplops May 15, 2023
5d526d7
delete comment and factorize
derpyplops May 16, 2023
058cae8
cleanup
lauritowal May 16, 2023
5162cab
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 16, 2023
398ec42
Fix file resolution and factor out sweep_dir()
derpyplops May 16, 2023
9a79c8f
change to relative import
lauritowal May 16, 2023
cf0ad33
Merge branch 'visualizations' of https://github.com/EleutherAI/elk in…
lauritowal May 16, 2023
d6bd7b7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 16, 2023
d4e99b0
Address walt's comments and some tests
derpyplops May 17, 2023
a2e5f60
Change write location to elk-reporters/{sweep}/viz
derpyplops May 18, 2023
68e4b52
Edit README
derpyplops May 18, 2023
0e152bc
Fix TestGetModelPaths
derpyplops May 18, 2023
9d6552f
Fix duplicate bug
derpyplops May 18, 2023
623b2c7
add overwrite flag
derpyplops May 18, 2023
256ad68
add transfer to SweepByDsMultiplot
derpyplops May 18, 2023
9f9c5bb
Remove docstrings for consistency
derpyplops May 18, 2023
033e901
remove vestigial .gitignore
derpyplops May 18, 2023
c176732
remove burns datasets
derpyplops May 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
create heatmap-visualizations for sweeps
  • Loading branch information
lauritofzi committed May 5, 2023
commit 37002b12cb29444731344a0db55cdd9127234ee0
9 changes: 9 additions & 0 deletions elk/training/sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import numpy as np
import torch

from elk.utils.visualize import render_model_results

from ..evaluation import Eval
from ..extraction import Extract
from ..files import elk_reporter_dir, memorably_named_dir
Expand All @@ -29,6 +31,9 @@ class Sweep:
If negative, no hyperparameter sweeps will be performed. Only valid for Eigen."""
skip_transfer_eval: bool = False
"""Whether to perform transfer eval on every pair of datasets."""

visualize: bool = False
"""Whether to generate visualizions of the results of the sweep."""
derpyplops marked this conversation as resolved.
Show resolved Hide resolved

name: str | None = None

Expand Down Expand Up @@ -163,3 +168,7 @@ def execute(self):
skip_supervised=run.supervised == "none",
)
eval.execute(highlight_color="green")

if self.visualize:
for i, model in enumerate(self.models):
render_model_results(sweep_dir / model, sweep_dir / "visualizations")
72 changes: 72 additions & 0 deletions elk/utils/visualize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
from pathlib import Path

import pandas as pd
import plotly.express as px


def generate_heatmap(data, model_name, layer, viz_folder_path):

pivot = pd.pivot_table(
data, values="auroc_estimate", index="eval_dataset", columns="train_dataset"
)

fig = px.imshow(pivot, color_continuous_scale="Viridis", text_auto=True)

fig.update_layout(
xaxis_title="Train Dataset",
yaxis_title="Transfer Dataset",
title=f"AUROC Score Heatmap: {model_name} | Layer {layer}",
)

model_viz_folder_path = os.path.join(viz_folder_path, model_name)
if not os.path.exists(model_viz_folder_path):
os.mkdir(model_viz_folder_path)
fig.write_image(os.path.join(model_viz_folder_path, f"{layer}.png"))


def filter_df(df, layer):
df = df[df["ensembling"] == "full"] # filter df to only include full ensembling
df = df[df["layer"] == layer] # filter df to only include target layer
return df


def render_model_results(model_path, visualizations_path):
if not visualizations_path.exists():
visualizations_path.mkdir()

df = None

def get_layer_min_max(model_path: Path):
dir = model_path.iterdir().__next__()
file = os.path.join(dir, "eval.csv")
raw_eval_df = pd.read_csv(file)