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

Multi datasets #123

Merged
merged 46 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
681698d
add multiple datasets support
Benw8888 Mar 9, 2023
ac1b9f1
Merge branch 'main' of github.com:EleutherAI/elk into multi-datasets
Benw8888 Mar 9, 2023
b864c77
train_reporter works on a list of layers now
Benw8888 Mar 10, 2023
7d7d97c
changing printed layer names
Benw8888 Mar 10, 2023
4fe61e9
fixed concatenation bug
Benw8888 Mar 11, 2023
fe61d67
minor edits
Benw8888 Mar 13, 2023
74da878
fixed pyright issues
Benw8888 Mar 13, 2023
569ef05
Merge branch 'main' of github.com:EleutherAI/elk into multi-datasets
Benw8888 Mar 14, 2023
b62b679
Merge branch 'main' into multi-datasets
norabelrose Mar 20, 2023
fe94c22
Fix tests
norabelrose Mar 20, 2023
bba24d8
Now working sorta
norabelrose Mar 22, 2023
03ba6e0
Skip slow BalancedBatchSampler test
norabelrose Mar 22, 2023
15ab351
Slightly relax test_output_is_roughly_balanced
norabelrose Mar 22, 2023
a80369e
Make BalancedSampler deterministic
norabelrose Mar 22, 2023
d304ab3
InitVar
norabelrose Mar 22, 2023
761c82d
Support multi class again
norabelrose Mar 22, 2023
f29743b
Fix naming issue
norabelrose Mar 22, 2023
b7b7e23
Support few shot prompts
norabelrose Mar 23, 2023
1afb563
Merge branch 'main' into multi-datasets
norabelrose Mar 23, 2023
225d4c7
fix multiclass labels
AlexTMallen Mar 23, 2023
9368dc8
Merge branch 'multi-datasets' of github.com:EleutherAI/elk into multi…
AlexTMallen Mar 23, 2023
a858b65
Merge branch 'main' into multi-datasets
norabelrose Mar 24, 2023
5dc2ec6
Merge branch 'multi-datasets' of github.com:EleutherAI/elk into multi…
norabelrose Mar 24, 2023
b1b95e5
Fix dumb part of test failures
norabelrose Mar 25, 2023
ee3911e
Fix assert_allclose warning
norabelrose Mar 25, 2023
a55b3de
Switch to torch.testing.assert_close in EigenReporter test
norabelrose Mar 25, 2023
44dc25c
Shuffle load_prompts output by default
norabelrose Mar 25, 2023
93d8d87
Fix smoke test failure
norabelrose Mar 25, 2023
fad4d74
Remove debug prints
AlexTMallen Mar 25, 2023
0a054f4
Remove more debug print statements
AlexTMallen Mar 25, 2023
177eec2
make min_memory usable; broadcast mmax_examples in __post_init__
AlexTMallen Mar 26, 2023
3a762b0
prompt loading refactor to enable better streaming
AlexTMallen Mar 26, 2023
f66c054
remove shuffle arg
AlexTMallen Mar 26, 2023
d3d87fc
remove unused @dataclass
lauritowal Mar 26, 2023
3d08147
merge
lauritowal Mar 27, 2023
c9a43e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 27, 2023
94290aa
add concatenated_layer_offset to eval
lauritowal Mar 27, 2023
f9298e4
Merge branch 'multi-datasets' of https://github.com/EleutherAI/elk in…
lauritowal Mar 27, 2023
3765c4f
add self.
lauritowal Mar 27, 2023
2b05193
replace target with data
lauritowal Mar 27, 2023
83731bb
add self.
lauritowal Mar 27, 2023
764fda9
remove second arg
lauritowal Mar 27, 2023
d2c66b0
fix passing the wrong params for world size / rank
thejaminator Mar 28, 2023
9186326
Update prompt_loading.py
lauritowal Mar 28, 2023
3f99a4d
fix pre-commit errors
lauritowal Mar 28, 2023
148130d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 28, 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
make min_memory usable; broadcast mmax_examples in __post_init__
  • Loading branch information
AlexTMallen committed Mar 26, 2023
commit 177eec2e02f11366f70b9c9213a267bec170eb59
2 changes: 1 addition & 1 deletion elk/evaluation/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def evaluate_reporters(cfg: EvaluateConfig, out_dir: Optional[Path] = None):
if feat.startswith("hidden_")
]

devices = select_usable_devices(cfg.num_gpus)
devices = select_usable_devices(cfg.num_gpus, min_memory=cfg.target.min_gpu_mem)
num_devices = len(devices)

transfer_eval = elk_reporter_dir() / cfg.source / "transfer_eval"
Expand Down
17 changes: 4 additions & 13 deletions elk/extraction/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
AutoTokenizer,
PreTrainedModel,
)
from typing import Iterable, Literal, Union
from typing import Iterable, Literal, Union, Optional
import logging
import os
import torch
Expand All @@ -46,6 +46,7 @@ class ExtractionConfig(Serializable):
layer_stride: Shortcut for setting `layers` to `range(0, num_layers, stride)`.
token_loc: The location of the token to extract hidden states from. Can be
either "first", "last", or "mean". Defaults to "last".
min_gpu_mem: Minimum amount of free memory (in bytes) required to select a GPU.
"""

prompts: PromptConfig
Expand All @@ -54,6 +55,7 @@ class ExtractionConfig(Serializable):
layers: tuple[int, ...] = ()
layer_stride: InitVar[int] = 1
token_loc: Literal["first", "last", "mean"] = "last"
min_gpu_mem: Optional[int] = None

def __post_init__(self, layer_stride: int):
if self.layers and layer_stride > 1:
Expand Down Expand Up @@ -203,18 +205,7 @@ def get_splits() -> SplitDict:
train_name, val_name = select_train_val_splits(available_splits)
print(f"Using '{train_name}' for training and '{val_name}' for validation")

out_splits = SplitDict(
train=available_splits[train_name], val=available_splits[val_name]
)

# Empty list means no limit
limit_list = cfg.prompts.max_examples
if not limit_list:
limit_list = [int(1e100)]

# Broadcast the limit to all splits
if len(limit_list) == 1:
limit_list *= len(out_splits)

return SplitDict(
{
Expand Down Expand Up @@ -255,7 +246,7 @@ def get_splits() -> SplitDict:
length=num_variants,
),
}
devices = select_usable_devices(num_gpus)
devices = select_usable_devices(num_gpus, min_memory=cfg.min_gpu_mem)
builders = {
split_name: _GeneratorBuilder(
cache_dir=None,
Expand Down
6 changes: 6 additions & 0 deletions elk/extraction/prompt_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def __post_init__(self):
"max_examples should be a list of length 0, 1, or 2,"
f"but got {len(self.max_examples)}"
)
if not self.max_examples:
self.max_examples = [int(1e100)]

# Broadcast the limit to all splits
if len(self.max_examples) == 1:
self.max_examples *= 2


def load_prompts(
Expand Down
2 changes: 1 addition & 1 deletion elk/training/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def train(cfg: RunConfig, out_dir: Optional[Path] = None):
with open(out_dir / "metadata.yaml", "w") as meta_f:
yaml.dump(meta, meta_f)

devices = select_usable_devices(cfg.num_gpus)
devices = select_usable_devices(cfg.num_gpus, min_memory=cfg.data.min_gpu_mem)
num_devices = len(devices)

cols = [
Expand Down
10 changes: 7 additions & 3 deletions elk/utils/gpu_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"""Utilities that use PyNVML to get GPU usage info, and select GPUs accordingly."""

from .typing import assert_type
from typing import Optional
import os
import pynvml
import torch
import warnings
import time


def select_usable_devices(num_gpus: int = -1, *, min_memory: int = -1) -> list[str]:
def select_usable_devices(
num_gpus: int = -1, *, min_memory: Optional[int] = None
) -> list[str]:
"""Select a set of devices that have at least `min_memory` bytes of free memory.
Blocks until at least `num_gpus` devices are available.

When there are more than enough GPUs to satisfy the request, the GPUs with the
most free memory will be selected. With default arguments, this function will
Expand All @@ -30,7 +34,7 @@ def select_usable_devices(num_gpus: int = -1, *, min_memory: int = -1) -> list[s
num_gpus: Number of GPUs to select. If negative, all available GPUs
meeting the criteria will be selected.
min_memory: Minimum amount of free memory (in bytes) required to select a GPU.
If negative, `min_memory` is set to 90% of the per-GPU memory.
If None, `min_memory` is set to 90% of the per-GPU memory.

Returns:
A list of suitable PyTorch device strings, in ascending numerical order, with
Expand Down Expand Up @@ -85,7 +89,7 @@ def select_usable_devices(num_gpus: int = -1, *, min_memory: int = -1) -> list[s
assert num_installed == num_visible, "PyNVML and PyTorch disagree on GPU count"

# Set default value for `min_memory`
if min_memory < 0:
if min_memory is None:
min_device_ram = min(
(
assert_type(
Expand Down
14 changes: 10 additions & 4 deletions tests/test_smoke_elicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,45 @@


def test_smoke_elicit_run_tiny_gpt2_ccs(tmp_path: Path):
model_path = "sshleifer/tiny-gpt2"
# we need about 5 mb of gpu memory to run this test
model_path, min_mem = "sshleifer/tiny-gpt2", 10 * 1024**2
dataset_name = "imdb"
config = RunConfig(
data=ExtractionConfig(
model=model_path,
prompts=PromptConfig(datasets=[dataset_name], max_examples=[10]),
min_gpu_mem=min_mem,
# run on all layers, tiny-gpt only has 2 layers
),
num_gpus=2,
net=CcsReporterConfig(),
)
train(config, tmp_path)
# get the files in the tmp_path
files: Path = list(tmp_path.iterdir())
files: list[Path] = list(tmp_path.iterdir())
created_file_names = {file.name for file in files}
expected_files = ["cfg.yaml", "metadata.yaml", "lr_models", "reporters", "eval.csv"]
for file in expected_files:
assert file in created_file_names


def test_smoke_elicit_run_tiny_gpt2_eigen(tmp_path: Path):
model_path = "sshleifer/tiny-gpt2"
# we need about 5 mb of gpu memory to run this test
model_path, min_mem = "sshleifer/tiny-gpt2", 10 * 1024**2
dataset_name = "imdb"
config = RunConfig(
data=ExtractionConfig(
model=model_path,
prompts=PromptConfig(datasets=[dataset_name], max_examples=[10]),
min_gpu_mem=min_mem,
# run on all layers, tiny-gpt only has 2 layers
),
num_gpus=2,
net=EigenReporterConfig(),
)
train(config, tmp_path)
# get the files in the tmp_path
files: Path = list(tmp_path.iterdir())
files: list[Path] = list(tmp_path.iterdir())
created_file_names = {file.name for file in files}
expected_files = ["cfg.yaml", "metadata.yaml", "lr_models", "reporters", "eval.csv"]
for file in expected_files:
Expand Down