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

Binarized meta-templates; some extraction refactoring #218

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bbee489
Initial support for FEVER
norabelrose Apr 22, 2023
5ba1ddd
Start saving and fitting a reporter to the input embeddings
norabelrose Apr 22, 2023
3b1f74d
Merge branch 'input-embeddings' into template-filtering
norabelrose Apr 22, 2023
51ba54f
Rename layer 0 to 'input' to make it more clear
norabelrose Apr 22, 2023
544b485
Actually rename layer 0 correctly
norabelrose Apr 22, 2023
43da44e
Handle layer_stride correctly
norabelrose Apr 22, 2023
9056e00
Merge branch 'input-embeddings' into template-filtering
norabelrose Apr 22, 2023
756fa53
label_choices
norabelrose Apr 22, 2023
93b7ae0
Clean up train and eval commands; do transfer in sweep
norabelrose Apr 22, 2023
57d0b8b
Support INLP and split eval output into multiple CSVs
norabelrose Apr 22, 2023
228a6a0
Merge branch 'inlp' into template-filtering
norabelrose Apr 22, 2023
b086f0b
Merge branch 'inlp' into template-filtering
norabelrose Apr 25, 2023
934cd54
Log ensembled metrics
norabelrose Apr 26, 2023
dff69bf
Fixing pyright version
norabelrose Apr 26, 2023
b181d3e
Merge remote-tracking branch 'origin/main' into ensembling
norabelrose Apr 26, 2023
15254bf
Merge main
norabelrose Apr 26, 2023
69c2d55
Tons of stuff, preparing for sciq_binary experiment
norabelrose Apr 27, 2023
960ff01
Support --binarize again
norabelrose Apr 27, 2023
c9e62ea
Partial support for truthful_qa
norabelrose Apr 27, 2023
eb71a6c
Merge branch 'main' into template-filtering
norabelrose Apr 29, 2023
88bb15e
Merge remote-tracking branch 'origin/main' into template-filtering
norabelrose Apr 29, 2023
c648ff0
Remove crap
norabelrose Apr 29, 2023
ef12130
EleutherAI/truthful_qa_mc
norabelrose Apr 29, 2023
5d60ebd
Update templates
norabelrose Apr 30, 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
20 changes: 10 additions & 10 deletions elk/evaluation/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
from collections import defaultdict
from dataclasses import dataclass
from pathlib import Path

import pandas as pd
import torch
from simple_parsing.helpers import field

from ..files import elk_reporter_dir, transfer_eval_directory
from ..files import elk_reporter_dir
from ..metrics import evaluate_preds
from ..run import Run
from ..training import Reporter
from ..utils import Color


@dataclass
@dataclass(kw_only=True)
class Eval(Run):
"""Full specification of a reporter evaluation run."""

source: str = field(default="", positional=True)
source: Path = field(positional=True)
skip_supervised: bool = False

def __post_init__(self):
assert self.source, "Must specify a source experiment."
if not self.out_dir:
self.out_dir = self.source / "transfer" / "+".join(self.data.datasets)

# Set the output directory to the transfer directory if it's not specified
self.out_dir = (
transfer_eval_directory(self.source)
if self.out_dir is None
else self.out_dir
)
def execute(self, highlight_color: Color = "cyan"):
return super().execute(highlight_color, split_type="val")

@torch.inference_mode()
def apply_to_layer(
self, layer: int, devices: list[str], world_size: int
) -> dict[str, pd.DataFrame]:
Expand Down
3 changes: 1 addition & 2 deletions elk/extraction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .balanced_sampler import BalancedSampler, FewShotSampler
from .extraction import Extract, extract, extract_hiddens
from .generator import _GeneratorBuilder, _GeneratorConfig
from .prompt_loading import PromptConfig, load_prompts
from .prompt_loading import load_prompts

__all__ = [
"BalancedSampler",
Expand All @@ -11,6 +11,5 @@
"extract",
"_GeneratorConfig",
"_GeneratorBuilder",
"PromptConfig",
"load_prompts",
]
26 changes: 15 additions & 11 deletions elk/extraction/balanced_sampler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from collections import deque
from dataclasses import dataclass, field
from dataclasses import InitVar, dataclass, field
from itertools import cycle
from random import Random
from typing import Iterable, Iterator, Optional
from typing import Hashable, Iterable, Iterator, Optional

from datasets import Features, IterableDataset
from torch.utils.data import IterableDataset as TorchIterableDataset
Expand All @@ -26,25 +26,29 @@ class BalancedSampler(TorchIterableDataset):
"""

data: Iterable[dict]
num_classes: int
label_choices: InitVar[set[Hashable]]
buffer_size: int = 1000
buffers: dict[int, deque[dict]] = field(default_factory=dict, init=False)
buffers: dict[Hashable, deque[dict]] = field(default_factory=dict, init=False)
label_col: str = "label"
strict: bool = True

def __post_init__(self):
def __post_init__(self, label_choices: set[Hashable]):
# Initialize empty buffers
self.buffers = {
label: deque(maxlen=self.buffer_size) for label in range(self.num_classes)
label: deque(maxlen=self.buffer_size) for label in label_choices
}

def __iter__(self):
for sample in self.data:
label = sample[self.label_col]

# This whole class is a no-op if the label is not an integer
if not isinstance(label, int):
yield sample
continue
if label not in self.buffers:
if self.strict:
raise ValueError(
f"Expected label to be one of {self.buffers}, got {label}"
)
else:
# Just skip this sample
continue

# Add the sample to the buffer for its class label
self.buffers[label].append(sample)
Expand Down
Loading