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
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
Prev Previous commit
Next Next commit
Change write location to elk-reporters/{sweep}/viz
  • Loading branch information
derpyplops committed May 18, 2023
commit a2e5f6070508917a89bad5e66b42975738271d11
32 changes: 12 additions & 20 deletions elk/plotting/visualize.py
derpyplops marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import itertools
import os
from dataclasses import dataclass
from pathlib import Path

Expand All @@ -14,8 +13,6 @@
import elk.plotting.utils as utils
from elk.utils.constants import BURNS_DATASETS

VIZ_PATH = Path(os.getcwd()) / "viz"


class SweepByDsMultiplot:
"""Multiplot containing visualization where the x-axis is the layer and
Expand Down Expand Up @@ -100,11 +97,11 @@ def render(
fig = utils.set_legend_font_size(fig, font_size=8)
if write:
fig.write_image(
file=VIZ_PATH / sweep.name / f"{self.model_name}-line-ds-multiplot.png",
file=sweep.path / f"{self.model_name}-line-ds-multiplot.png",
scale=2,
)
fig.write_html(
file=VIZ_PATH / sweep.name / f"{self.model_name}-line-ds-multiplot.html"
file=sweep.path / f"{self.model_name}-line-ds-multiplot.html"
)

return fig
Expand Down Expand Up @@ -210,30 +207,25 @@ def collect(cls, model_path: Path, sweep_name: str) -> ModelVisualization:

def render_and_save(
self,
sweep: SweepVisualization,
dataset_names: list[str] = BURNS_DATASETS,
score_type="auroc_estimate",
ensembling="full",
) -> None:
df = self.df
model_name = self.model_name
sweep_name = self.sweep_name
layer_min, layer_max = df["layer"].min(), df["layer"].max()
model_path = VIZ_PATH / sweep_name / f"{model_name}"
model_path = sweep.path / model_name
model_path.mkdir(parents=True, exist_ok=True)
if self.is_transfer:
for layer in range(layer_min, layer_max + 1):
filtered = df[(df["layer"] == layer) & (df["ensembling"] == ensembling)]
path = VIZ_PATH / sweep_name / f"{model_name}" / f"{layer}.png"
if not path.parent.exists():
path.parent.mkdir()
fig = TransferEvalHeatmap(
layer, score_type=score_type, ensembling=ensembling
).render(filtered)
fig.write_image(file=path)
fig.write_image(file=model_path / f"{layer}.png")
fig = TransferEvalTrend(dataset_names).render(df)
fig.write_image(
file=VIZ_PATH / sweep_name / f"{model_name}" / "transfer_eval_trend.png"
)
fig.write_image(file=model_path / "transfer_eval_trend.png")

@staticmethod
def _read_eval_csv(path, eval_dataset, train_dataset):
Expand Down Expand Up @@ -268,12 +260,12 @@ def _get_model_paths(sweep_path: Path) -> list[Path]:
return folders

@classmethod
def collect(cls, sweep: Path) -> SweepVisualization:
sweep_name = sweep.parts[-1]
sweep_viz_path = VIZ_PATH / sweep_name
def collect(cls, sweep_path: Path) -> SweepVisualization:
sweep_name = sweep_path.parts[-1]
sweep_viz_path = sweep_path / "viz"
sweep_viz_path.mkdir(parents=True, exist_ok=True)

model_paths = cls._get_model_paths(sweep)
model_paths = cls._get_model_paths(sweep_path)
models = {
model_path.name: ModelVisualization.collect(model_path, sweep_name)
for model_path in model_paths
Expand All @@ -284,7 +276,7 @@ def collect(cls, sweep: Path) -> SweepVisualization:

def render_and_save(self):
for model in self.models.values():
model.render_and_save()
model.render_and_save(self)
self.render_table(write=True)
self.render_multiplots(write=True)

Expand Down Expand Up @@ -313,4 +305,4 @@ def render_table(


def visualize_sweep(sweep_path: Path):
SweepVisualization.collect(sweep_path).render_and_save(write=True)
SweepVisualization.collect(sweep_path).render_and_save()
Loading