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 12 commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@ dmypy.json

# Pyre type checker
.pyre/

viz
3 changes: 2 additions & 1 deletion elk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from simple_parsing import ArgumentParser

from elk.evaluation.evaluate import Eval
from elk.plotting.command import Plot
from elk.training.sweep import Sweep
from elk.training.train import Elicit

Expand All @@ -13,7 +14,7 @@
class Command:
"""Some top-level command"""

command: Elicit | Eval | Sweep
command: Elicit | Eval | Sweep | Plot

def execute(self):
return self.command.execute()
Expand Down
4 changes: 4 additions & 0 deletions elk/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from pathlib import Path


def sweeps_dir() -> Path:
return elk_reporter_dir() / "sweeps"


def elk_reporter_dir() -> Path:
"""Return the directory where reporter checkpoints and logs are stored."""
env_dir = os.environ.get("ELK_DIR", None)
Expand Down
27 changes: 27 additions & 0 deletions elk/plotting/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
from dataclasses import dataclass, field

from elk.files import sweeps_dir
from elk.plotting.visualize import visualize_sweep


@dataclass
class Plot:
sweeps: list[str] = field(default_factory=list)

def execute(self):
sweeps_root_dir = sweeps_dir()
sweep = max(sweeps_root_dir.iterdir(), key=os.path.getctime)
if self.sweeps:
sweep = sweeps_root_dir / self.sweeps[0]
if not sweep.exists():
print(f"No sweep with name {self.sweeps[0]} found in {sweeps_root_dir}")
return
if len(self.sweeps) > 1:
# TODO support more than one sweep
print(
f"""{len(self.sweeps)} paths specified.
Only one sweep is supported at this time."""
)
else:
visualize_sweep(sweep)
78 changes: 78 additions & 0 deletions elk/plotting/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import shutil
from pathlib import Path

from rich.console import Console
from rich.table import Table


def set_subplot_title_font_size(fig, font_size=14, font_family="Arial"):
fig.update_annotations(
font=dict(
family=font_family,
size=font_size,
)
)
return fig


def set_legend_font_size(fig, font_size=8, font_family="Arial"):
fig.update_layout(
xaxis=dict(
tickfont=dict(
family=font_family,
size=font_size,
)
),
yaxis=dict(
tickfont=dict(
family=font_family,
size=font_size,
)
),
legend=dict(
font=dict(
family=font_family,
size=font_size,
)
),
)
return fig


def display_table(pivot_table):
console = Console()

table = Table(show_header=True, header_style="bold magenta", show_lines=True)

table.add_column("Run Name")
for column in pivot_table.columns:
table.add_column(str(column))

for index, row in pivot_table.iterrows():
table.add_row(str(index), *[str(value) for value in row])

console.print(table)


def restructure_to_sweep(
derpyplops marked this conversation as resolved.
Show resolved Hide resolved
elk_reporters: Path, data_path, new_name: str
): # usually /elk-reporters/*
for model_repo_path in elk_reporters.iterdir():
for model_path in model_repo_path.iterdir():
for dataset_path in model_path.iterdir():
for run_path in dataset_path.iterdir():
new_path = (
data_path
/ new_name
/ run_path.name
/ model_repo_path.name
/ model_path.name
/ dataset_path.name
)
if not new_path.exists():
new_path.mkdir(parents=True)
for file in run_path.iterdir():
if file.is_file():
shutil.copy(file, new_path / file.name)
else:
shutil.copytree(file, new_path / file.name)
Loading